Windows繪圖中的GDI映射模式

來源:互聯網
上載者:User

標籤:屬性   bsp   alt   rect   計算   img   viewport   編程   amp   

  

  對Windows編程新手來說,GDI編程中最困難的部分就是映射模式(Mapping Mode)。

      什麼是映射模式?

      我們知道,GDI畫圖是在裝置描述表這個邏輯意義上的顯示平面上進行,其使用的是邏輯座標,簡單地說,映射模式就是裝置描述表的屬性,用於確定從邏輯座標到裝置座標值的轉換方式。

       Windows支援8中映射模式:MM_TEXT為預設。

   

  

  /* Mapping Modes

       #define MM_TEXT                   1

       #define MM_LOMETRIC           2

       #define MM_HIMETRIC            3

       #define MM_LOENGLISH          4

       #define MM_HIENGLISH           5

       #define MM_TWIPS                6

       #define MM_ISOTROPIC           7

       #define MM_ANISOTROPIC       8

       */

      

       CDC* pDC = GetDC();

 

       // 預設映射模式 MM_TEXT

      pDC->Ellipse(0, 0, 100, 100);

 

       // 設定映射模式 MM_LOMETRIC   y向下為負 0.1mm

       pDC->SetMapMode(MM_LOMETRIC);

       pDC->Ellipse(0, 0, 100, -100);

 

       // 設定映射模式 MM_HIMETRIC   y向下為負 0.01mm

       pDC->SetMapMode(MM_HIMETRIC);

       pDC->Ellipse(0, 0, 100, -100);

 

       // 設定映射模式 MM_LOENGLISH   y向下為負 0.01in  0.254mm    1英寸(in)=25.4毫米(mm)

       pDC->SetMapMode(MM_LOENGLISH);

       pDC->Ellipse(0, 0, 100, -100);

 

       // 設定映射模式 MM_HIENGLISH   y向下為負 0.001in 0.0254mm   1英寸(in)=25.4毫米(mm)

       pDC->SetMapMode(MM_HIENGLISH);

       pDC->Ellipse(0, 0, 100, -100);

 

       // 設定映射模式 MM_TWIPS   y向下為負 0.0007in   1英寸(in)=25.4毫米(mm)

   pDC->SetMapMode(MM_TWIPS);

   pDC->Ellipse(0, 0, 100, -100);

 

       /* 可程式化映射模式 */

       // 根據視窗尺寸按比例自動調節畫圖的輸出大小

       CRect rect;

       GetClientRect(&rect);

 

       // 各向異性 MM_ANISOTROPIC

       pDC->SetMapMode(MM_ANISOTROPIC);

       pDC->SetWindowExt(100, 100);

       pDC->SetViewportExt(rect.Width(), rect.Height());

       pDC->Ellipse(0, 0, 100, 100);

 

       pDC->SetMapMode(MM_ANISOTROPIC);

       pDC->SetWindowExt(100, -100);

       pDC->SetViewportExt(rect.Width(), rect.Height());

       pDC->Ellipse(0, 0, 100, -100);

 

       //各向同性  MM_ISOTROPIC

       pDC->SetMapMode(MM_ISOTROPIC);

       pDC->SetWindowExt(100, -100);

       pDC->SetViewportExt(rect.Width(), rect.Height());

       pDC->Ellipse(0, 0, 100, -100);

 

       pDC->SetMapMode(MM_ISOTROPIC);

       pDC->SetWindowExt(100, -100);

       pDC->SetViewportExt(rect.Width(), rect.Height());

       pDC->Ellipse(0, 0, 100, -100);

 

  

   CDC::SetWindowExt             設定“視窗範圍”

       CDC::SetViewportExt           設定“視口範圍”

       可以這樣認為,視窗的尺寸以邏輯單位計算,視口的尺寸以裝置尺寸或像素點計算。

       需要注意的是,在MM_ISOTROPIC模式下,應該首先調用SetWindowExt,否則部分視窗客戶區可能會因落在視窗的邏輯範圍之外而無法使用。

Windows繪圖中的GDI映射模式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.