How to save a device context ?

Started by
3 comments, last by Don GL 17 years, 2 months ago
Hello, I have some window in c++ with a 'frame' item placed in it. I am drawing stuff using SetPixel (hDC,x,y,COLORREF) I retrieve the DC with GetDC(getDlgItem(wnd,frame)) The drawing goes well, but whenever the window loses focus, or something get on top of the window, the drawing disappear. To be more specific, I have a proces going on, and during that I want to draw a graph of the process. so; while (process) x++; calc(y) SetPixel(x,y) I've tried the functions SaveDC and RestoreDC ( I saved after the process, and restored on messages ). RestoreDC always returned 0. I wonder, will this work at all? How could I make sure that what I draw with SetPixel(..) also stays drawns after it has been 'out of sight'?? Like a button or whatever also simply stays drawn, after minimalizing the window or whatever. Thanx in advance
Advertisement
In my opinion, it would be best to draw the stuff again, what you want to draw!?

You could try just to place a UpdateWindow() call in the programms WM_PAINT message...

UpdateWindow calls the frame you want to draw. And within the frame(window), there is another WM_PAINT message where the stuff is drawn.

This is how I would do it..

Hopefully this was usefull to you.

Greeting
Alex
Quote:Original post by Don GL
Like a button or whatever also simply stays drawn, after minimalizing the window or whatever.

The button doesn't stay drawn. It draws itself again, as a result of the WM_PAINT message. Since it remembers its width, height, caption, etc., it can draw itself as many times as it wants, and be drawn the same each time. Learn from its example.
I'd recommend using a bitmap section. That would allow you to save it, be good coding style, and probably be way faster than what you're doing.
Thanx, I'll go with a bitmap and a redraw then

This topic is closed to new replies.

Advertisement