#include #include #define TIMER1 1 static LONG quarterx, quartery; static POINT p[4]; static double Angel; LRESULT CALLBACK Handle_fir(HWND, UINT, WPARAM, LPARAM); void DrawPic(HDC, double); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("Rectangle & Ellipse "); HWND hwnd1; MSG msg; WNDCLASS wndclass1; wndclass1.style = CS_HREDRAW | CS_VREDRAW; wndclass1.lpfnWndProc = Handle_fir; wndclass1.cbClsExtra = 0; wndclass1.cbWndExtra = 0; wndclass1.hInstance = hInstance; wndclass1.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass1.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass1.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wndclass1.lpszMenuName = NULL; wndclass1.lpszClassName = szAppName; if (!(RegisterClass(&wndclass1))) { MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd1 = CreateWindow(szAppName, TEXT("SetWorldTransform Test Origin"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd1, iCmdShow); UpdateWindow(hwnd1); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK Handle_fir(HWND hwnd1, UINT message, WPARAM wParam, LPARAM lParam) { static int cxClient, cyClient; HDC hdc1; PAINTSTRUCT ps; RECT rt; switch (message) { case WM_CREATE: SetTimer(hwnd1, TIMER1, 50, NULL); Angel = 0.0; return 0; case WM_TIMER: InvalidateRect(hwnd1, NULL, TRUE); return 0; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); quarterx = 1 * cxClient / 4; quartery = 1 * cyClient / 4; p[0].x = quarterx; p[0].y = 4 * quartery; p[1].x = 3 * quarterx; p[1].y = 4 * quartery; p[2].x = quarterx; p[2].y = 5 * quartery; p[3].x = 3 * quarterx; p[3].y = 5 * quartery; return 0; case WM_PAINT: { hdc1 = BeginPaint(hwnd1, &ps); Angel = Angel + 1.0; if (Angel == 361.0) Angel = 1.0; SetMapMode(hdc1, MM_ISOTROPIC); SetWindowExtEx(hdc1, 1000, 1000, NULL); SetViewportExtEx(hdc1, cxClient, cyClient, NULL); SetWindowOrgEx(hdc1, 500, 500, NULL); SetViewportOrgEx(hdc1, cxClient / 2, cyClient / 2, NULL); GetClientRect(hwnd1, &rt); FillRect(hdc1, &rt, WHITE_BRUSH); int nGraphicMode = SetGraphicsMode(hdc1, GM_ADVANCED); DrawPic(hdc1, Angel); EndPaint(hwnd1, &ps); return 0; } case WM_DESTROY: KillTimer(hwnd1, TIMER1); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd1, message, wParam, lParam); } void DrawPic(HDC hdc1, double Angel) { XFORM xForm; Angel = Angel * 3.1516926 / 180; float sinangel = sin(Angel); float cosangel = cos(Angel); xForm.eM11 = cosangel; xForm.eM12 = sinangel; xForm.eM21 = -sinangel; xForm.eM22 = cosangel; xForm.eDx = (float) (-2 * quarterx * cosangel + 2 * quartery * sinangel); xForm.eDy = (float) (-2 * quarterx * sinangel - 2 * quartery * cosangel); SetWorldTransform(hdc1, &xForm); OffsetWindowOrgEx(hdc1, -500, -500, NULL); MoveToEx(hdc1, 0, 15, NULL); LineTo(hdc1, 4 * quarterx, 15); RoundRect(hdc1, quarterx, 0, 5 * quarterx, 5 * quartery, quarterx / 2, quartery / 2); Arc(hdc1, quarterx, 0, 2 * quarterx, 1 * quartery / 2, quarterx, 1 * quartery / 8, 5 * quarterx / 4, 3 * quartery / 8); Rectangle(hdc1, quarterx, quartery, 3 * quarterx, 3 * quartery); Ellipse(hdc1, quarterx, quartery, 3 * quarterx, 3 * quartery); Polygon(hdc1, p, 4); }