CRect::operator LPRECT

来源:互联网 发布:浙江省数据库三级 编辑:程序博客网 时间:2024/06/06 02:07
      When you use this function, you don't need the address-of ( &) operator. This operator will be automatically used when you pass a CRect object to a function that expects an LPRECT.
Example:
BOOL CMyDlg::OnInitDialog()
{           
          CDialog::OnInitDialog(); 
          // CWnd::GetWindowRect() takes a LPRECT, but we can 
          // simply pass our CRect object because of the LPRECT
         
 // cast operator in the CRect class.
        
 CRect rect; GetWindowRect(rect); 
        // Similarly, CWnd::MoveWindow() takes a LPCRECT but
       
 // the LPCRECT cast operator is used implicitly: 
         MoveWindow(rect, FALSE); 
        return TRUE;
 }

什么意思呢?
MFC定义了
LPRECT类型转换,那么在使用要求LPRECT类型指针的地方可以直接使用CRect对象。
例如:
void GetClientRect( LPRECT lpRect ) const;
BOOL Rectangle( LPCRECT lpRect );
BOOL Ellipse( LPCRECT lpRect );
这些函数中可以写为如下形式
 CRect rect;
GetClientRect(&rect);
pDC->Rectangle(&rect);
pDC->Ellipse(&rect);
也可以写为去掉&的形式
 CRect rect;
GetClientRect(rect);
pDC->Rectangle(rect);
pDC->Ellipse(rect); 
实例:
void CMy123View::OnDraw(CDC* pDC)
{
CMy123Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)return;
// TODO: add draw code for native data hereCRect rect;
GetClientRect(rect);
pDC->Rectangle(rect);
pDC->Ellipse(rect);
}
效果图 

 
 



0 0
原创粉丝点击