Resort to thunks or tls? In this case, I do not know what you mean by impact, but it is quite easy - albeit a bit confusing - to load a window into the shell of the C ++ class.
class UserWindow { HWND _hwnd; public: operator HWND(){ return _hwnd; } UserWindow():_hwnd(0){} ~UserWindow(){ if(_hwnd){ SetWindowLongPtr(GWL_USERDATA,0); DestroyWindow(_hwnd); } static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ UserWindow* self = 0; if(uMsg == WM_CREATE) { LPCREATESTRUCT crst = (LPCREATESTRUCT)lParam; self = (Window*)crst->lpCreateParams; SetWindowLongPtr(hwnd,GWL_USERDATA,(LONG_PTR)self); self->_hwnd = hwnd; } else self = (Window*)GetWindowLongPtr(hwnd,GWL_USERDATA); if(self){ LRESULT lr = self->WndProc(uMsg,wParam,lParam); if(uMsg == WM_DESTROY){ if(self = (Window*)GetWindowLongPtr(hwnd,GWL_USERDATA)) self->_hwnd = NULL; } return lr; } return DefWindowProc(hwnd,uMsg,wParam,lParam); } HWND Create(int x, int y, int w, int h, LPCTSTR pszTitle,DWORD dwStyle,DWORD dwStyleEx,LPCTSTR pszMenu,HINSTANCE hInstance, HWND hwndParent){ WNDCLASSEX wcex = { sizeof (wcex),0}; if(!GetClassInfo(hInstance,ClassName(),&wcex)){ wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WindowndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.lpszClassName = ClassName(); OnCreatingClass( wcex ); RegisterClassEx(&wcex); } return CreateWindowEx( dwStyleEx, ClassName(), pszTitle, dwStyle, x, y, w, h, hwndParent, pszMenu, hInstance, this); }
This is all a bit confusing, but that means the window can be safely destroyed by deleting the class, OR, being destroyed. During a call to CreateWindow, one or two size-related messages are sent before WM_CREATE sets GWL_USERDATA to "this", but they have practically no meaning. A window class is automatically created when the window is first created.
One thing this style of auto-registering classes on the first call to does not support is the creation of this window type as a control in a dialog box. To support this case, you will need to change an integer number of things ... provide a function for registering a static class ... the "new MyClass" in the WM_CREATE static handler ... it is not obvious to me how this can be done in the frame type style.