Archived

This topic is now archived and is closed to further replies.

MaximusDM_PT

Refreshing a window

Recommended Posts

I''m using windows GDI for text printing, using the function TextOut, but when the window gets inactive and becomes active again, it recieves the Paint message, but since I''m using BeginPaint using the background color the text it was there gets lost, I thought of keeping the pixels info of the window in a 2 dimension array with GetPixel, and then when the window becomes active again I tried to restore that info with SetPixel, but nothing hapened, I''ve made some tests and realised that when I try to increase a variable in the function "Keep"(the one that''s called when the window looses focus) it''s like the function gets called several times, but folowing the code it should only be called when the window looses focus, then when it gains, again another function is called "Restore", I would apretiate help in these two cases, that is a simple way of refreshing the window and an explanation on why my approach isn''t working. If that requires the code since I feel I didn''t explain that well, just ask the code or send me a mail at mangas_pt@sapo.pt. Thanks!

Share this post


Link to post
Share on other sites
I think i understood that. I dont know specificly why your approach isnt working it could be that the Keep function is called after the window is erazed (so your array is filled with white)
also, this is a very slow way of doing it. The way i deal with it is to have a backbuffer.(See CreateCompatibleBitmap, CreateCompatibleDC, SelectObject)
When i want to draw to the screen i draw to the back buffer. When im finished i blit it to the window (see BitBlt, GetDC, ReleaseDC).

However i do not delete the backbuffer or the DC assosiated with it. When my app recives the WM_PAINT i just blit again.

[edited by - empirical on March 18, 2004 9:02:42 AM]

Share this post


Link to post
Share on other sites
Maximus ... not sure I''m understanding the question, but here''s an overview that might help.

Ideally, you do ALL your drawing (in a conventional windows prog) in response to WM_PAINT (including any text printing). Windows will send the WM_PAINT msg any time your window needs updating (like after another window has obscured it, or when it''s being displayed after minimization, etc). You can force Windows to send a paint msg by calling InvalidateRect(..). If you do any drawing to the screen outside of WM_PAINT, it will get lost the next time windows (or your program) sends a paint msg.

When a paint msg is sent, you also have the oppportunity to deal with the background by responding to the WM_ERASEBKGND msg which always accompanies WM_PAINT.

Share this post


Link to post
Share on other sites