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
|
#include <Windows.h>
// message handler
LRESULT CALLBACK WndProc(HWND hWindow, UINT iMessage,WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(
HINSTANCE hInstance, // Handle to the current instance
HINSTANCE hPrevInst, // Handle to the previous instance
LPSTR lpCmdLine, // Pointer to the command line
int nShowCmd // Shows the state of the window
)
{
WNDCLASS kWndClass; // window object
// set visual properties of the window
kWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
kWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
kWndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
// set system properties of the window
kWndClass.hInstance = hInstance;
kWndClass.lpfnWndProc = (WNDPROC)WndProc;
kWndClass.lpszClassName = TEXT("01 Basic Window");
// set extra properties
kWndClass.lpszMenuName = NULL;
kWndClass.cbClsExtra = NULL;
kWndClass.cbWndExtra = NULL;
kWndClass.style = NULL;
// register the window object
if(!RegisterClass(&kWndClass))
{
MessageBox(NULL, TEXT("Window Registration Failed!"), TEXT("Error!"),
MB_ICONEXCLAMATION | MB_OK);
return -1;
}
HWND hWindow; // The window
hWindow = CreateWindow(
TEXT("01 Basic Window"), // Registered class name
TEXT("A Blank Window"), // Application window name
WS_OVERLAPPEDWINDOW | WS_VISIBLE, // Window style
CW_USEDEFAULT, // Horizontal position of the window
CW_USEDEFAULT, // Vertical position of the window
CW_USEDEFAULT, // Window width
CW_USEDEFAULT, // Window height
NULL, // Handle to the parent window
NULL, // Handle to the menu the identifier
hInstance, // Handle to the application instance
NULL // Pointer to the window-creation data
);
// Check if it failed to create the window successfully
if(!hWindow)
return FALSE;
ShowWindow(hWindow,nShowCmd);
UpdateWindow(hWindow);
MSG kMessage; // Message
// Message Loop
while( GetMessage(&kMessage,hWindow,0,0)!= FALSE )
{
TranslateMessage(&kMessage);
DispatchMessage(&kMessage);
}
return kMessage.wParam;
}
LRESULT CALLBACK WndProc(HWND hWindow, UINT iMessage,WPARAM wParam, LPARAM lParam)
{
switch(iMessage)
{
case WM_CLOSE:
DestroyWindow(hWindow);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWindow,iMessage,wParam,lParam);
}
return 0;
}
|