Ken you're a saviour when it comes to windows programming.
MSDN says:
GWLP_WNDPROC
Sets a new address for the window procedure.
Just a quick question:
As far as my reading goes, wouldn't that mean you can change the WNDPROC from your static, to your non-static after creation?
I.e.
Code:
SetWindowLongPtr(hWnd, GWLP_WNDPROC, &MessageProc);
Where MessageProc() is the non-static message handler.
Although, a quick test of that after the creation of my hWnd object yielded the error:
error C2276: '&' : illegal operation on bound member function expression
Which makes me think that it can't be that simple.
So, back on topic.
I've switched my GetWindowLong() and SetWindowLong() to their superceding counterparts (though none of the parameters change, which makes me wonder why these were ever available in the first place...were the Ptrs added after?)
And it is indeed the (LPCREATESTRUCT) that is causing the problem (the MessageBox is popping up).
Another quick question:
Code:
reinterpret_cast<LPCREATESTRUCT>(lParam);
Is that the equivalent typecast of:
Code:
(LPCREATESTRUCT)lParam;
Is one C, and the other C++ related?
And back to the main problem:
lpCreateParams is failing.
Just to show I'm researching and really trying to figure this out on my own...MSDN says:
lpCreateParams
Contains additional data which may be used to create the window. If the window is being created as a result of a call to the CreateWindow or CreateWindowEx function, this member contains the value of the lpParam parameter specified in the function call.
However, lpCreateParams doesn't take any parameters, so it can't really be blamed for anything. I'm assuming the lpParam being referred to is the one in the CreateWindow() function.
Code:
//CREATE OUR WINDOW
hWnd = CreateWindow(
ClassName, //OUR CLASS NAME
"Game", //THE TITLE FOR OUR WINDOW
WindowStyles, //APPLY OUR STYLES
(GetSystemMetrics(SM_CXSCREEN) / 2) - (Width / 2), //PLACE IN THE HORIZONTAL CENTRE
(GetSystemMetrics(SM_CYSCREEN) / 2) - (Height / 2), //PLACE IN THE VERTICAL CENTRE
Width, //WIDTH OF THE WINDOW
Height, //HEIGHT OF THE WINDOW
NULL,
NULL,
*hInstance, //OUR HINSTANCE
NULL); //OUR lpParam!!!
Looks like I'm setting it to NULL...so, off I go to find a value to set here...hmm...what would be appropriate? (It is now 11:02PM)
11:28
My first logical guess is to pass this as the lpParam...no dice...
I'll throw the question out there: what do I add? I'll keep on tossing in random variable names until somebody helps me out in hopes of getting lucky
Thanks for reading/skimming.
Edit:
Whoa, whoa whoa.
MSDN:
lpParam
[in] Pointer to a value to be passed to the window through the CREATESTRUCT structure passed in the lpParam parameter of the WM_CREATE message. If an application calls CreateWindow to create a multiple-document interface (MDI) client window, lpParam must point to a CLIENTCREATESTRUCT structure.
CREATESTRUCT??? Jeez. Okay, I'm gonna go make one and see what happens. (11:41)
11:43
No! No! No!
lpCreateParams is a parameter of the CREATESTRUCT? It's one big vicious circle! I'm gonna go watch Saturday Night Live in hopes that it'll be funny finally.
12:56
It WAS this
Turns out I misread the code before and wrote:
Code:
long __stdcall cWindow::SMessageProc(HWND hWnd, unsigned int Msg, WPARAM wParam, LPARAM lParam)
{
cWindow *TempWindow = (cWindow*)GetWindowLong(hWnd, GWL_USERDATA);
if(!TempWindow)
{
if(Msg == WM_NCCREATE)
{
LPCREATESTRUCT LPC = (LPCREATESTRUCT)lParam;
if(LPC->lpCreateParams)
{
TempWindow = (cWindow*)LPC->lpCreateParams;
SetWindowLong(hWnd, GWL_USERDATA, (LONG)TempWindow);
}
else
{
MessageBox(NULL, "WM_NCCREATE Failed", "Error", MB_OK);
return -1;
}
}
}
else
{
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return TempWindow->MessageProc(hWnd, Msg, wParam, lParam);
}
Note the position of the last else. Meaning the TempWindow->MessageProc() would never fire. The else has to be nested one level deeper in that chunk of code.
Hooray! Thanks for the point in the right direction Ken