#include <Windows.h>
HWND hParent, hBitMap, hDeskTop;
HDC hMemDC;
HBITMAP hBit;
HMODULE hModule;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
WNDCLASS wc;
static TCHAR* szAppName = TEXT("大灰机");
HWND hwnd = NULL;
MSG msg;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
if (!RegisterClass(&wc))
{
MessageBox(NULL, TEXT("程序只能在WindowsNT下运行"),
szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName,
TEXT("大灰机"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
200,
230,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
RECT rect;
POINT point;
HDC hDC, hDeskTopDC, hBitDC;
switch (message)
{
case WM_CREATE:
hBitMap = CreateWindowEx(0, TEXT("STATIC"),
NULL,
SS_CENTER | WS_CHILD | WS_VISIBLE,
19, 39, 127, 120,
hwnd,
NULL,
hModule,
NULL);
hDeskTop = GetDesktopWindow();
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
hDeskTopDC = GetDC(hDeskTop);
hMemDC = CreateCompatibleDC(hDeskTopDC);
hBit = CreateCompatibleBitmap(hDeskTopDC, 120, 120);
SelectObject(hMemDC, hBit);
ReleaseDC(hDeskTop, hDeskTopDC);
SetTimer(hwnd, 1, 80, NULL);
return 0;
case WM_CLOSE:
DeleteDC(hMemDC);
DeleteObject(hBit);
DestroyWindow(hwnd);
PostQuitMessage(0);
return 0;
case WM_TIMER:
GetCursorPos(&point);
hDeskTopDC = GetDC(hDeskTop);
hBitDC = GetDC(hBitMap);
PatBlt(hMemDC, 0, 0, 120, 120, BLACKNESS);
StretchBlt(hMemDC, 0, 0, 120, 120, hDeskTopDC, point.x, point.y, 80, 80, SRCCOPY);
BitBlt(hBitDC, 0, 0, 120, 120, hMemDC, 0, 0, SRCCOPY);
ReleaseDC(hDeskTop, hDeskTopDC);
ReleaseDC(hBitMap, hBitDC);
return 0;
case WM_PAINT:
hDC = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
DrawText(hDC, TEXT("放大镜"), -1, &rect, DT_CENTER);
EndPaint(hwnd, &ps);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}