#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow) {
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
static TCHAR szAppName[] = TEXT("XZZ");
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
if(!RegisterClass(&wndclass)) {
MessageBox(NULL, TEXT("Register failure..."),
szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0)) {
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
void display(int* pcxBitmap, int* pcyBitmap) {
DEVMODE devmode;
int num = 0;
*pcxBitmap = *pcyBitmap = 0;
ZeroMemory(&devmode, sizeof(DEVMODE));
devmode.dmSize = sizeof(DEVMODE);
while(EnumDisplaySettings(NULL, num++, &devmode)) {
*pcxBitmap = max(*pcxBitmap, (int)devmode.dmPelsWidth);
*pcyBitmap = max(*pcxBitmap, (int)devmode.dmPelsHeight);
}
}
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam) {
static int cxClient, cyClient, cxBitmap, cyBitmap;
static HBITMAP hBitmap;
static HDC hdcMem;
HDC hdc;
PAINTSTRUCT ps;
static POINT point;
switch(message) {
case WM_CREATE:
display(&cxBitmap, &cyBitmap);
hdc = GetDC(hwnd);
hdcMem = CreateCompatibleDC(hdc);
hBitmap = CreateCompatibleBitmap(hdc, cxBitmap, cyBitmap);
if(!hBitmap) {
ReleaseDC(hwnd, hdc);
DeleteDC(hdcMem);
return 0;
}
SelectObject(hdcMem, hBitmap);
PatBlt(hdcMem, 0, 0, cxBitmap, cyBitmap, WHITENESS);
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_LBUTTONDOWN:
point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
return 0;
case WM_MOUSEMOVE:
hdc = GetDC(hwnd);
if(wParam & MK_LBUTTON) {
MoveToEx(hdc, point.x, point.y, NULL);
MoveToEx(hdcMem, point.x, point.y, NULL);
point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
LineTo(hdc, point.x, point.y);
LineTo(hdcMem, point.x, point.y);
}
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
BitBlt(hdc, 0, 0, cxClient, cyClient, hdcMem, 0, 0, SRCCOPY);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
DeleteObject(hBitmap);
DeleteDC(hdcMem);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
|