Nasty runtime error with WM_PAINT
When I create a child window and initialize it as mentioned it runs ok; the global WNDPROC routes all messages via the SetWindowLong/GetWindowLong to the window and they are handled ok. ALL BUT THE WM_PAINT MESSAGE. The application crashes with a runtime error. The same occurs with WM_NCPAINT.
Could it be an issue with the paint messages?
LRESULT CALLBACK
WinControl::GlobalWndProc(HWND pHWnd, UINT pMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT
nResult = 0;
WinControl *
nControl = NULL;
MSG
nMsg = { 0 };
WinCriticalSection
nLock;
LPCREATESTRUCT
nLPStruct = { 0 };
nLock.Lock();
nControl = reinterpret_cast<WinControl *>(::GetWindowLong(pHWnd, GWL_USERDATA));
if((nControl == NULL) && (pMsg == WM_NCCREATE))
{
nLPStruct = reinterpret_cast<LPCREATESTRUCT>(lParam);
nControl = reinterpret_cast<WinControl *>(nLPStruct->lpCreateParams);
::SetWindowLong(pHWnd, GWL_USERDATA, (LONG)nControl);
}
if((nControl == NULL) || (!(::IsWindow(nControl->GetHWND()))))
{
nResult = ::DefWindowProc(pHWnd, pMsg, wParam, lParam);
}
else
{
nMsg.hwnd = pHWnd;
nMsg.lParam = lParam;
nMsg.wParam = wParam;
nMsg.message = pMsg;
/////////// THIS PART FAILS WHEN ITS WM_PAINT OR WM_NCPAINT ON THE CHILD WINDOW
/////////// (WS_CHILD | WS_VISIBLE)
nResult = nControl->WndProc(&nMsg);
nControl = NULL;
}
nLock.Unlock();
return nResult;
}

