Can't call CWnd::Create from COleControl C++

186 Views Asked by At

I am developing an ActiveX Control for a MFC app.

In this app I have a controle class:

class MyControl : public COleControl

and a CWnd class:

class MyCWnd : public CWnd

As well as other classes for the active x and an idl file...

Within the MyControl class I want to open the window MyCWnd as an MFC appartment (a thread where the window runs).

To do so I have an attribute theWnd in MyControl defined as:

MyCWnd theWnd

in a method withing MyControl I want to create the window by calling:

theWnd.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), NULL, AFX_IDW_PANE_FIRST, NULL);

but this line returns false.

How should I initialize then create (start) a CWnd within a COleControl class? If it is not possible is there another class I can inherit from than COleControl for an ActiveX controle?

1

There are 1 best solutions below

1
On

So I found a solution that seems to me like a hack:

theWnd.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), GetDesktopWindow(), AFX_IDW_PANE_FIRST, NULL)

The parent window is then the desktop. I don't know if it is a clean way to do it...