Code:
//Code in main.cpp - call for the class:
wWindow mainWindow(WndProc, hInstance);
mainWindow.createGLWindow(className, windName, SCREEN_HEIGHT, SCREEN_WIDTH, 32);
//code in init.h - declaration of the class:
class wWindow
{
public:
wWindow(WNDPROC tWndProc, HINSTANCE hInst);
~wWindow();
HWND hwnd;
HINSTANCE hinstance;
HDC hdc;
WNDCLASSEX wndclass;
WNDPROC wndproc;
HGLRC hrc;
LPCSTR tclassName;
bool wWindow::createWindow(LPCSTR className, LPCSTR windowName, LPCSTR menuName, int height, int width);
bool wWindow::createGLWindow(LPCSTR className, LPCSTR windowName, int height, int width, int bits);
};
//code in Init.cpp - which contains the class:
wWindow::wWindow(WNDPROC tWndProc, HINSTANCE hInst)
{
wndproc = tWndProc;
hdc = NULL;
hinstance = hInst;
}
bool wWindow::createGLWindow(LPCSTR className, LPCSTR windowName, int height, int width, int bits)
{
wndclass = initWindowClass(className, hinstance, wndproc, NULL, NULL);
SetLastError(0);
DWORD eh = GetLastError();
RegisterClassEx(&wndclass);
eh = GetLastError();
hwnd = createWindowR(className, windowName, height, width, hwnd, hinstance);
hdc = GetDC(hwnd);
setPiFD(SCREEN_HEIGHT, SCREEN_WIDTH, 16, hdc);
if (!(hrc = wglCreateContext(hdc)))
{
MessageBox(NULL, "Error creating hRC", "Error", NULL);
}
wglMakeCurrent(hdc, hrc);
initGL();
ReSizeGLScene(SCREEN_WIDTH, SCREEN_HEIGHT);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
return true;
}
//The initWindowClass and createWindow functions:
NDCLASSEX initWindowClass(LPCTSTR className, HINSTANCE hinst, WNDPROC wndproc, LPCTSTR menuName, HBRUSH backGround)
{
WNDCLASSEX wndClass;
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndClass.lpfnWndProc = wndproc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hinst;
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = backGround;
wndClass.lpszMenuName = menuName;
wndClass.lpszClassName = className;
return wndClass;
}
HWND createWindowR(LPCTSTR className, LPCTSTR windName, int width, int height, HWND hwnd, HINSTANCE hinst)
{
hwnd = CreateWindowEx( NULL,
className,
windName,
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW,
0, 0,
width, height,
NULL,
NULL,
hinst,
NULL);
if (!hwnd)
{
MessageBox(NULL, "Error creating window", "ERROR", NULL);
return NULL;
}
return hwnd;
}
Help would be really appreciated -