Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to refresh the screen after drawing?

0 views
Skip to first unread message

Kingherc

unread,
Mar 28, 2005, 4:05:02 PM3/28/05
to
Here's the thing: I draw a temporary rectangle on the screen (with the dc of
the screen) successfully and then I want to refresh it so that it goes away
and the portion of the screen goes back to normal. One solution I found was
using RedrawWindow with the window, rectangle, region nulls and with the flag
RDW_ERASE. But nothing happens and no error. Then I thought about redrawing
the window, but I did get the dc of the screen and not of a window, so I do
not have a handle. Then I thought about saving a temporary bitmap before
drawing and when done, redraw the bitmap again. But that actually does not
refresh the screen and there maybe something wrong if the screen's changing
too quickly.
Any ideas/help?

Severian

unread,
Mar 28, 2005, 4:30:50 PM3/28/05
to

For an outline rectangle, create a colored pen and SetROP2(hdc,
R2_XORPEN); Redrawing the rectangle will then erase it.

For a filled rectangle, the easiest way to make it visible is to
invert it, then invert again when done.

However, other applications can interfere with either method.

Why do you need to paint to the screen DC?

--
Sev

Kingherc

unread,
Mar 29, 2005, 6:03:03 AM3/29/05
to
Well, thanks, I'll try this asap.
I need to draw on the screen dc, so that I can show a user a designated
rectangle area of the screen (not of a particular window). But as I just want
to show it, I also want to erase the painting after some short time.

Kingherc

unread,
Mar 29, 2005, 10:11:06 AM3/29/05
to
Again, there's a problem. The solution you told me works nice in some
situations, but fails in others: That is, when a window has refreshed between
the interval until I redraw the rectangle, it may have refreshed a part of
the rectangle (or even the whole). So, when I redraw the rectangle, it draws
the same rectangle (or part of it that was refreshed) rather than delete it.
Maybe suggest using another option rather than R2_XORPEN?...
And another question: If I use the RedrawWindow for the screen, is there any
possibility that it won't be redrawn (because it doesn't)?
Any other suggestion please?

Severian

unread,
Mar 29, 2005, 3:00:01 PM3/29/05
to
On Tue, 29 Mar 2005 07:11:06 -0800, "Kingherc"
<King...@discussions.microsoft.com> wrote:

>Again, there's a problem. The solution you told me works nice in some
>situations, but fails in others: That is, when a window has refreshed between
>the interval until I redraw the rectangle, it may have refreshed a part of
>the rectangle (or even the whole). So, when I redraw the rectangle, it draws
>the same rectangle (or part of it that was refreshed) rather than delete it.
>Maybe suggest using another option rather than R2_XORPEN?...
>And another question: If I use the RedrawWindow for the screen, is there any
>possibility that it won't be redrawn (because it doesn't)?
>Any other suggestion please?

I don't know exactly what you're trying to do; but if you want to
capture a part of the desktop to an image, you could capture the
entire desktop at the beginning (mouse button down), display it in a
full-screen window (so that the image is static), then destroy the
window and crop the image when the mouse button is released.

The full-screen capture can take a significant amount of time, so you
may want to display an hourglass between at button down and your
selection cursor once your full-screen copy has painted.

Also, to repaint the entire screen, you can:

InvalidateRect(HWND_DESKTOP, NULL, 0);


--
Sev

Kingherc

unread,
Mar 30, 2005, 1:17:03 AM3/30/05
to
Yes, that's what I'm trying to do. I'll try this. Thanks for your tips. They
are very helpful!

Murugan Andezuthu Dharmaratnam

unread,
Apr 15, 2005, 2:20:02 AM4/15/05
to
Hi Kingherc,
If U would like to refresh the screen preodically U can use a thread to
do that . Here is a small snippet


void DisplayRefresh(void *n)
{
RECT x;
x.top = 0;
x.left = 0;
x.bottom = 480;
x.right = 640;
while(true)
{
InvalidateRect(hWind,&x,false);
Sleep(150);
}
}

Create the thread in function that Processes messages for the main window.

case WM_CREATE:
hWind = hWnd; // HDC hWind; I declared it as a global
variable
_beginthread(DisplayRefresh,0,NULL);
break;

Hope this helps.

Thanks!
Murugan Andezuthu Dharmaratnam
www.muruganad.net

"Nothing is impossible its just improbable"


"Kingherc" <King...@discussions.microsoft.com> wrote in message
news:A2EF7659-1585-4DCE...@microsoft.com...

0 new messages