Solved

Using an ActiveX control in VC++

Posted on 2002-04-30
11
716 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:Daed
  • 5
  • 4
11 Comments
 
LVL 6

Expert Comment

by:Triskelion
ID: 6980250
How did you bind the class to the control?
0
 

Author Comment

by:Daed
ID: 6980263
I didn't understand what do you mean. Plz explain more.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6980280
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

Author Comment

by:Daed
ID: 6980315
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
 
LVL 6

Expert Comment

by:Triskelion
ID: 6981498
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
 

Author Comment

by:Daed
ID: 6982701
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
 
LVL 6

Expert Comment

by:Triskelion
ID: 6983132
Can you add ANY other Active X control that works properly?
Do you have the Active X test container thingy?
0
 

Author Comment

by:Daed
ID: 6991108
Yes I can add other ActiveX controls that works properly and I tried my Control in Text container and everything worked fine.
0
 

Author Comment

by:Daed
ID: 11687647
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
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 11708544
PAQed, with points refunded (100)

Netminder
Site Admin
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question