WM_PAINT and InvalidateRect()

Hyper 96 Apr 10, 2012 at 09:18 gui c++


Is there anything or reason that would cause Windows to not update a specified region via InvalidateRect() (which sends a WM_PAINT message)?
It is very peculiar, and it has been making me wonder. At times, it almost seems inconsistent, almost even as if it’s not sending the WM_PAINT message at all.

Here is an image which demonstrates what I am referring to; The blue rectangle doesn’t exist (the window simply has not been updated for some reason):

~~The code for this is pretty straight-forward, as you’d expect. I have even checked the return value, and it is non-zero (success).~~

void IMAGE::update(HWND& hwnd, int frame) {
    RECT repaint = area;

    repaint.top -= frame;
    repaint.left   -= frame;
    repaint.right  += frame;
    repaint.bottom += frame;

    if (InvalidateRect(hwnd, &repaint, TRUE) == 0) {
        std::stringstream ss;
        ss << "ERROR: InvalidateRect() returned 0\n";

The first question I’m assuming I’ll be asked is: Are you drawing the rectangles after having had called InvalidateRect()?
To that I answer: No. I am drawing the rectangles, then updating the specific areas.

The second question I’m assuming I’ll be asked is:Are you updating the region that includes the rectangle?
To that I answer: Yes! I am updating the actual rectangle (square) + 2 pixels (to cover the rectangle).

The third question I’m assuming I’ll be asked is: When is it occurring?
To that I answer: During the first selection. There are \~100 images like those above (from a video game).

The fact that it works after the initial selection is what makes me wonder the most!
What or where could this possibly be occurring at (in the code, if at all), and why?

~~Thank you, as usual, for your time and consideration in reading/replying to this.~~

EDIT: I found the culprit! It was a crafty comment… Haha.
I think this is a tall tale sign that I need to get to bed.

0 Replies

Please log in or register to post a reply.

No replies have been made yet.