先说下相关的API(具体含义例子代码中有注释):
int SetMapMode(
HDC hdc, // handle to device context
int fnMapMode // new mapping mode
);BOOL SetWindowExtEx(
HDC hdc, // handle to device context
int nXExtent, // new horizontal window extent
int nYExtent, // new vertical window extent
LPSIZE lpSize // original window extent
);BOOL SetViewportExtEx(
HDC hdc, // handle to device context
int nXExtent, // new horizontal viewport extent
int nYExtent, // new vertical viewport extent
LPSIZE lpSize // original viewport extent
);BOOL SetViewportOrgEx(
HDC hdc, // handle to device context
int X, // new x-coordinate of viewport origin
int Y, // new y-coordinate of viewport origin
LPPOINT lpPoint // original viewport origin
);
其中SetMapMode函数的fnMapMode参数(指定具体的映射方式):
fnMapMode [in] Specifies the new mapping mode. This parameter can be 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. 例子代码:
void SetIsotropic(HWND hWnd, HDC hdc) //将坐标系设置成笛卡尔坐标系
{
RECT rt = GetClientRect(hWnd,&rt); //获取窗口客户区的大小
SetMapMode(hdc,MM_ISOTROPIC); //指定坐标系映射方式
SetWindowExtEx(hdc,1000,1000,NULL); //设置坐标系的逻辑单位
SetViewportExtEx(hdc,rt.right,-rt.bottom,NULL); //设置坐标系的定义域和值域
SetViewportOrgEx(hdc,rt.right/2,rt.bottom/2,NULL);//设置坐标系的原点坐标
}
已经有(0)位网友发表了评论,你也评一评吧!
原创文章如转载,请注明:转载自Eddy Blog
原文地址:http://www.rrgod.com/program/76.html 欢迎订阅Eddy Blog。