Jump to content
  • Advertisement
Sign in to follow this  
OrcishCoder

InvalidateRect() question.

This topic is 4842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Normally if I write GDI games, I will use such technique to update the sprite: void MoveSprite(HDC hDc, HDC hDcSprite, int x, int y) { BitBlt(hDc, x, y, 32, 32, hDcSprite, 0, 0, SRCCOPY); InvalidateRect(hWnd, NULL, false); UpdateWindow(hWnd); <------------------- } Normally I read lot of tutorials, they used "InvalidateRect()" only. Because I want it get updated immediately, so I add "UpdateWindow()". Will it produce any hidden problem?? Sorry if my question is too noob, because recently my GDI game when running on WinXP system, it is fine, and when running Win9x/Me, it black out. Sometime it will appear back the image, but just a while, it black out again. I dont know why, now I suspect I did some bad programming habbit which cause this bug. Can anyone tell me I put "UpdateWindow" after InvalidateRect is good or bad? and, any suggestion to my bug? Thanks in advance regards, Martin

Share this post


Link to post
Share on other sites
Advertisement
InvalidateRect() puts a WM_PAINT in the message queue. UpdateWindow() will put a WM_PAINT in the message queue if there are any dirty rectangles (which there is). If there are multiple WM_PAINTs in the message queue they are automatically combined into one.

So UpdateWindow() in effect doesnt do anything in this case [smile]

As for your bug, check to see if the GDI functions are failing or and that you are properly cleaning up your GDI resources.

Share this post


Link to post
Share on other sites
Quote:
Original post by Colin Jeanne
InvalidateRect() puts a WM_PAINT in the message queue. UpdateWindow() will put a WM_PAINT in the message queue if there are any dirty rectangles (which there is). If there are multiple WM_PAINTs in the message queue they are automatically combined into one.

So UpdateWindow() in effect doesnt do anything in this case [smile]

As for your bug, check to see if the GDI functions are failing or and that you are properly cleaning up your GDI resources.
Off Topic: First time I've seen you post here :)
On Topic: Are you using GDI's TransparentBlt function? (As it has memory leaks on pre win2k, causing wierd things)

Share this post


Link to post
Share on other sites
I am using normal BitBlt only. And the weird thing only happen on win9x/me system.
I dont know why my program will behave like that. If it is not GDI function problem,I think it is because some array overrun, make weird thing happen.
Is there any good memory checker for visual c/c++? and one more thing, how to create a window which cannot resize?

thanks in advance

regards,
Martin

Share this post


Link to post
Share on other sites
OK, when selecting bitmaps into HDCs, are you storing the 'old' bitmap and selecteing it back into the HDC later?

Share this post


Link to post
Share on other sites
corsix,

i create global hdcs, and select bitmap to them once time.
then, during my program run time, i nv delete dc or delete bitmap object.
so i dont think that will be a problem.
or mayb i miss out something?


regards,
Martin

Share this post


Link to post
Share on other sites
So, are you doing eg.:
A:
HDC hDC;
HBITMAP hBitmap, hDC_OldBitmap;
hDC_OldBitmap = SelectObject(hDC, hBitmap);
/* ... */
SelectObject(hDC, hDC_OldBitmap);
DeleteObject(hBitmap);
DeleteDC(hDC);
or
B:
HDC hDC;
HBITMAP hBitmap;
SelectObject(hDC, hBitmap);
/* ... */
DeleteObject(hBitmap);
DeleteDC(hDC);

Share this post


Link to post
Share on other sites
Quote:
Original post by Colin Jeanne
InvalidateRect() puts a WM_PAINT in the message queue. UpdateWindow() will put a WM_PAINT in the message queue if there are any dirty rectangles (which there is). If there are multiple WM_PAINTs in the message queue they are automatically combined into one.

So UpdateWindow() in effect doesnt do anything in this case [smile]

I'm fairly sure that UpdateWindow causes the window to updated syncronously rather than just dumping a WM_PAINT into the queue. i.e. it basically does SendMessage(WM_PAINT) instead of PostMessage(WM_PAINT). It wouldn't make any sense for the api to even exist otherwise becacuase as you say anthing that invalidates a portion of the window put a WM_PAINT in the queue anyway.

Quote:
Original post by OrcishCoder
and one more thing, how to create a window which cannot resize?

Generally speaking it's better to not lock windows into a single size as it hurts usability for people with very big (or very small) monitors. But if you must you just turn off the WS_SIZEBOX bit in the dwstyle parameter of your CreateWindow call. You're probably using WS_OVERLAPPEDWINDOW. You can change it to (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX).

Share this post


Link to post
Share on other sites
Quote:
Original post by Anon Mike
I'm fairly sure that UpdateWindow causes the window to updated syncronously rather than just dumping a WM_PAINT into the queue. i.e. it basically does SendMessage(WM_PAINT) instead of PostMessage(WM_PAINT). It wouldn't make any sense for the api to even exist otherwise becacuase as you say anthing that invalidates a portion of the window put a WM_PAINT in the queue anyway.

I checked the MSDN and you are right, it posts WM_PAINT directly to the window procedure and bypasses the message queue.

Sorry about that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!