• Windows GDI 映射模式(出自:Windows程序设计第5版-珍藏版)


    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;
    }
    

      

  • 相关阅读:
    LeetCode 1122. Relative Sort Array (数组的相对排序)
    LeetCode 46. Permutations (全排列)
    LeetCode 47. Permutations II (全排列 II)
    LeetCode 77. Combinations (组合)
    LeetCode 1005. Maximize Sum Of Array After K Negations (K 次取反后最大化的数组和)
    LeetCode 922. Sort Array By Parity II (按奇偶排序数组 II)
    LeetCode 1219. Path with Maximum Gold (黄金矿工)
    LeetCode 1029. Two City Scheduling (两地调度)
    LeetCode 392. Is Subsequence (判断子序列)
    写程序判断系统是大端序还是小端序
  • 原文地址:https://www.cnblogs.com/wucg/p/3323517.html
Copyright © 2020-2023  润新知