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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/* a minimal Windows API application skeleton, 32-bit */
#include <windows.h>
/* Window Procedure function prototype ========================================= */
/* this is a callback function, only the Windows operating system calls it
the application should NEVER call the window procedure directly */
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR lpCmdLine, int nShowCmd)
{
UNREFERENCED_PARAMETER(lpCmdLine);
/* define some variables */
const char szWinClass[] = "WinSkeleton32bit"; /* the name of the window class */
const CHAR szAppTitle[] = "Skeletal Windows API Application"; /* the app's title */
HWND hwnd; /* the handle to the created window */
MSG msg; /* a structure containing message information */
WNDCLASSEX wc; /* a structure containing the attributes of the application's window class */
/* define the window class */
wc.cbSize = sizeof(WNDCLASSEX); /* size of the WNDCLASSEX structure */
wc.hInstance = hInstance; /* handle to this instance */
wc.lpszClassName = szWinClass; /* window class name */
wc.lpfnWndProc = WndProc; /* points to the window procedure */
wc.style = CS_HREDRAW | CS_VREDRAW; /* redraw the window if the window changes size or location */
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* predefined icon */
wc.hIconSm = NULL; /* no small icon */
wc.hCursor = LoadCursor(NULL, IDC_ARROW); /* predefined cursor */
wc.lpszMenuName = NULL; /* no class menu */
wc.cbClsExtra = 0; /* no extra class info needed */
wc.cbWndExtra = 0; /* no extra window info needed */
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); /* predefined color brush for the client area background color */
/* register the defined window class */
if (0 == RegisterClassEx(&wc))
{
/* unable to register the window class, abort */
MessageBox(NULL, "Couldn't Register the Window Class!", "ERROR", MB_OK | MB_ICONERROR);
return FALSE;
}
/* now that a window class has been registered, create the main window */
hwnd = CreateWindow(szWinClass, /* name of window class to create */
szAppTitle, /* window title bar caption */
WS_OVERLAPPEDWINDOW, /* window style - this is the normal style for most main windows */
CW_USEDEFAULT, /* X coordinate - let Windows decide */
CW_USEDEFAULT, /* Y coordinate - let Windows decide */
CW_USEDEFAULT, /* width of the entire window - let Windows decide */
CW_USEDEFAULT, /* height of the entire window - let Windows decide */
NULL, /* no parent window */
NULL, /* no menu */
hInstance, /* handle to this instance */
NULL); /* no additional arguments */
/* check to see if window was successfully created */
if (NULL == hwnd)
{
/* couldn't create the main window, abort */
MessageBox(NULL, "Couldn't Create the Main Window!", "ERROR", MB_OK | MB_ICONERROR);
return FALSE;
}
/* display (and update) the newly created window */
ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd);
/* create the message loop - if GetMessage() returns zero the app is being closed */
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
TranslateMessage(&msg); /* translate virtual key messages into character messages */
DispatchMessage(&msg); /* send the message to the window procedure and return control to Windows */
}
return (int) msg.wParam;
}
/* processes the messages that Windows sends to the application */
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
/* choose which Windows messages you want to process */
switch(message)
{
/* the window is being destroyed, so tell Windows the application can be terminated.
this message is one every application is required to process,
all other messages are optional depending on the program */
case WM_DESTROY:
/* send a message to Windows the application can exit */
PostQuitMessage(0);
return 0;
}
/* let Windows default process any messages not specified in the switch statement */
return DefWindowProc(hwnd, message, wParam, lParam);
}
|