GDI映射模式(mapping mode):
和映射模式紧密相关的还有4个其它的设备环境属性:
1.窗口原点(window origin)
2.视口原点(viewport origin)
3.窗口范围(window extents)
4.视口范围(viewport extents)
所有GDI函数中(如TextOut),参数坐标值都是“逻辑单位(logical unit)”, Windows必须将逻辑单位转换为“设备单位(device unit)”
Windows定义了8种映射模式。他们在WINGDI.H中定义的标识符如下表示.
映射模式被定义为从“窗口”(window)(逻辑坐标)到“视口”(viewport)(设备坐标)的映射。
测试代码:
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static int cxClient,cyClient; int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); return 0; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... /* //SetMapMode(hdc,MM_ISOTROPIC); SetMapMode(hdc,MM_ANISOTROPIC); //会拉伸 SetWindowExtEx(hdc, 32767,32767,NULL); SetViewportExtEx(hdc,cxClient,-cyClient,NULL); SetViewportOrgEx(hdc,0,cyClient,NULL); //MoveToEx(hdc,0,0,NULL); LineTo(hdc,32767,32767); */ SetMapMode(hdc,MM_ISOTROPIC); SetWindowExtEx(hdc,1000,1000,NULL); SetViewportExtEx(hdc,cxClient/2,-cyClient/2,NULL); //(xWinOrg,yWinOrg),(xViewOrg,yViewOrg) 均默认为(0,0) //SetWindowOrgEx(hdc,cxClient/2,cyClient/2,NULL); SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL); Rectangle(hdc,-200,-200,200,200); MoveToEx(hdc,-200,-200,NULL); LineTo(hdc,200,200); //Window偏移 SetWindowOrgEx(hdc,-50,-50,NULL); Rectangle(hdc,-200,-200,200,200); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }