在子类 CStatic 控件中处理 WM_PAINT
我创建了一个自定义控件,其类以 CStatic 作为基类。目前我使用 WM_PAINT 事件处理绘图。但有一个奇怪的行为。当我使用 CWnd::EnableWindow 函数禁用窗口后重新启用窗口时,它拒绝绘制我在 OnPaint 函数中编写的内容。它改为绘制静态控件。
我同意有一个覆盖 DrawItem
并使用 SS_OWNERDRAW
样式的标准方法。但是 WM_PAINT
有什么问题吗?
void XXControl::OnPaint()
{
CPaintDC PaintDC( this );
// ** draw the control to PaintDC**
}
I created a custom control whose class has CStatic
as base class. Currently I handle the drawing using WM_PAINT
event. But there is a strange behavior. When I re-enable the window after disabling it using CWnd::EnableWindow
function, it refuses to draw what I written in OnPaint
function. It draws the static control instead.
I agree that there is this standard method of overriding DrawItem
and using SS_OWNERDRAW
style. But what's wrong with WM_PAINT
?
void XXControl::OnPaint()
{
CPaintDC PaintDC( this );
// ** draw the control to PaintDC**
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这正是我所写的:
子类化:
其中
IDC_DRAW
是对该对话框的资源的静态控制。我编写了两个按钮处理程序:并且它工作完美!删除
Invalidate
调用,它将失败。Here is exactly what I have written:
And subclassed:
Where
IDC_DRAW
is static control on resource for this dialog. I wrote two button handlers:And it works flawlessly! Remove
Invalidate
call and it would fail.尝试关闭 Aero。我遇到了一个类似的问题,我正在绘制静态控件,当它从禁用变为启用时,永远不会收到 WM_PAINT 消息,但如果我关闭 Aero,它工作正常。
Try turning off Aero. I'm having a similiar problem where I'm drawing a static control and when it goes from disabled to enabled the WM_PAINT message is never received, but if I turn Aero off it works fine.