#include <windows.h>
HWND hWnd;
LPCTSTR lpszClassName = "GameClass";
LPCTSTR lpszWindowName = "Game";
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return (0);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLing, int nShowCmd)
{
WNDCLASSEX wc;
MSG msg;
wc.cbSize = sizeof(wc);
wc.style = 0;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = lpszClassName;
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if (!RegisterClassEx(&wc))
{
return (0);
}
hWnd = CreateWindowEx(0,
lpszClassName,
lpszWindowName,
WS_OVERLAPPEDWINDOW,
0,
0,
640,
480,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
// Do Game Initialization
while (1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// Do Game Frame Code
}
}
// Do Game Shutdown
return (msg.wParam);
}
Edited by - Ecco2000 on 12/26/00 6:33:53 AM
Win32 Framework
After spending a few hours in the msdn library i've come up with this win32 framework code. please tell me your opinion on it's functionability as the framework for a game. Thanks.
"Don't make me come down there..." -GOD
I''d handle a WM_PAINT message and validate the invalidated RECT or windows''ll keep sending you WM_PAINT messages till you do.
Gyzmo
=======================
Meddle not in the affairs of dragons for you are crunchy and go well with toast.
Gyzmo
=======================
Meddle not in the affairs of dragons for you are crunchy and go well with toast.
Gyzmo=============================="Well is the world standard" - The Alchemist"Not in Canada!" - jonnyfish
Thanks Gyzmo, I put a counted under the WM_PAINT message and found that it had been fired around 10000 times in the course of a few seconds like you said. I''ve updated the code and now it only fires once unless you resize / uncover parts of the window.
"Don't make me come down there..." -GOD
Pleeaase explain me that "invalidated rect" stuff... I have about no idea what you mean!
please help!
please help!
Jan PieczkowskiBrainwave Studios
You might want to wrap the win32 stuff in a class. For an example check the resource section of my site;
http://members.home.net/eckiller
cheers,
ECKILLER
http://members.home.net/eckiller
cheers,
ECKILLER
ECKILLER
The_[PI]_ehT Validating and Invalidating rect is a way to force windows to update or not update a certain area of a window.
"Don't make me come down there..." -GOD
and use WaitMessage() in your while(){...}, this way u will not waste precious CPU time for doing nothing...
have fun
have fun
^cyer would I use WaitMessage even if i'm going to be doing rendering there. Like this...
Edited by - Ecco2000 on December 26, 2000 10:04:51 PM
// Do Game Initializationwhile (1){ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { break; } TranslateMessage(&msg); DispatchMessage(&msg); } else { WaitMessage(); // Do Game Frame Code }}// Do Game Shutdown
Edited by - Ecco2000 on December 26, 2000 10:04:51 PM
"Don't make me come down there..." -GOD
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement