SetMapMode使用问题

燕赵飞歌 2015-09-01 05:25:46
SetMapMode在一个函数中设定后,在另一个函数中调用GetMapMode后又恢复成了默认的模式。
SetMapMode是非模态的?每次使用必须先调用然后在写后边的代码?尤其是在其他函数中调用DPtoLP等函数时,要先SetMapMode等函数才行。
刚用有些不熟悉,还请多多指教.
...全文
227 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgl7903 2015-09-02
  • 打赏
  • 举报
回复
引用 4 楼 Fireindark 的回复:
楼上的哥们,你们是怎么用的?在一个新的button下 执行一下画图操作 或是在MouseMove下执行一下DPtoLP操作 你看看坐标会变成之前设定的坐标吗? 比如在Paint中: ::SetMapMode(dc.GetSafeHdc(),MM_ANISOTROPIC); ::SetWindowExtEx(dc.GetSafeHdc(),320,320,NULL); ::SetViewportExtEx(dc.GetSafeHdc(),cRect.Width(),-cRect.Height(),NULL); ::SetViewportOrgEx(dc.GetSafeHdc(),cRect.Width()/2,cRect.Height()/2,NULL); 在新的button或是mousemove下直接使用画图或是DPtoLP函数 无法获得逻辑坐标
你用的这几个函数都会返回之前的状态和坐标, 备份之,用完了再恢复
燕赵飞歌 2015-09-02
  • 打赏
  • 举报
回复
楼上的哥们,你们是怎么用的?在一个新的button下 执行一下画图操作 或是在MouseMove下执行一下DPtoLP操作 你看看坐标会变成之前设定的坐标吗? 比如在Paint中: ::SetMapMode(dc.GetSafeHdc(),MM_ANISOTROPIC); ::SetWindowExtEx(dc.GetSafeHdc(),320,320,NULL); ::SetViewportExtEx(dc.GetSafeHdc(),cRect.Width(),-cRect.Height(),NULL); ::SetViewportOrgEx(dc.GetSafeHdc(),cRect.Width()/2,cRect.Height()/2,NULL); 在新的button或是mousemove下直接使用画图或是DPtoLP函数 无法获得逻辑坐标
燕赵飞歌 2015-09-02
  • 打赏
  • 举报
回复
好像搞明白了! 可能是用了多个GetDC的原因
赵4老师 2015-09-01
  • 打赏
  • 举报
回复
CDC::SetMapMode virtual int SetMapMode( int nMapMode ); Return Value The previous mapping mode. Parameters nMapMode Specifies the new mapping mode. It can be any one of the following values: MM_ANISOTROPIC Logical units are converted to arbitrary units with arbitrarily scaled axes. Setting the mapping mode to MM_ANISOTROPIC does not change the current window or viewport settings. To change the units, orientation, and scaling, call the SetWindowExt and SetViewportExt member functions. MM_HIENGLISH Each logical unit is converted to 0.001 inch. Positive x is to the right; positive y is up. MM_HIMETRIC Each logical unit is converted to 0.01 millimeter. Positive x is to the right; positive y is up. MM_ISOTROPIC Logical units are converted to arbitrary units with equally scaled axes; that is, 1 unit along the x-axis is equal to 1 unit along the y-axis. Use the SetWindowExt and SetViewportExt member functions to specify the desired units and the orientation of the axes. GDI makes adjustments as necessary to ensure that the x and y units remain the same size. MM_LOENGLISH Each logical unit is converted to 0.01 inch. Positive x is to the right; positive y is up. MM_LOMETRIC Each logical unit is converted to 0.1 millimeter. Positive x is to the right; positive y is up. MM_TEXT Each logical unit is converted to 1 device pixel. Positive x is to the right; positive y is down. MM_TWIPS Each logical unit is converted to 1/20 of a point. (Because a point is 1/72 inch, a twip is 1/1440 inch.) Positive x is to the right; positive y is up. Remarks Sets the mapping mode. The mapping mode defines the unit of measure used to convert logical units to device units; it also defines the orientation of the device’s x- and y-axes. GDI uses the mapping mode to convert logical coordinates into the appropriate device coordinates. The MM_TEXT mode allows applications to work in device pixels, where 1 unit is equal to 1 pixel. The physical size of a pixel varies from device to device. The MM_HIENGLISH, MM_HIMETRIC, MM_LOENGLISH, MM_LOMETRIC, and MM_TWIPS modes are useful for applications that must draw in physically meaningful units (such as inches or millimeters). The MM_ISOTROPIC mode ensures a 1:1 aspect ratio, which is useful when it is important to preserve the exact shape of an image. The MM_ANISOTROPIC mode allows the x- and y-coordinates to be adjusted independently. CDC Overview | Class Members | Hierarchy Chart See Also CDC::SetViewportExt, CDC::SetWindowExt,::SetMapMode
赵4老师 2015-09-01
  • 打赏
  • 举报
回复
我只会复制粘贴MSDN98
赵4老师 2015-09-01
  • 打赏
  • 举报
回复
SetMapMode The SetMapMode function sets the mapping mode of the specified device context. The mapping mode defines the unit of measure used to transform page-space units into device-space units, and also defines the orientation of the device's x and y axes. int SetMapMode( HDC hdc, // handle of device context int fnMapMode // new mapping mode ); Parameters hdc Handle to the device context. fnMapMode Specifies the new mapping mode. It can be any one of the following values: Value Description MM_ANISOTROPIC Logical units are mapped to arbitrary units with arbitrarily scaled axes. Use the SetWindowExtEx and SetViewportExtEx functions to specify the units, orientation, and scaling. MM_HIENGLISH Each logical unit is mapped to 0.001 inch. Positive x is to the right; positive y is up. MM_HIMETRIC Each logical unit is mapped to 0.01 millimeter. Positive x is to the right; positive y is up. MM_ISOTROPIC Logical units are mapped to arbitrary units with equally scaled axes; that is, one unit along the x-axis is equal to one unit along the y-axis. Use the SetWindowExtEx and SetViewportExtEx functions to specify the units and the orientation of the axes. Graphics device interface (GDI) makes adjustments as necessary to ensure the x and y units remain the same size (When the window extent is set, the viewport will be adjusted to keep the units isotropic). MM_LOENGLISH Each logical unit is mapped to 0.01 inch. Positive x is to the right; positive y is up. MM_LOMETRIC Each logical unit is mapped to 0.1 millimeter. Positive x is to the right; positive y is up. MM_TEXT Each logical unit is mapped to one device pixel. Positive x is to the right; positive y is down. MM_TWIPS Each logical unit is mapped to one twentieth of a printer's point (1/1440 inch, also called a "twip"). Positive x is to the right; positive y is up. Return Values If the function succeeds, the return value identifies the previous mapping mode. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. Remarks The MM_TEXT mode allows applications to work in device pixels, whose size varies from device to device. The MM_HIENGLISH, MM_HIMETRIC, MM_LOENGLISH, MM_LOMETRIC, and MM_TWIPS modes are useful for applications drawing in physically meaningful units (such as inches or millimeters). The MM_ISOTROPIC mode ensures a 1:1 aspect ratio. The MM_ANISOTROPIC mode allows the x-coordinates and y-coordinates to be adjusted independently. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. See Also Coordinate Spaces and Transformations Overview, Coordinate Space and Transformation Functions, GetMapMode, SetViewportExtEx, SetViewportOrgEx, SetWindowExtEx, SetWindowOrgEx

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧