0

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?

firehelm
  • 49
  • 5
  • Not sure that using `NULL` for the first parameter of the `CWnd::Create()` call is allowed. [Documentation](https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class?view=msvc-160#create). – Adrian Mole Jan 28 '21 at 17:16
  • @AdrianMole, I don't think this is a problem as in another project I saw the first parameter of create as `NULL` and it works fine. In that other project `CWnd::Create()` is called from a CWnd class so the 5th argument is defined as `this`. I am guessing the problem here is that `MyControl` is not a window. – firehelm Jan 28 '21 at 17:25
  • First, why do you use ActiveX? And yes in a thread, this is not enough for the 5th argument. You don't have a window yet. – Tom Tom Jan 31 '21 at 07:56

1 Answers1

0

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...

firehelm
  • 49
  • 5
  • 1
    I'm pretty sure, this is a dirty solution. Why don't you utilize a window of the hosting MFC application? Even if the ActiveX control needs to be invisible, it's a good idea to integrate it in the applications window hierarchy, so it gets WM_DESTROY messages and can react accordingly, for example. – thomiel Jan 29 '21 at 12:28