The struct is like this
Code:
typedef struct {
HINSTANCE hInstance;
HWND hwnd;
HDC hdc;
HGLRC hrc;
GLData data;
} Window;
GLData is another struct that holds data like the width and height of the screen.
WinMain:
Code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {
GLData wndDat = {800, 600, 32, 16, false, 100.0f};
Window window = {hInstance, NULL, NULL, NULL, wndDat};
WNDCLASSEX wc;
MSG msg;
bool isRunning;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), "MainIcon");
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), "MainIcon", IMAGE_ICON, 16, 16, 0);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "UVClass";
if (!RegisterClassEx(&wc)) {
ERRORBOX("Could not register class.");
return 0;
}
while(isRunning) {
if (createGLWindow(&window)) {
if (!init()) {
isRunning = false;
} else {
bool msgRun = true;
while (msgRun) {
if (PeekMessage(&msg, window.hwnd, 0, 0, PM_REMOVE) != 0) {
if (msg.message == WM_QUIT) {
if (msg.wParam == 1)
isRunning = false;
msgRun = false;
}
else {
if (msg.message == WM_SIZE) {
glSize(window.data);
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
} else {
if (Input::vkeys[VK_ESCAPE])
PostMessage(window.hwnd, WM_QUIT, 1, 0);
update(0);
draw();
SwapBuffers(window.hdc);
}
}
}
deInit();
destroyGLWindow(&window);
} else {
ERRORBOX("Window initialization failed.");
isRunning = false;
}
}
if (!UnregisterClass("UVClass", window.hInstance))
ERRORBOX("Could not unregister class.");
return 0;
}
And the window procedure:
Code:
RESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
case WM_CLOSE:
PostQuitMessage(1);
break;
case WM_KEYDOWN:
Input::vkeys[wParam] = true;
break;
case WM_KEYUP:
Input::vkeys[wParam] = false;
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
When I post a message to window.hwnd and then test for it in the loop, it works, but the window procedure doesn't seem to be working.
Edit:
The procedure must be working, sorry, that's what I use to check input, and that's working, for some reason it's just not getting the window messages.