Using an ActiveX control in VC++

When trying to use my ActiveX control in Visual C++, I noticed that when inserting the control in the dialog the control will not be created which causes the m_hWnd to be NULL which causes problems in my control behavior at design time. What shall I do to overcome this problem? Any ideas?
DaedAsked:
Who is Participating?
 
NetminderCommented:
PAQed, with points refunded (100)

Netminder
Site Admin
0
 
TriskelionCommented:
How did you bind the class to the control?
0
 
DaedAuthor Commented:
I didn't understand what do you mean. Plz explain more.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
TriskelionCommented:
When you put the control on the (I'm assuming) CFormView, did you create a class for it to be controlled or are you attempting to access it directly/only by its handle?
0
 
DaedAuthor Commented:
I added the control to a dialog based project by choosing “Add to project” from the “Project” menu, then chose “Components and Controls” then “Registered ActiveX Controls”. When clicking Ok the system will insert the .cpp and .h files of the control. In MyDialog.h, I created an instance of the control as follows:
MyControlCtl* ptrControl1;
In the OnInitDialog in MyDialog.cpp, I wrote the follows:
ptrControl1 = (MyControlCtl *) GetDlgItem(controlID);

0
 
TriskelionCommented:
Can you use the class wizard to attach a variable to the control.
I see that you're doing it manually with the GetDlgItem, but does Class Wizard see the thing?
0
 
DaedAuthor Commented:
Yes, the ClassWizard can see the control and i can add it as a member variable from there. May be the problem is in the control code not the application?!
0
 
TriskelionCommented:
Can you add ANY other Active X control that works properly?
Do you have the Active X test container thingy?
0
 
DaedAuthor Commented:
Yes I can add other ActiveX controls that works properly and I tried my Control in Text container and everything worked fine.
0
 
DaedAuthor Commented:
Please delete this question. I found out that my problem was that the control was not created at design-time, that's why the m_hWnd was always NULL. I solved the problem by adding the following lines of code in the OnDraw:

    if(!AmbientUserMode() && !m_hWnd)
    {
        // This drawing code creates the window and has it draw its
        // child windows into it.
        _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
        ASSERT(pThreadState != NULL);
        pThreadState->m_pWndPark = new CWnd;
        pThreadState->m_pWndPark->m_hWnd = pcdc->GetWindow()->GetSafeHwnd();
   }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.