none
Insert ActiveX Control on MFC ActiveX Control

    Question

  • I'm trying to use an existing ActiveX control on a dialog of an MFC ActiveX control that I wrote.

    For the MFC ActiveX control that I wrote, I followed these instructions from the All-In-One Framework CodeFx sample MFCActiveX.

    /////////////////////////////////////////////////////////////////////////////
    Creation:
    
    A. Creating the project
    
    Step1. Create a Visual C++ / MFC / MFC ActiveX Control project named 
    MFCActiveX in Visual Studio 2008.
    
    Step2. In the page "Control Settings", select "Create control based on" as 
    STATIC. Under "Additional features", check "Activates when visible" and 
    "Flicker-free activation", and un-check "Has an About box dialog".
    
    B. Adding a main dialog to the control
    
    Step1. In Resource View, insert a new dialog resource and change the control 
    ID to IDD_MAINDIALOG.
    
    Step2. Change the default properties of the dialog to Border - None, 
    Style - Child, System Menu - False, Visible - True.
    
    Step3. Create a class for the dialog, by right clicking on the dialog and 
    selecting Add Class. Name the class CMainDialog, with the base class CDialog.
    
    Step4. Add the member variable m_MainDialog of the type CMainDialog to the 
    class CMFCActiveXCtrl.
    
    Step5. Select the class CMFCActiveXCtrl in Class View. In the Properties 
    sheet, select the Messages icon. Add OnCreate for the WM_CREATE message. 
    
    Step6. Open MFCActiveXCtrl.cpp, and add the following code to the OnCreate 
    method to create the main dialog.
    
    	m_MainDialog.Create(IDD_MAINDIALOG, this);
    
    Step7. Add the following code to the OnDraw method to size the main dialog 
    window and fill the background.
    
    	m_MainDialog.MoveWindow(rcBounds, TRUE);
    	CBrush brBackGnd(TranslateColor(AmbientBackColor()));
    	pdc->FillRect(rcBounds, &brBackGnd);
    

    I thought I would be able to insert an activeX control by right clicking in my dialog and choosing "Insert ActiveX Control".  It works, mostly, in that it appears correctly in the dialog editor, but when I try to instantiate my control using the ActiveX Control Test Container, nothing appears, not even the controls from the dialog - only the placeholder ellipse (that comes from creating a default project) actually draws.  I can create the child ActiveX control fine with the test container.  And if I don't insert it into my dialog, then I can create MY ActiveX control fine, but if there's an ActiveX control on my ActiveX control, then nothing appears...not even other buttons in my dialog.

    So how do I put an ActiveX control on my ActiveX control?

    Any idea what I might have done wrong?  Can anyone explain how to do this?
    Tuesday, December 08, 2009 3:25 PM

Answers

  • Hello Wyck,

    Please try call the AfxEnableControlContainer() function in the Activex Control's InitInstance function.

    In the MFCActiceX.cpp file, try the following function

    BOOL CMFCActiveXApp::InitInstance()
    {
     BOOL bInit = COleControlModule::InitInstance();
     if (bInit)
     {
      AfxEnableControlContainer();
      // TODO: Add your own module initialization code here.
     }
     return bInit;
    }

    More info
    http://msdn.microsoft.com/en-us/library/x1se4y1y.aspx

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Wyck Tuesday, December 15, 2009 2:54 PM
    Wednesday, December 09, 2009 10:10 AM

All replies

  • Hello Wyck,

    Please try call the AfxEnableControlContainer() function in the Activex Control's InitInstance function.

    In the MFCActiceX.cpp file, try the following function

    BOOL CMFCActiveXApp::InitInstance()
    {
     BOOL bInit = COleControlModule::InitInstance();
     if (bInit)
     {
      AfxEnableControlContainer();
      // TODO: Add your own module initialization code here.
     }
     return bInit;
    }

    More info
    http://msdn.microsoft.com/en-us/library/x1se4y1y.aspx

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Wyck Tuesday, December 15, 2009 2:54 PM
    Wednesday, December 09, 2009 10:10 AM
  • Yep.  that works!   AfxEnableControlContainer was the missing thing.

    Thanks!
    Tuesday, December 15, 2009 2:42 PM