Hi, thx 4 your help.
now I can use the Callback-Function.
But now I have some other Problems.
My Callback is:
LRESULT CALLBACK COGL::WndProc(HWND hWnd,UINT uMsg,WPARAM wParam, LPARAM lParam)
{
COGL *ogl = new COGL;
switch (uMsg) {
case WM_ACTIVATE: {
if (!HIWORD(wParam)) {
ogl->active=TRUE; }
else
{
ogl->active=FALSE; }
return 0; }
case WM_SYSCOMMAND: {
switch (wParam) {
case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; }
break; }
case WM_CLOSE: {
PostQuitMessage(0); return 0; }
case WM_KEYDOWN: {
ogl->keys[wParam] = TRUE; return 0; }
case WM_KEYUP: {
ogl->keys[wParam] = FALSE; return 0; }
case WM_SIZE: {
ogl->ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); return 0; }
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
When the program runs, and I press the F1-Key (to resize screen) nothing happens.
I got the error keys[]: no this operator when i debug the program.
I think keys and other commands doesn't get the wParam argument.
Why?
kaepteniglo
[edited by - kaepteniglo on November 21, 2002 4:33:05 AM]
Put NeHe's Tutorial in a Class
Could you explain why you create a new instance of COGL in the callback?
I hope you have understood the problem.
You can't make the callback a regular member-function, because it won't fit the specified callback declaration. This is because a member-function carries an invisible 'this-pointer'.
A member-function needs the 'this-pointer' to access it's member variables. A static member-function has no 'this-pointer'. So if you make the callback static you have solved that particular problem. But you now have a new problem. You want to be able to access your member functions/variables from your callback, right? To do this you need the 'this-pointer'. The very thing we just got rid of! What we need to do is somehow store the 'this-pointer' in a place where we can access it from the callback.
How to do this is explained in the links I supplied in previous posts. The explanations in those are unfortunatly not as clear as those in the article I had when I learned this. But as I said earlier, I can't find it again
Anyway, if I remember correctly, these are the steps you need to do.
1. You should pass your 'this-pointer' in the last parameter in CreateWindowEx.
2. In WM_NCCREATE, lParam consists of a CREATESTRUCT. The 'lpCreateParams' member of CREATESTRUCT will now contain your 'this-pointer'.
Fetch it and store it in thw windows userdata area. That way you can get the 'this-pointer' whenever you need it.
3. Later, whenever you need the 'this-pointer' you can get it from the windows extra data. Like this.
Btw I don't know if this code will compile, I took the code from the gamedev tutorial, and simplified it(took away the reinterpret_cast).
[edited by - lowlevel on November 22, 2002 8:52:46 AM]
I hope you have understood the problem.
You can't make the callback a regular member-function, because it won't fit the specified callback declaration. This is because a member-function carries an invisible 'this-pointer'.
A member-function needs the 'this-pointer' to access it's member variables. A static member-function has no 'this-pointer'. So if you make the callback static you have solved that particular problem. But you now have a new problem. You want to be able to access your member functions/variables from your callback, right? To do this you need the 'this-pointer'. The very thing we just got rid of! What we need to do is somehow store the 'this-pointer' in a place where we can access it from the callback.
How to do this is explained in the links I supplied in previous posts. The explanations in those are unfortunatly not as clear as those in the article I had when I learned this. But as I said earlier, I can't find it again
Anyway, if I remember correctly, these are the steps you need to do.
1. You should pass your 'this-pointer' in the last parameter in CreateWindowEx.
CreateWindowEx(...,...,..(void*)this);
2. In WM_NCCREATE, lParam consists of a CREATESTRUCT. The 'lpCreateParams' member of CREATESTRUCT will now contain your 'this-pointer'.
Fetch it and store it in thw windows userdata area. That way you can get the 'this-pointer' whenever you need it.
COGL *wnd;if(message == WM_NCCREATE){ // Fetch the 'this pointer' wnd = (COGL*)(((LPCREATESTRUCT)lparam)->lpCreateParams); // and store it in your windows userdata. ::SetWindowLong(hwnd, GWL_USERDATA, (long)(wnd));}
3. Later, whenever you need the 'this-pointer' you can get it from the windows extra data. Like this.
wnd = (COGL*)(::GetWindowLong(hwnd, GWL_USERDATA));// Now you can use 'wnd' to access your member variables/functionswnd->ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
Btw I don't know if this code will compile, I took the code from the gamedev tutorial, and simplified it(took away the reinterpret_cast).
[edited by - lowlevel on November 22, 2002 8:52:46 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement