#include <windows.h>
// f prototype
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
--------- END OF m_ain.h START OF m_ain.cpp ----------
#include "m_ain.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HWND hWnd;
MSG Msg;
WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_CLASSDC, WindowProc, 0L, 0L, hInstance, NULL, NULL, NULL, NULL, "GameClass", NULL };
// reg class exit on err
if(!RegisterClassEx(&wcex))
return FALSE;
hWnd = CreateWindow("GameClass", "the title", WS_OVERLAPPEDWINDOW, 0, 0, 400, 400, NULL, NULL, hInstance, NULL);
// return if err on CreateWindow
if(hWnd == NULL)
return FALSE;
// show the window
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
// Clear out message structure
ZeroMemory(&Msg, sizeof(MSG));
// loop until msg = exit
while(Msg.message != WM_QUIT) {
// peek into queue to see if there's message waiting
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
} else {
// time-crusial stuff
}
}
// unreg class
UnregisterClass("GameClass", hInstance);
// exit
return 0;
}
// MSG procedure
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_DESTROY:
PostQuitMessage(0); // close app
break;
// handle other msg
default: return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
} ---------------------------------------
someone knowledge ends where
someone else knowledge starts