Default Message Handler in a Class
Hey all, I've done all the reading:
Thread 1 (Started by me a long time ago)
And numerous others, which have explained over and over how to incorporate a member function of a class as the default message handler for the WNDPROC.
My important code looks like this:
However, both SetWindowLong() functions fail, and as a result, so does my GetWindowLong(), which results in my secondary MessageProc to never fire (and never handle any events).
long __stdcall cWindow::SMessageProc(HWND hWnd, unsigned int Msg, WPARAM wParam, LPARAM lParam)
long Temp = 0;
cWindow *TempWindow = NULL;
if(Msg == WM_NCCREATE)
LPCREATESTRUCT LPC = (LPCREATESTRUCT)lParam;
Temp = SetWindowLong(hWnd, GWL_USERDATA, (long)LPC->lpCreateParams);
if(Temp == 0)
MessageBox(NULL, "SetWindowLong1 Failed", "Error", MB_OK);
Temp = SetWindowLong(hWnd, 0, 1);
if(Temp == 0)
MessageBox(NULL, "SetWindowLong2 Failed", "Error", MB_OK);
return DefWindowProc(hWnd, Msg, wParam, lParam);
if((GetWindowLong(hWnd, 0)) != 0)
TempWindow = (cWindow*)GetWindowLong(hWnd, GWL_USERDATA);
return TempWindow->MessageProc(hWnd, Msg, wParam, lParam);
MessageBox(NULL, "GetWindowLong Failed", "Error", MB_OK);
return(DefWindowProc(hWnd, Msg, wParam, lParam));
In the thread I posted above (started by me a longer time ago), it seems I hit this very same snag, but it wasn't ever really solved. So, here I am again, hoping for some help :-) If anybody can guess why SetWindowLong() is failing, I would love to hear it.
I also looked up the GWL_USERDATA flag, which appears to be defined in Winuser.h. But tossing an:
Still didn't change anything.
P.S. I didn't post any more code because it seems most of the values for the SetWindowLong() calls are declared/initialized in this function.