STM_SETIMAGE 不会使静态控件失效/重新绘制 [英] STM_SETIMAGE doesn't invalidate/repaint the static control

查看:42
本文介绍了STM_SETIMAGE 不会使静态控件失效/重新绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我在使用 STM_SETIMAGE 消息更改位图后静态控件不使其区域无效是否正常?

Can anyone tell me if it's normal or not for a static control not to invalidate its area after the bitmap has been changed with the STM_SETIMAGE message?

我使用了SS_BITMAP样式的静态控件,我用下面的代码设置了它的图片

I use a static control with the SS_BITMAP style, and I set its picture with the following code

    HBITMAP DestBmp;
    // Paint on DestBmp...

    HBITMAP hOldBmp = (HBITMAP) ::SendMessage(hStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) DestBmp);
    if (hOldBmp)
        DeleteObject(hOldBmp);

    // *** Why do I need this? ***
    ::InvalidateRect(hStatic, NULL, FALSE);

如果我不调用 InvalidateRect,静态控件不会重新绘制自身.这是 STM_SETIMAGE 的正常行为,还是我做错了什么?文档 在 MSDN 没有提到需要在 STM_SETIMAGE 之后调用 InvalidateRect 的任何内容,无论如何,这很奇怪,例如,您不需要在 SetWindowText 之后调用 InvalidateRect.这让我觉得我的代码可能有问题.

If I don't call InvalidateRect, the static control doesn't repaint itself. Is this the normal behaviour of STM_SETIMAGE, or am I doing something wrong? The documentation at MSDN doesn't mention anything about needing to call InvalidateRect after STM_SETIMAGE, and its strange anyway, you don't need to call InvalidateRect after SetWindowText for example. This makes me think something might be wrong with my code.

更新

这是在我的 .rc 文件中定义控件的方式

This is how the control is defined in my .rc file

CONTROL         "",IDC_IMAGE_PREVIEW,"Static",SS_BITMAP | NOT WS_VISIBLE,29,293,15,13

NOT WS_VISIBLE 标志不是问题,我稍后使用 ShowWindow(SW_SHOW); 使控件可见.

The NOT WS_VISIBLE flag is not a problem, I make the control visible with ShowWindow(SW_SHOW); later.

推荐答案

由于还没有真正的解释,而且问题是获得意见,我将在这里添加我的解决方法.调用 InvalidateRect() 强制控件重新绘制.

Since there is no real explanation yet, and the question is getting views, I'll add my workaround here. Call InvalidateRect() to force the control to repaint.

HBITMAP hOldBmp = (HBITMAP) ::SendMessage(hStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) DestBmp);
.....
::InvalidateRect(hStatic, NULL, FALSE);

这篇关于STM_SETIMAGE 不会使静态控件失效/重新绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆