写代码好几年了,突然想到自己学编程刚入门的那会最熟悉的代码,今天又把这段代码重新敲写了一遍,在此贴出来缅怀一下,也感谢《Windows程序设计》的作者:Charles Petzold 。
#include <Windows.h>
LRESULT CALLBACK WndProcCBK(HWND hWnd, UINT uMsgID, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG uMsg;
HWND hWnd;
WNDCLASS wndclass;
TCHAR szAppName[] = TEXT("szAppWindow");
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProcCBK;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("RegisterClass invoking error !"), szAppName, MB_ICONERROR | MB_OK);
return -1;
}
hWnd = CreateWindow(szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
while (GetMessage(&uMsg, NULL, 0, 0))
{
TranslateMessage(&uMsg);
DispatchMessage(&uMsg);
}
return uMsg.wParam;
}
LRESULT CALLBACK WndProcCBK(HWND hWnd, UINT uMsgID, WPARAM wParam, LPARAM lParam)
{
switch (uMsgID)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, uMsgID, wParam, lParam);
}