So, if I make it a friend, can I still access member variables of the application class without making the application class global?
I noticed in an example from the book: "OpenGL game programming", they somehow get a pointer to the OGlWindow that's currently being used with this:
COGLWindow *glWindow = (COGLWindow*)GetWindowLong(hWnd, GWL_USERDATA);
They do this right at the top of their WinProc function. I don't understand how that's supposed to work, because GetWindowLong returns a long. I don't understand how that could possibly be cast to a COGLWindow pointer.
If you want to see their windProc, here it is:
(Its a friend of the COGLWindow by the way)
// WndProcOGL()// desc: the WndProc for the OpenGL windowLRESULT APIENTRY WndProcOGL(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ COGLWindow *glWindow = (COGLWindow*)GetWindowLong(hWnd, GWL_USERDATA); // make sure window has been created if ((glWindow == NULL) && (uMsg != WM_CREATE)) { return DefWindowProc(hWnd, uMsg, wParam, lParam); } // dispatch messages switch (uMsg) { case WM_CREATE: // window creation { HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); glWindow = (COGLWindow*)(((LPCREATESTRUCT)lParam)->lpCreateParams); SetWindowLong(hWnd, GWL_USERDATA, (LONG)glWindow); glWindow->hWnd = hWnd; return glWindow->Create(); } case WM_QUIT: case WM_CLOSE: // window close glWindow->Destroy(); PostQuitMessage(0); return 0; case WM_DESTROY: // window destroy glWindow->Destroy(); PostQuitMessage(0); return 0; case WM_ACTIVATEAPP: // activate app if (wParam) { if (glWindow->fullscreen) glWindow->BeginFullScreen(glWindow->width, glWindow->height, glWindow->bits); ShowWindow(hWnd, SW_RESTORE); UpdateWindow(hWnd); } else { ShowWindow(hWnd, SW_MINIMIZE); UpdateWindow(hWnd); if (glWindow->fullscreen) glWindow->EndFullScreen(); } return 0; case WM_PALETTECHANGED: // palette change glWindow->PaletteChanged(wParam); return 0; case WM_QUERYNEWPALETTE: // new palette return glWindow->QueryNewPalette(); case WM_PAINT: // paint glWindow->Paint(); return 0; case WM_SIZE: // window size if (wParam != SIZE_MINIMIZED) { glWindow->width = LOWORD(lParam); glWindow->height= HIWORD(lParam); glWindow->Size(); } return 0; case WM_LBUTTONDOWN: // left mouse button if (!glWindow->useDInput) { SetCapture(hWnd); Drag = lParam; bLMB = true; glWindow->OnMouseDownL(glWindow->GetNormalizedPosX(lParam), glWindow->GetNormalizedPosY(lParam)); } break; case WM_RBUTTONDOWN: // right mouse button if (!glWindow->useDInput) { SetCapture(hWnd); Drag = lParam; bRMB = true; glWindow->OnMouseDownR(glWindow->GetNormalizedPosX(lParam), glWindow->GetNormalizedPosY(lParam)); } break; case WM_MOUSEMOVE: // mouse movement { if (!glWindow->useDInput) { int x = glWindow->mouseX = glWindow->GetMouseX(lParam); int y = glWindow->mouseY = glWindow->GetMouseY(lParam); int dx = x - glWindow->GetMouseX(Drag); int dy = y - glWindow->GetMouseY(Drag); glWindow->OnMouseMove(x,y, glWindow->width, glWindow->height); if (GetCapture() == hWnd) { // left mouse button if (bLMB) { glWindow->OnMouseDragL(x,y, dx,dy); } // right mouse button if (bRMB) { glWindow->OnMouseDragR(x,y, dx,dy); } Drag = lParam; } } break; } case WM_LBUTTONUP: // left button release if (!glWindow->useDInput) { if ((GetCapture() == hWnd) && !bRMB) { ReleaseCapture(); } bLMB = false; glWindow->OnMouseUpL(); } break; case WM_RBUTTONUP: // right button release if (!glWindow->useDInput) { if ((GetCapture() == hWnd) && !bLMB) { ReleaseCapture(); } bRMB = false; glWindow->OnMouseUpR(); } break; case WM_KEYUP: if (!glWindow->useDInput) { glWindow->OnKeyUp((int)wParam); } return 0; case WM_KEYDOWN: if (!glWindow->useDInput) { glWindow->OnKeyDown((int)wParam); } return 0; default: break; } return DefWindowProc(hWnd, uMsg, wParam, lParam);}
[edited by - EGD Eric on March 21, 2004 4:49:53 PM]