解决方案 »
- 请问高手,有么有实时管道???
- 如何利用vc模拟一个物体的移动
- 如何给工程添加类库?
- 用Win32 SDK实现透明按钮(急)
- 如何检测一个虚拟光驱中的文件是否存在,使用FindFirstFile失败.
- 有用过 Nero Burnning Rom 的吗?请进
- 如何让Cdialog上的工具条适时变为“可用”、“不可用”?
- 请问:如果已知对方的口令和密码,如何能访问该机器的各驱动器?
- 怎样调整对比度
- 我想在Win2000下开发程序,任何用户安装后,其他用户也能看到并正常使用,具体见内容!!
- ActiveX :自己编辑了一个编辑框控件,加载到网页里,网页大小变化时,控件部分会有残影,鼠标放上去才会显示正常
- 在MainFrm.cpp中用这个函数((CMFCMyOCTApp*)AfxGetApp())->m_StrFileName = strDBpath
“还有,我尝试在DefWindowProc中用BeginPaint返回的DC中画图,然后直接return,则没有显示,不清楚原因。为什么OnPaint中和DefWindowProc中同样的代码,表现不同?”发现重载WindowProc而不是DefWindowProc以后,用BeginPaint返回的DC是可以画出来的,而且它对InvalidateRect的响应也正确。其他部分不会重绘。
The BeginPaint function automatically sets the clipping region of the device context to exclude any area outside the update region. The update region is set by the InvalidateRect or InvalidateRgn function and by the system after sizing, moving, creating, scrolling, or any other operation that affects the client area. If the update region is ed for erasing, BeginPaint sends a WM_ERASEBKGND message to the window. An application should not call BeginPaint except in response to a WM_PAINT message. Each call to BeginPaint must have a corresponding call to the EndPaint function. If the caret is in the area to be painted, BeginPaint automatically hides the caret to prevent it from being erased. If the window's class has a background brush, BeginPaint uses that brush to erase the background of the update region before returning.
而Beginpaint获取的HDC 正是经过这种处理后的HDC
你GetDC获取的 自然是没有处理过的
另外在dialog函数中写这种代码 直接CPaintDC dc(this)就可以了
只有在WNDPROC里才需要 begin end
如果 窗口 有 无效区, 必须 使用 paintDC。你 可以 叫 窗口 有效, ValidateRect (这个函数不常用,Beginpaint 后 窗口 就有效了 )
BeginPaint, EndPaint, WM_PAINT, OnPaint, CPaintDC, Invalidate, InvalidateRect和无效区域,是相关的。
GetDC, ReleaseDC和上面的所有都完全没关系。可以直接在通过GetDC获得的DC进行绘图,但有个小难点在于需要自己维护背景,如果后画的东西没有完全覆盖之前画的部分,则未覆盖的部分会露出来,所以用这种方式绘图,需要在程序中调用所有要更新的区域的绘图操作,可能是多层的背景前景绘图。另外,关于闪烁,只要在一块区域中绘制多次,就会有闪烁,
如果用WM_PAINT的响应绘制,则如果能够绘制全部更新区域,且不透明,则可以重载WM_ERASEBKGROUND,然后return true;来禁用系统画背景色,或者在Invalidate/InvalidateRect中第二个参数用false也是一样的。
如果用GetDC来绘制,也是需要能够绘制全部更新区域,且不透明。无论哪种,只要保证在一块区域中只绘制一次就没问题。