Solved

Using an ActiveX control in VC++

Posted on 2002-04-30
11
713 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now