Pre-register ATL window class

I use a combination of ATL and WTL for a project and inferred my own class from CWindowImpl, which looks something like this:

class CMyControl : public CWindowImpl<CMyControl>
{
public:
    DECLARE_WND_CLASS(_T("MyClassName"))
    ...
    BEGIN_MSG_MAP(CMyControl)
        ...
    END_MSG_MAP()
};

This is good, and if I use CMyControl::Createto create an instance of the control, then it works fine, since under the hood the function CWindowImpl::Createregisters the Win32 class (in this case it is called MyClassName).

However, this behavior - the Win32 class is registered when an instance is created, which causes me a headache. I want to be able to register the class up in order to use the class name with another third-party library that will create this window using a call to Win32 CreateWindowEx, but I cannot find an easy way to do this. Currently, I bypass this using staticas the class name CreateWindowEx, and then use CMyWindow::SubclassWindowto join your class, but it is kludge.

Does anyone know how to register a derived class CWindowImplwithout actually creating a window, so can I successfully pass the class name CreateWindowEx? I would think that there is a standard way to do this with ATL windows, since I cannot be the first to encounter this problem.

+3
3

, , . , ATL/WTL ATL. ptr thunk. thunk WNDPROC HWND WNDPROC ptr .

, , ATL , . , CreateWindowEx . WNDPROC thunk , , , . , CWindowImpl:: Create hwnd ATL .

+2

Win32 API RegisterClassEx.

0

:

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

Although ... I'm not sure why you are not just instantiating the window and keeping it hidden. Its a bit over the head, but it avoids bowling the cropping logic (which is pretty complicated stuff ... the last thing you want, some unexpected or unusual problems with "thunking").

0
source

Source: https://habr.com/ru/post/1703655/


All Articles