Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

STM_SETIMAGE doesn't invalidate/repaint the static control

Tags:

c++

winapi

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?

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);

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.


Update

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

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

like image 867
sashoalm Avatar asked Jun 07 '26 04:06

sashoalm


1 Answers

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);
like image 165
sashoalm Avatar answered Jun 08 '26 17:06

sashoalm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!