Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

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

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?

question from:https://stackoverflow.com/questions/65941779/cant-call-cwndcreate-from-colecontrol-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...