Using a Custom ActiveX Control in MFC
CoderSource.net
Using a Custom ActiveX Control in MFC - Article by shours
Level: BeginnerType: Article
Rating: 5Page: 2 of 3

Date: 1/14/2006 12:00:00 AM

Environment: Windows, Visual Studio

We will include a toolbar, a status bar and the toolbar will have a normal look.


For the step 5 of 6 we will not have any changes.

And finally the 6th step will bring a window with the filenames. We will not operate any changes here.

The classes made are: CAboutDlg, CEvolApp, CEvolCntrItem, CEvolDoc, CEvolView, CMainFrame.

Now we will have to make some changes and adding to the code.

For the class CEvolDoc, the one who is manipulating the document itself, we will some functionality. Here you will develop the routine that is loading the ActiveX. In the public section of the header add:

          ICatInformationPtr m_pCatInfo;
          CArray< CATID, CATID& > m_aImplementedCategories;
          CArray< CATID, CATID& > m_aRequiredCategories;
          CList< CLSID, CLSID& > m_lControls;
          CEvolCntrItem* pItem;

Next you will have to add some code the function OnNewDocument():

          BOOL tDone;
          HRESULT hResult;
          IEnumGUIDPtr pEnum;
          CLSID clsid;
          LPOLESTR pszName;
          CString strName;
          ULONG nImplementedCategories,iCategory;
          CATID* pcatidImpl;
          ULONG nRequiredCategories;
          CATID* pcatidReq,catid;
          POSITION posControl;

          tDone = FALSE;
          posControl=m_lControls.GetHeadPosition();
          // clsid=m_lControls.GetNext(posControl);

          if(!posControl)
          {
                     hResult =m_pCatInfo.CreateInstance( CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER );
                     if( FAILED( hResult ) )
                     {
                           TRACE( "Failed to create category manager\n" );
                           return FALSE;
                      }
                      catid = CATID_Control;
                      m_aImplementedCategories.Add( catid );

                      nImplementedCategories = m_aImplementedCategories.GetSize();
                      if( nImplementedCategories == 0 )
                      {
                             nImplementedCategories = ULONG( -1 );
                             pcatidImpl = NULL;
                      }
                      else
                      {
                              pcatidImpl = (CATID*)_alloca( nImplementedCategories*sizeof( CATID ) );
                              for(iCategory = 0; iCategory < nImplementedCategories; iCategory++ )
                              {
                                    pcatidImpl[iCategory] = m_aImplementedCategories[iCategory];
                              }
                       }
                                                  
                       nRequiredCategories = m_aRequiredCategories.GetSize();

                       if( nRequiredCategories == 0 )
                       {
                            pcatidReq = NULL;
                        }
                        else
                        {
                             pcatidReq = (CATID*)_alloca( nRequiredCategories*sizeof( CATID ) );
                             for( iCategory = 0; iCategory < nRequiredCategories; iCategory++ )
                             {
                                  pcatidReq[iCategory] = m_aRequiredCategories[iCategory];
                              }
                         }

                         hResult = m_pCatInfo->EnumClassesOfCategories( nImplementedCategories, pcatidImpl, nRequiredCategories, pcatidReq, &pEnum );

                         if( FAILED( hResult ) )
                         {
                             return FALSE;
                         }

                         tDone = FALSE;
                         while( !tDone )
                         {
                               hResult = pEnum->Next( 1, &clsid, NULL );
                               if( hResult == S_OK )
                               {
                                   pszName = NULL;
                                   hResult = OleRegGetUserType( clsid, USERCLASSTYPE_FULL, &pszName );
                                   if( SUCCEEDED( hResult ) )
                                   {
                                         strName = pszName;
                                         CoTaskMemFree( pszName );
                                         pszName = NULL;
                                         if(strstr(strName, "EvolActiveX"))
                                         posControl = m_lControls.AddTail( clsid ); 
                                    }
                                  }
                                  else
                                  {
                                      tDone = TRUE;
                                   }
                               }
                         }
                         if(tDone)
                         {
                                                  pItem=NULL;
                                                  Load();
                         }

 


Attachments

Project Files Demo Files

1 2 3

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us