Code:
#include "window.h"
RECT windowRect = {100, 100, 400, 400};
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
void MakeWindow(HINSTANCE hInstance, char * className, char * title, int iCmdShow);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
MakeWindow(hInstance,"Windows Class","Title",iCmdShow);
}
void MakeWindow(HINSTANCE hInstance, char * className, char * title, int iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wndClass;
wndClass.cbSize = sizeof(wndClass);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = className;
RegisterClassEx (&wndClass);
hWnd = CreateWindow(title,wndClass,WS_OVERLAPPEDWINDOW,windowRect.left,windowRect.top,windowRect.right,windowRect.bottom,NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,iCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClassEx(wndClass,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch(iMsg)
{
case WM_CLOSE:
case WM_QUIT:
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}