LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; int iMapMode; static int cxClient, cyClient; switch (message) { case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); //创建自界说映射 iMapMode = GetMapMode(hdc); SetMapMode(hdc, MM_ISOTROPIC); //各向同性(会去干与干预映射过程,将多余裁剪) //SetMapMode(hdc, MM_ANISOTROPIC); //各向异性(不会去干与干预,会自适应) SetWindowExtEx(hdc, 100, 100, NULL); //相当于取出本来逻辑窗口的100*100像素放大为此刻视口的1/2*1/2(1/4) 所以此刻视口所显示的最大尺寸为200*200 SetViewportExtEx(hdc, cxClient / 2, cyClient / 2, NULL); //设置视口原点在中心 SetViewportOrgEx(hdc, cxClient / 2, cyClient / 2, NULL); //MM_ISOTROPIC: windows为了保证按比例将整个视口落在视图中,会将多余的尺寸排除在外,若是有配景,,则多余为黑色,会以最大比例占据窗口(前提是和本来设置和视口和窗口之比不乱的前提下) //MM_ANISOTROPIC:则不会,而是成比例拉伸 Rectangle(hdc, -100, -100, 100, 100); Ellipse(hdc, -80, -80, 80, 80); EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }