-
App wont open
I'm using the tutorial from www.gametutorials.com to make a simple game, i started off just a plain window with a black background but when i compile it and run it, the window doesn't show up and after a while, i ended up copying almost the entire thing from the tutorial but the window still wouldn't show up. I'm new to win32 so the mistake is probably obvious.
Code:
HWND CreateMainWindow(HINSTANCE hInstance)
{
HWND hWnd = NULL;
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc.hInstance = hInstance;
wc.lpszClassName = "Game";
wc.lpfnWndProc = WinProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.lpszMenuName = NULL;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
RegisterClass(&wc);
hWnd = CreateWindow("Game",
"Game",
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
CW_USEDEFAULT,
CW_USEDEFAULT,
600,
600,
NULL,
NULL,
hInstance,
NULL);
g_hInstance = hInstance;
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
return hWnd;
}
Code:
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszargv,
int ishow)
{
HWND hWnd = CreateMainWindow(hThisInstance);
if (hWnd == NULL) return false;
init(hWnd);
return (int)MainLoop();
}
every function here have been declared and defined
Also, if anyone has that tutorial, does MainLoop return a WPARAM? the return value isnt used anywhere so why not void?
-
I don't see anything necessarily wrong with that code. What do your init, MainLoop, and WinProc functions look like?
-
What's the code of your WndProc ? Chances are that it is your problem.
-
Maybe there is one "break" or "return" missing from a WndProc case label.
That has happened to me pretty often.
-
Code:
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
deinit();
break;
default:
return DefWindowProc(hWnd, msg, lParam, wParam);
break;
}
return 0;
}
-
Oh, so i mixed up wparam with lparam...
thanks