1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <windows.h>
#include <windowsx.h>
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPCSTR lpCmdLine, int nCmdShow)
{
//the handle for the window, filled by a function
HWND hWnd;
//this struct holds information for the window class
WNDCLASSEX wc;
//clear out the window class for use
ZeroMemory(&wc, sizeof(WNDCLASSEX));
//fill in the struct with the needed information
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"WindowClass1";
//Register the window class
RegisterClassEx(&wc);
//create the window and use the result as the handle
hWnd = CreateWindowEx(NULL,
L"WindowClass1",
L"Our First Windowed Program",
WS_OVERLAPPEDWINDOW,
300,
300,
500,
400,
NULL,
NULL,
hInstance,
NULL);
//display the window on the screen
ShowWindow(hWnd, nCmdShow);
//enter the main loop
//this struct holds Windows Event Messages
MSG msg;
//wait for the next message in thr queue, store the result in 'msg'
while (GetMessage(&msg, NULL, 0, 0))
{
//Translate keystroke messages into the right format
TranslateMessage(&msg);
//send the message to the WindowProc function
DispatchMessage(&msg);
}
return msg.wParam;
}
//this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//sort through and find what code to run for the message given
switch (message)
{
//this message is read when the window is closed
case WM_DESTROY:
{
//close the application entirely
PostQuitMessage(0);
return 0;
} break;
}
//Handle any messages the switch statement didn't
return DefWindowProc(hWnd, message, wParam, lParam);
}
|