Solved

Using an ActiveX control in VC++

Posted on 2002-04-30
11
718 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Title # Comments Views Activity
MFC Dialog 9 54
mixString challenge 36 137
string initialization in java 11 122
wait notify demo infinite loop 3 148
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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