   Initializing Opengl with class wrapped window
  Hi,recently I've been writing an object wersion of opengl window, and i have a problem.The most important parts of my code:LRESULT CALLBACK WndProc(HWND hwnd,UINT message, WPARAM wParam,LPARAM lParam){if (message == WM_NCCREATE) {LPCREATESTRUCT cs = (LPCREATESTRUCT) lParam;SetWindowLong(hwnd, GWL_USERDATA, (long) cs->lpCreateParams);}COGLWindow *window = (COGLWindow *) GetWindowLong(hwnd, GWL_USERDATA);if (window)return window->OGLWndProc(hwnd, message, wParam, lParam);elsereturn DefWindowProc(hwnd, message, wParam, lParam);}LRESULT COGLWindow::OGLWndProc(HWND hwnd,UINT message, WPARAM wParam,LPARAM lParam){switch(message){case WM_CREATE:  hDC = GetDC(hwnd);g_HDC = hDC;   SetupPixelFormat(hDC);   wglCreateContext(hDC);   wglMakeCurrent(hDC, hRC);break;    . . . With this code(copied from tutorials) i managed to use window procedure as a class method, but Opengl initialization code simply doesnt work now. Does anybody know how to solve it?thx 4 response   
  "Doesn't work" is pretty vague.  What do you mean it doesn't work?  Does it never get called?  Do you get an exception or a crash?  What happens (or doesn't happen)?  Anyway, I noticed you're window creation handling is a little different than how I do it, so I'll do a little explaining.First, here is the code I use when handling the creation of a render window (i.e. what's in your WndProc function)   if (uMsg == WM_CREATE)   {  SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG((LPCREATESTRUCT(lParam))->lpCreateParams));  return 0;   }   RenderWindow *win = (RenderWindow*)(GetWindowLongPtr(hwnd, GWLP_USERDATA));   if (!win)  return DefWindowProc(hwnd, uMsg, wParam, lParam);Ok, you'll probably want to use SetWindowLongPtr rather than SetWindowLong because SetWindowLongPtr has officially superseded the SetWindowLong function (and the same goes for GetWindowLongPtr and GetWindowLong).Aside from that, it looks like the only real difference is that you call SetWindowLong on the WM_NCCREATE message and don't return anything (specific to the processing of that message, at least), whereas I listen for the WM_CREATE message and that I return 0 after handling it.  I don't think there is anything wrong with listening for WM_NCCREATE, but if you do listen for it and process it, MSDN says you should return TRUE.  Since you don't return TRUE after handling the WM_NCCREATE message, I'd guess that the rest of the code might be causing the callback to return some value other than TRUE that might be screwing up the creation of the window.  Anyway, try adding return TRUE; after you SetWindowLong (or rather, SetWindowLongPtr).   ;  First, tkanks for response.Unfortunately, adding return true after SetWindowLong(...) doesnt change the situation.The problem is that there is no error message, just OpenGL doesnt initialize, application behaves as if there was no initializing code(GetDC, SetupPixelFormat,etc.)   ;Quote:Original post by arczevFirst, tkanks for response.Unfortunately, adding return true after SetWindowLong(...) doesnt change the situation.The problem is that there is no error message, just OpenGL doesnt initialize, application behaves as if there was no initializing code(GetDC, SetupPixelFormat,etc.)How do you know that the initializing doesn't get called?  Have you stepped through the program with a debugger to see exactly what's going on?   ;  I knew because when I normally use non-object version of window procedure, this code makes the screen black and than I can draw in opengl mode.Ok, problem solved, The last parameter of CreateWindowEx(...) should be (void*)this, I had NULL   