Pre-registering an ATL window class

╄→尐↘猪︶ㄣ 提交于 2019-12-05 19:08:38

What you are trying to do won't work. This is because the creation of the ATL/WTL Window must go through the ATL class. The class registers its this ptr with a window thunk. This thunk becomes the WNDPROC and replaces the HWND parameter of the WNDPROC with the this ptr of the object instance.

So in short, if you knew how ATL windowing worked under the hood, you would not endeavor to try this. If you were able to register the window class, the CreateWindowEx call would succeed in creating the window. However the WNDPROC thunk would not be created and there would be no object instance to associate your window with and none of your message handlers would called. Instead, see if you can create your window using the CWindowImpl::Create and pass your 3rd party library the hwnd of an ATL control once it is created.

You can use:

WNDPROC pUnusedWndSuperProc; 
pUnusedWndSuperProc = NULL;
CMyControl::GetWndClassInfo().Register(&pUnusedWndSuperProc);

Though... I'm not sure why you don't just create an instance of the window and keep it hidden. Its a little bit of overhead but it avoids mucking with the guts of the windowing logic (which is pretty complicated stuff... the last thing you want is some unexpected or unusual problem with "thunking").

Yigang Wu

You can call Win32 API RegisterClassEx function directly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!