以下是设置视图背景颜色的代码:void CTestView::OnDraw(CDC* pDC)
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rectClient;
CBrush brushBkColor;
GetClientRect(rectClient);
brushBkColor.CreateSolidBrush(RGB(255,0,0));
pDC->DPtoLP(rectClient);
pDC->FillRect(rectClient,&brushBkColor);
…
} 我有两个问题:1.我在MSDN中查看了GetClientRect()函数的说明是:void GetClientRect( LPRECT lpRect )const
其中的参数lpRect:Points to a RECT structure or a CRect object to receive the client coordinates. 也就是说,lpRect是一个指向RECT结构或者是一个CRect对象的指针,但是上面的GetClientRect(rectClient)参数是CRect rectClient,而rectClient并不是定义成指针的啊!2.void DPtoLP(LPRECT lpRect) const;的作用是Converts device units into logical units.This parameter is used for the simple case of converting one rectangle from device points to logical points.能不能具体的说一下是从什么样子的设备坐标转换到什么样子的逻辑坐标?为什么要转换坐标?谢谢!
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rectClient;
CBrush brushBkColor;
GetClientRect(rectClient);
brushBkColor.CreateSolidBrush(RGB(255,0,0));
pDC->DPtoLP(rectClient);
pDC->FillRect(rectClient,&brushBkColor);
…
} 我有两个问题:1.我在MSDN中查看了GetClientRect()函数的说明是:void GetClientRect( LPRECT lpRect )const
其中的参数lpRect:Points to a RECT structure or a CRect object to receive the client coordinates. 也就是说,lpRect是一个指向RECT结构或者是一个CRect对象的指针,但是上面的GetClientRect(rectClient)参数是CRect rectClient,而rectClient并不是定义成指针的啊!2.void DPtoLP(LPRECT lpRect) const;的作用是Converts device units into logical units.This parameter is used for the simple case of converting one rectangle from device points to logical points.能不能具体的说一下是从什么样子的设备坐标转换到什么样子的逻辑坐标?为什么要转换坐标?谢谢!
设备坐标系是指X方向向右,Y方向向下,原点在屏幕的左上角
逻辑坐标系是指X方向向右,Y方向向上,
以上是一般绘图语言中所认可的,在Windows程序设计中,指定窗口坐标系为逻辑坐标系,视图为设备坐标系,详情你可查阅Windows程序设计第五版中GDI一章:)
第一个问题:
实施坐标转换是因为坐标不统一的缘故
关于第一个问题,你再详细看一下receClient的含义
第2个问题设备坐标是以象素为单位,逻辑坐标就不一定,可以为毫米,可以为英寸,转化就是把设备坐标值计算到当前的逻辑坐标值,因为绘图函数用逻辑坐标啊
逻辑坐标Y方向也可以向下啊,没认真看书啊,你该好好看看Windows程序设计第五版中GDI一章:)