LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ // retreive special data, in this case, a pointer to the CEngine object that created the window core::CEngine* engine = (core::CEngine*)GetWindowLong(hWnd, GWL_USERDATA); switch(message){ case WM_PAINT: { PAINTSTRUCT ps; HDC hDC = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); } return 0; case WM_SIZE: { /* wParam == SIZE_RESTORED: The window has been resized, but neither * the SIZE_MINIMIZED nor SIZE_MAXIMIZED value applies. */ if( wParam == SIZE_RESTORED ){ video::IVideoDriver* d = engine->getVideoDriver(); if( d != NULL ) d->resizeWindow( video::dimension2d(LOWORD(lParam), HIWORD(lParam)) ); } } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam);}
Okay, I'm trying to do it this way, but for some reason, the wndProc function is called before I can see the window created, and when I step through, I'm getting an error because 'engine' is NULL.
I'm assuming this is because WndProc is called to create the window and perform whatever is user-defined for WM_CREATE, but then why is it going into WM_SIZE? Because the window has been re-sized from whatever default to what I've specified in the CreateWindow function? Okay, sure, I can see that working, but then, how am I supposed to differentiate between the time that the window is created, but my info hasn't been put in, to when my info is in? I could always check if 'engine' != NULL, but then, release mode doens't NULL memory for you does it?
In case you wanted to know, here's the window creation bit (not the actual CreateWindowEx function, we all know what that looks like):
CEngine::CEngine(const video::dimension2d& screenSize): m_videoDriver(NULL), m_hwnd(NULL){ if( !createWindow(screenSize) ){ // inits 'm_hwnd' to a valid window handle util::Message::print("CEngine::CEngine: window could not be created."); } else{ util::Message::print("CEngine::CEngine: window creation was successful at %dx%d", (int)screenSize.width, (int)screenSize.height); m_videoDriver = new video::COpenGLDriver(screenSize, m_hwnd); m_sceneManager = new scene::CSceneGraph(m_videoDriver); // store pointer to this CEngine object for later retrieval in the WndProc function SetWindowLong(m_hwnd, GWL_USERDATA, (long)this); }}
Should I just move the SetWindowLong function to inside the 'createWindow' (CEngine member function) function?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper