Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...