void CMyDialog::OnPaint()
{
CWnd *pWnd=GetDlgItem(IDC_STATIC1);
CDC *pControlDC=GetDC(pWnd);
pWnd->Invalidate();
pWnd->UpdateWindow();
pControlDC->SelectStockObject(BLACK_BRUSH);
pControlDC->Rectangle(0,0,10,10);
pWnd->ReleaseDC(pControlDC);
}
说明:
既要在控件窗口内绘图,又要防止windows
对它进行重复绘制。可利用Invalidate/UpdateWindow调用来实现。
问:对于Invalidate函数
Windows sends a WM_PAINT message whenever the CWnd update region is not empty
and there are no other messages in the application queue for that window.
而UpdateWindow函数
The UpdateWindow member function sends a WM_PAINT message directly, bypassing
the application queue.
是不是总共发送了两个WM_PAINT,还有是不是Invalidate/UpdateWindow调用后,当调用
pControlDC->SelectStockObject(BLACK_BRUSH);
pControlDC->Rectangle(0,0,10,10);
pWnd->ReleaseDC(pControlDC);IDC_STATIC1控件窗口虽然发生变化,也不发送WM_PAINT
。
{
CWnd *pWnd=GetDlgItem(IDC_STATIC1);
CDC *pControlDC=GetDC(pWnd);
pWnd->Invalidate();
pWnd->UpdateWindow();
pControlDC->SelectStockObject(BLACK_BRUSH);
pControlDC->Rectangle(0,0,10,10);
pWnd->ReleaseDC(pControlDC);
}
说明:
既要在控件窗口内绘图,又要防止windows
对它进行重复绘制。可利用Invalidate/UpdateWindow调用来实现。
问:对于Invalidate函数
Windows sends a WM_PAINT message whenever the CWnd update region is not empty
and there are no other messages in the application queue for that window.
而UpdateWindow函数
The UpdateWindow member function sends a WM_PAINT message directly, bypassing
the application queue.
是不是总共发送了两个WM_PAINT,还有是不是Invalidate/UpdateWindow调用后,当调用
pControlDC->SelectStockObject(BLACK_BRUSH);
pControlDC->Rectangle(0,0,10,10);
pWnd->ReleaseDC(pControlDC);IDC_STATIC1控件窗口虽然发生变化,也不发送WM_PAINT
。
解决方案 »
- 点击软件界面没有反应
- 我想通过一个按钮单击事件使对话框窗口来变成最大化!
- 求多线程FTP/HTTP下载源代码,哪有呀
- 为什么只能将字符串中的第一个字符放到CString中?关键字:CString, _UNICODE
- 很怪的现象!急!求救!
- 救命啊,哪位有项目总结报告的模板指点小弟一下
- 我用DELPHI写了一个DLL,但是我在VC中怎样调用DLL里的函数呢???(参数怎么解决呢)
- WIN2000下如何知道当前登陆的用户的用户名?
- 上海某软件公司诚招VC/C++软件开发人员
- 有没有人想知道倒计时关机的源码??
- 50分求助一个菜鸟问题。
- (*)(*) 各位同道请帮忙解决有关数据库程序的问题,谢谢!(内详)
原来的sdk编程,createwindow后updatewindow窗口才显示出来
2、UpdateWindow/RedrawWindow负责发送WM_PAINT消息。UpdateWindow在无效矩形为空时不发送WM_PAINT消息。
3、在窗口内绘图只需获得其窗口的设备环境(DC),通过它来向窗口客户区绘图。from msdn:
The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function. CWnd::Invalidate
Invalidates the entire client area of CWnd.UpdateWindow
The UpdateWindow function updates the client area of the specified window by sending a WM_PAINT message to the window if the window's update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent。因此,
CWnd *pWnd=GetDlgItem(IDC_STATIC1);
CDC *pControlDC=GetDC(pWnd);
pWnd->Invalidate(); // 标记控件窗口无效矩形
pWnd->UpdateWindow(); // 发送WM_PAINT消息
pControlDC->SelectStockObject(BLACK_BRUSH);
pControlDC->Rectangle(0,0,10,10);
pWnd->ReleaseDC(pControlDC);
RedrawWindow
= Invalidate +
UpdateWindow
的调用。而UpdateWindow才是发出WM_PAINT的函数
既要在控件窗口内绘图,又要防止windows
对它进行重复绘制。可利用Invalidate/UpdateWindow调用来实现。
谢谢!下面这句话我不太了解,还有他们在上面的程序的作用?
既要在控件窗口内绘图,又要防止windows
对它进行重复绘制。可利用Invalidate/UpdateWindow调用来实现。