Jump to content


WM_PAINT and InvalidateRect()

c++ gui

  • You cannot reply to this topic
No replies to this topic

#1 Hyper

    Valued Member

  • Members
  • PipPipPip
  • 195 posts

Posted 10 April 2012 - 09:18 AM

Hello.

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

Posted Image

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";
		OutputDebugString(ss.str().c_str());
	}
}

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.

Edited by Hyper, 10 April 2012 - 09:34 AM.

“You may be disappointed if you fail, but you are doomed if you don't try.”
Beverly Sills





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users