#include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int aSide = 10; int bSide = 20; POINT rectExPoint; bool Inside (POINT mouse, POINT rectMidd, int a, int b) { if (mouse.x > rectMidd.x-a & mouse.x < rectMidd.x+a & mouse.y > rectMidd.y-b & mouse.y < rectMidd.y+b) { return true; } else { return false; } } int DrawRect(HDC hdc, int x, int y, int a, int b, COLORREF color) { HPEN hNPen=CreatePen(PS_SOLID,1, color); HPEN hOPen=(HPEN)SelectObject(hdc,hNPen); Rectangle(hdc, x-a , y-b, x+a, y+b); DeleteObject(SelectObject(hdc,hOPen)); return 0; } int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("Connect") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; 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_CROSS) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; rectExPoint.x = -1; rectExPoint.y = -1; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT (""), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, TEXT (""), 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)>0) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return (int)msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int iPrevX,iPrevY,cxClient,cyClient; static HDC hdc, hdcMem; static HBITMAP hBitmap , oldBitmap; PAINTSTRUCT ps; static POINT rectPoint; switch(message) { case WM_RBUTTONUP: hdc=GetDC(hwnd); rectExPoint.x = 100; rectExPoint.y = 100; DrawRect(hdc, rectExPoint.x, rectExPoint.y, aSide, bSide, RGB(0, 0, 0)); ReleaseDC(hwnd,hdc); return 0 ; case WM_MOUSEWHEEL: if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) { hdc=GetDC(hwnd); DrawRect(hdc, rectExPoint.x, rectExPoint.y, aSide, bSide, RGB(255, 255, 255)); aSide++; bSide++; DrawRect(hdc, rectExPoint.x, rectExPoint.y, aSide, bSide, RGB(0, 0, 0)); ReleaseDC(hwnd,hdc); }; if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) { hdc=GetDC(hwnd); DrawRect(hdc, rectExPoint.x, rectExPoint.y, aSide, bSide, RGB(255, 255, 255)); aSide--; bSide--; DrawRect(hdc, rectExPoint.x, rectExPoint.y, aSide, bSide, RGB(0, 0, 0)); ReleaseDC(hwnd,hdc); }; return 0 ; case WM_MOUSEMOVE: rectPoint.x = LOWORD (lParam); rectPoint.y = HIWORD (lParam); if((wParam & MK_LBUTTON) & Inside(rectPoint, rectExPoint, aSide, bSide)) { hdc=GetDC(hwnd); DrawRect(hdc, rectExPoint.x, rectExPoint.y, aSide, bSide, RGB(255, 255, 255)); rectExPoint = rectPoint; DrawRect(hdc, rectPoint.x, rectPoint.y, aSide, bSide, RGB(0, 0, 0)); ReleaseDC(hwnd,hdc); } return 0; case WM_CLOSE: SelectObject(hdcMem,hBitmap); DeleteObject (hBitmap); DeleteObject(hdcMem); PostQuitMessage (0); return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }