Computing.Net > Forums > Programming > Window redraw...I think not!

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Window redraw...I think not!

Reply to Message Icon

Original Message
Name: livingdecay
Date: November 15, 2004 at 09:36:38 Pacific
Subject: Window redraw...I think not!
OS: Windows XP Professional
CPU/Ram: AMD Athlon XP 1800+/512Mb
Comment:

Hi.
I am trying to create a windows game in C++ which involves drawing lines on the window. The problem I have is that everytime the Window goes behind another window, it redraws itself, erasing the lines. Is there anyway to tell the window not to do this? I have thought of just redrawing the lines that need to be there on WM_ACTIVATE, but this is complicated with my code as it is now, and will probably require a major change in my code, which is otherwise working (mostly).
Please help!

Athlon XP 1800+
512Mb DDR266 RAM
Leadtek Geforce 6800
Thermaltake 360W PSU
56X CD-ROM
52x24x52 Samsung CD-RW
20 GB Maxtor HDD
80 GB Hitachi HDD
Gigabyte GA-7DX+ mobo


Report Offensive Message For Removal


Response Number 1
Name: Stephen Hall
Date: November 15, 2004 at 13:18:07 Pacific
Reply: (edit)

livingdecay,

Well, I'm not boasting myself as a great windows programmer, but I'll just add my $0.02 and you can do with it what you want.
First, Windows does not _seem_ to keep a copy of what is actually on the screen except for in video memory. This means that when your window is obscured, "poof" -- there goes your graphics into computer oblivion. You cannot rely on Windows to remember what you have displayed on the screen. Windows only erases the screen and then sends commands to redraw items. It does not restore overlayed windows internally.
Second, there are a few different ways to overcome this. One way I prefer from being an old-time DOS game programmer is to use an off-screen buffer. This isn't always the best way to do things in Windows, but it does _work_, as opposed to other methodologies. Basically, the idea is to make a representation of your screen in memory first, then copy that to the screen through GDI or something like that. It's been a while since I've played around with this, and if I remember right GDI is too slow to redraw the stored screen pixel by pixel, but like I said, I can't remember.
Another way (and probably the better) is to wait for any WM_PAINT messages sent you main window proc's way. These are the same messages the rest of the window is responding to and rebuilding itself from (i.e. the caption bar, the border, etc.). Simply waiting on a WM_ACTIVATE message will only redraw the window when it is selected, not when another window is moved to unobscure yours.
Since you said that might be a pain to do, think about doing this. Place all your drawing code into WM_PAINT and then send a WM_PAINT message to your window whenever you need the screen drawn. It all kind of depends on how your graphics loop is set up, or if you're using a loop at all.

Regardless of how you've got it set up, there's no way to get around the fact that other windows are going to erase your graphics and you're going to have to rebuild them. Static graphics are a no-do on Windows, since your graphics aren't kept when another widnow obscures yours.

Hope this helps, I'm sure it's clear as mud, but hey, it's worth a shot.

Best wishes,


Stephen

"Live long and program......or at least do _something_ with all that time......"


Report Offensive Follow Up For Removal

Response Number 2
Name: livingdecay
Date: November 16, 2004 at 09:29:16 Pacific
Reply: (edit)

That's actually not a bad idea, the WM_PAINT thing, I'll give it a shot when I have the chance.
Thanks!
(If anyone else reads this, I'm still open for suggestions in case this doesn't work)

Athlon XP 1800+
512Mb DDR266 RAM
Leadtek Geforce 6800
Thermaltake 360W PSU
56X CD-ROM
52x24x52 Samsung CD-RW
20 GB Maxtor HDD
80 GB Hitachi HDD
Gigabyte GA-7DX+ mobo


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software