注册 登录
编程论坛 VC++/MFC

关于键盘操作的InvalidateRect函数

聪儿 发布于 2012-09-06 17:30, 519 次点击
需要实现的是,单击左键,出现一矩形
代码如下:
void CMfcpen_1View::OnLButtonDown(UINT nFlags, CPoint point)
{    CClientDC dc(this);
    CRect rc;
    GetClientRect(&rc);
    dc.MoveTo((rc.left+rc.right)/2,0);
    dc.LineTo(rc.right,(rc.top+rc.bottom)/2);
    dc.LineTo((rc.left+rc.right)/2,rc.bottom);
    dc.LineTo(rc.left,(rc.top+rc.bottom)/2);
    dc.LineTo((rc.left+rc.right)/2,0);
    //InvalidateRect(NULL);  通知更新之后反而不更新了??好奇怪。

    // TODO: Add your message handler code here and/or call default
   
    CView::OnLButtonDown(nFlags, point);
}


并且我查到 这个函数的作用如下:
Invalidates the client area within the given rectangle by adding that rectangle to the CWnd update region.
应该是用户区有改变时候通知用户矩形区更新的,所以就更不明白上述问题了。

请大家指点一二,多谢!
1 回复
#2
聪儿2012-09-17 14:40
通过几天的学习明白了这个原理。
这个是由于通知更新显示的是 ondraw中的东西,而我的该函数没有相关输出。
1