/* -------------------------------------------------------------------
MyWindows.c -- 基本窗口模型
--------------------------------------------------------------------*/
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HANDLE hStdin;
HANDLE hStdout;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
static TCHAR szClassName[] = TEXT("MyClass");
static TCHAR szAppName[] = TEXT("MyWindows");
HWND hWnd;
MSG uMsg;
WNDCLASS stWndClass;
AllocConsole();
hStdin = GetStdHandle(STD_INPUT_HANDLE);
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
stWndClass.style = CS_HREDRAW | CS_VREDRAW;
stWndClass.lpfnWndProc = WndProc;
stWndClass.cbClsExtra = 0;
stWndClass.cbWndExtra = 0;
stWndClass.hInstance = hInstance;
stWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
stWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
stWndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
stWndClass.lpszMenuName = NULL;
stWndClass.lpszClassName = szClassName;
RegisterClass(&stWndClass);
hWnd = CreateWindow(szClassName, szAppName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
while(GetMessage(&uMsg, NULL, 0, 0))
{
TranslateMessage(&uMsg);
DispatchMessage(&uMsg);
}
return uMsg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hDc;
PAINTSTRUCT stPs;
RECT stRect;
char buf[1024];
DWORD length;
switch(uMsg)
{
case WM_PAINT:
GetUpdateRect(hWnd, &stRect, FALSE);
hDc = BeginPaint(hWnd, &stPs);
wsprintf(buf, "GetUpdateRect:\t(left:%d)(top:%d)(right:%d)(bottom:%d)\n", stRect.left, stRect.top, stRect.right, stRect.bottom);
length = strlen(buf);
WriteFile(hStdout, buf, length, &length, 0);
wsprintf(buf, "BeginPaint:\t(left:%d)(top:%d)(right:%d)(bottom:%d)\n", stPs.rcPaint.left, stPs.rcPaint.top, stPs.rcPaint.right, stPs.rcPaint.bottom);
length = strlen(buf);
WriteFile(hStdout, buf, length, &length, 0);
EndPaint(hWnd, &stPs);
return 0;
case WM_DESTROY:
DestroyWindow(hWnd);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}