Re: Child windows and OOP
Quote:
how can i pass the object's address when creating child windows?
Don't you create the ones with CreateWindowEx? If yes, act the same way you did before.
Re: Child windows and OOP
A few things. As stated before, if using CreateWindowEx your CHILD windows will get the WM_CREATE message.
Also, there is a more elegant function to use for storing window data properties, has been since Windows 2000. It's call SetProp/GetProp. There are ANSI and UNICODE versions of these functions.
Code:
class CWindow
{
protected:
HWND m_hWindowHandle;
virtual INT_PTR WindowProcess(UINT message,WPARAM wParam,LPARAM lParam)
{
// message processing here
}
static INT_PTR CALLBACK HandleWindowProcess(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
// first message passed to a window is WM_NCCREATE
if (message == WM_NCCREATE)
{
LPCREATESTRUCTW lpCreate = reinterpret_cast<LPCREATESTRUCTW>(lParam);
CWindow * pWindow = reinterpret_cast<CWindow *>(lpCreate->lpCreateParams);
pWindow->m_hWindowHandle = hWnd;
::SetPropW(hWnd,L"WindowObject");
return pWindow->WindowProcess();
}
else
{
CWindow * pWindow = reinterpret_cast<CWindow *>(::GetPropW(hWnd,L"WindowObject"));
if (pWindow != NULL)
{
return pWindow->WindowProcess(message,wParam,lParam);
}
else
{
return ::DefWindowProcW(hWnd,message,wParam,lParam);
}
}
}
};