win32/gl problems

hello, attempting to write a simple windows class to create opengl windows. but im having some problems and seeing that i suck/not good at windows programming thought i might post my problem here in search of help. I get my MessageBox error “couldn’t create window func”. If you could tell me what stupid error i did or left out please leave me a post! heres the code:
cwindow.h file

#ifndef CWINDOW#define CWINDOW#define WIN32_LEAN_AND_MEAN // trim the excess fat from Windows////// Includes#include <windows.h> // standard Windows app include#include <gl/gl.h> // standard OpenGL include#include <gl/glu.h> // OpenGL utilties#include <gl/glaux.h> // OpenGL auxiliary functionsclass cwindow{ HDC hDC; HINSTANCE hInstance; HGLRC hRC; HWND hWnd; WNDCLASSEX winClass; MSG msg; DWORD dwExStyle; DWORD dwStyle; RECT winRectangle; int iWidth, iHeight, iBits;public: void registerWindowData(); void setupWindow(char *cTitle); void renderLoop(); void setupPixelFormat(HDC t_hDC); MSG getMessage(){ return msg; } HWND getHwnd(){ return hWnd; } void setHDC(HDC t_DC){ hDC = t_DC; }// void setInstance(HINSTANCE i){ hInstane = i; } HDC getHDC(){ return hDC; }};#endif

cwindow.cpp

#include "cwindow.h"cwindow prog;float angle = 0.0f;//static HDC s_hDC; //used to pass DeviceContext on a global scale //*must find out when you need to define for overall //program so i can then define the class version w/ static //this lets me use static in WinMain and WndProc (which one loads first)?///////////////////int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){// prog.setInstance(hInstance); prog.registerWindowData(); prog.setupWindow(“Ren Engine: Build t01”); bool done = false; HWND t_hWnd = prog.getHwnd(); MSG t_msg = prog.getMessage(); while(!done){ PeekMessage(&t_msg,t_hWnd,NULL, NULL,PM_REMOVE); if(t_msg.message == WM_QUIT) done = true; else{ prog.renderLoop(); SwapBuffers(prog.getHDC()); TranslateMessage(&t_msg); DispatchMessage(&t_msg); } } return t_msg.wParam;}////////////////////LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ static HGLRC t_hRC; static HDC t_hDC; int width,height; switch(message){ case WM_CREATE: t_hDC = GetDC(hwnd); prog.setHDC(t_hDC); prog.setupPixelFormat(prog.getHDC()); t_hRC = wglCreateContext(prog.getHDC()); wglMakeCurrent(prog.getHDC(),t_hRC); return 0; break; case WM_CLOSE: wglMakeCurrent(prog.getHDC(),t_hRC); wglDeleteContext(t_hRC); PostQuitMessage(0); return 0; break; case WM_SIZE: height = HIWORD(lParam); width = LOWORD(lParam); if(height == 0) height = 1; glViewport(0, 0, width, height); // reset the viewport to new dimensions glMatrixMode(GL_PROJECTION); // set projection matrix current matrix glLoadIdentity(); // reset projection matrix // calculate aspect ratio of window gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); // set modelview matrix glLoadIdentity(); // reset modelview matrix return 0; break; default: break; } return (DefWindowProc(prog.getHwnd(),message,wParam,lParam));}///////////////////void cwindow::registerWindowData(){ winRectangle.top = (long)0; winRectangle.bottom = (long)0; winRectangle.right = (long)iWidth; winRectangle.left = (long)iHeight; winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = CS_HREDRAW | CS_VREDRAW; winClass.lpfnWndProc = WndProc; winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; winClass.hInstance = hInstance; winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winClass.hCursor = LoadCursor(NULL, IDC_ARROW); winClass.hbrBackground = NULL; winClass.lpszMenuName = NULL; winClass.lpszClassName = “Window”; winClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); if(!RegisterClassEx(&winClass)) ::MessageBox(prog.getHwnd(),“Cant Register Window Data”,“Error”,MB_OK); // printf("Error: Registing winClass Failed!
"); //put fullscreen later here dwExnostyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwnostyle=WS_OVERLAPPEDWINDOW; AdjustWindowRectEx(&winRectangle, dwStyle, FALSE, dwExStyle);}void cwindow::setupWindow(char *cTitle){ hWnd = CreateWindowEx(dwExStyle, “Window”, “stuff”, dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, winRectangle.right - winRectangle.left, winRectangle.bottom - winRectangle.top, NULL, NULL, hInstance, NULL); if(!hWnd) ::MessageBox(prog.getHwnd(),“Couldn’t Create Window”,“Error”,MB_OK);// printf("Error: CreateWindowEx Failed!
"); ShowWindow(hWnd,SW_SHOW); UpdateWindow(hWnd);}void cwindow::renderLoop(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); angle = angle + 0.1f; if (angle >= 360.0f) angle = 0.0f; glTranslatef(0.0f,0.0f,-5.0f); glRotatef(angle, 0.0f,0.0f,1.0f); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_TRIANGLES); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,1.0f,0.0f); glEnd();}void cwindow::setupPixelFormat(HDC t_hDC){ int iFormat; static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; iFormat = ChoosePixelFormat(t_hDC, &pfd); SetPixelFormat(t_hDC, iFormat, &pfd);}

If you see something i left out or just messed up on please leave me a post here. Thanks alot!

hello, attempting to write a simple windows class to create opengl windows. but im having some problems and seeing that i suck/not good at windows programming thought i might post my problem here in search of help. I get my MessageBox error “couldn’t create window func”. If you could tell me what stupid error i did or left out please leave me a post! heres the code:
////////////////////////////////cwindow.h

#ifndef CWINDOW
#define CWINDOW
#define WIN32_LEAN_AND_MEAN

//// Includes
#include <windows.h>
#include <gl/gl.h> #include <gl/glu.h>
#include <gl/glaux.h>
class cwindow{ HDC hDC; HINSTANCE hInstance; HGLRC hRC; HWND hWnd; WNDCLASSEX winClass; MSG msg; DWORD dwExStyle; DWORD dwStyle; RECT winRectangle; int iWidth, iHeight, iBits;public: void registerWindowData(); void setupWindow(char *cTitle); void renderLoop(); void setupPixelFormat(HDC t_hDC); MSG getMessage(){ return msg; } HWND getHwnd(){ return hWnd; } void setHDC(HDC t_DC){ hDC = t_DC; }// void setInstance(HINSTANCE i){ hInstane = i; } HDC getHDC(){ return hDC; }};#endif

////////////////////////////////cwindow.cpp

#include "cwindow.h"cwindow prog;float angle = 0.0f;//static HDC s_hDC; //used to pass DeviceContext on a global scale //*must find out when you need to define for overall //program so i can then define the class version w/ static //this lets me use static in WinMain and WndProc (which one loads first)?///////////////////int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){// prog.setInstance(hInstance); prog.registerWindowData(); prog.setupWindow(“Ren Engine: Build t01”); bool done = false; HWND t_hWnd = prog.getHwnd(); MSG t_msg = prog.getMessage(); while(!done){ PeekMessage(&t_msg,t_hWnd,NULL, NULL,PM_REMOVE); if(t_msg.message == WM_QUIT) done = true; else{ prog.renderLoop(); SwapBuffers(prog.getHDC()); TranslateMessage(&t_msg); DispatchMessage(&t_msg); } } return t_msg.wParam;}////////////////////LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ static HGLRC t_hRC; static HDC t_hDC; int width,height; switch(message){ case WM_CREATE: t_hDC = GetDC(hwnd); prog.setHDC(t_hDC); prog.setupPixelFormat(prog.getHDC()); t_hRC = wglCreateContext(prog.getHDC()); wglMakeCurrent(prog.getHDC(),t_hRC); return 0; break; case WM_CLOSE: wglMakeCurrent(prog.getHDC(),t_hRC); wglDeleteContext(t_hRC); PostQuitMessage(0); return 0; break; case WM_SIZE: height = HIWORD(lParam); width = LOWORD(lParam); if(height == 0) height = 1; glViewport(0, 0, width, height); // reset the viewport to new dimensions glMatrixMode(GL_PROJECTION); // set projection matrix current matrix glLoadIdentity(); // reset projection matrix // calculate aspect ratio of window gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); // set modelview matrix glLoadIdentity(); // reset modelview matrix return 0; break; default: break; } return (DefWindowProc(prog.getHwnd(),message,wParam,lParam));}///////////////////void cwindow::registerWindowData(){ winRectangle.top = (long)0; winRectangle.bottom = (long)0; winRectangle.right = (long)iWidth; winRectangle.left = (long)iHeight; winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = CS_HREDRAW | CS_VREDRAW; winClass.lpfnWndProc = WndProc; winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; winClass.hInstance = hInstance; winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winClass.hCursor = LoadCursor(NULL, IDC_ARROW); winClass.hbrBackground = NULL; winClass.lpszMenuName = NULL; winClass.lpszClassName = “Window”; winClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); if(!RegisterClassEx(&winClass)) ::MessageBox(prog.getHwnd(),“Cant Register Window Data”,“Error”,MB_OK); // printf("Error: Registing winClass Failed!
"); //put fullscreen later here dwExnostyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwnostyle=WS_OVERLAPPEDWINDOW; AdjustWindowRectEx(&winRectangle, dwStyle, FALSE, dwExStyle);}void cwindow::setupWindow(char *cTitle){ hWnd = CreateWindowEx(dwExStyle, “Window”, “stuff”, dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, winRectangle.right - winRectangle.left, winRectangle.bottom - winRectangle.top, NULL, NULL, hInstance, NULL); if(!hWnd) ::MessageBox(prog.getHwnd(),“Couldn’t Create Window”,“Error”,MB_OK);// printf("Error: CreateWindowEx Failed!
"); ShowWindow(hWnd,SW_SHOW); UpdateWindow(hWnd);}void cwindow::renderLoop(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); angle = angle + 0.1f; if (angle >= 360.0f) angle = 0.0f; glTranslatef(0.0f,0.0f,-5.0f); glRotatef(angle, 0.0f,0.0f,1.0f); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_TRIANGLES); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,1.0f,0.0f); glEnd();}void cwindow::setupPixelFormat(HDC t_hDC){ int iFormat; static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; iFormat = ChoosePixelFormat(t_hDC, &pfd); SetPixelFormat(t_hDC, iFormat, &pfd);}

Try posting your code on more than one line so people can read it.