When exactly is OnDraw called as a result of InvalidateRect()
I have the follwoing situation:
OnDraw(CDC * pDC)
{
pDC->DrawRect(m_rectA);
}
later in another function.
void RemoveRect()
{
// remove the rect without paint the whole screen
InvalidateRect(m_rectA)
// remove the rect to be drawn
m_rectA.top = m_rectA.bottom = m_rectA.left = m_rectA.bottom = 0;
}
My quesetion: Is the above code correct to just remove the rect? I mean I have called InvalidateRect() at which point OnDraw still have the same rect, so it will not change? but if the OnDraw function is actually called after this function is done (as a result of InvalidateRect()), it should clear the rect correctly? Is the later case fair to assume?
[710 byte] By [
retry] at [2007-11-19 7:29:44]

# 1 Re: When exactly is OnDraw called as a result of InvalidateRect()
No, it's correct, because InvalidateRect does not actually redraw the window. It tells windows that the rect is invalidate, so windows post a WM_PAINT-Msg in the message-queue. But this message is processed when your application gets into the main message-loop the next time which could not be before the end or your function.
martho at 2007-11-11 0:27:17 >

# 2 Re: When exactly is OnDraw called as a result of InvalidateRect()
Besides what martho said, why didn't you remove the rect before calling Invalidate if you were worried about the moment the drawing is done?
This would be fuitless anyways since the rect has been nullified now calling InvalidateRect() on m_rectA has nomeaning!
If I have to go that way, It should be something like this:
void RemoveRect()
{
// remove the rect to be drawn
CRect rectTemp = m_rectA;
m_rectA.top = m_rectA.bottom = m_rectA.left = m_rectA.bottom = 0;
// remove the rect without paint the whole screen
InvalidateRect(m_rectTemp)
}
I thought it shoulld be uncessary if the OnDraw is called after this function is done which is the case and so first approach is the correct one.
retry at 2007-11-11 0:28:17 >

# 3 Re: When exactly is OnDraw called as a result of InvalidateRect()
void RemoveRect()
{
// remove the rect to be drawn
m_rectA.top = m_rectA.bottom = m_rectA.left = m_rectA.bottom = 0;
// remove the rect without paint the whole screen
InvalidateRect(m_rectA)
}
Cilu... shouldn't you better rethink that code...? ;)
# 4 Re: When exactly is OnDraw called as a result of InvalidateRect()
I thought it shoulld be uncessary if the OnDraw is called after this function is done which is the case and so first approach is the correct one.You are right. OnDraw() will only be called when your main message loop gets the next occasion to process WM_PAINT messages. And this will not happen while your RemoveRect() function is still executed (if this doesn't happen from a different thread, which I hope is not the case).
# 5 Re: When exactly is OnDraw called as a result of InvalidateRect()
Cilu... shouldn't you better rethink that code... slowly...? ;)
:D I think I do. :cry:
Disregard it please. Erare human est!
cilu at 2007-11-11 0:31:26 >
