3

I am currently drawing graphics with GDI but I need to be able to redraw the entire desktop/screen. My graphics are drawn on the screen but when I would move a plotted pixel it would become a line because I am not redrawing the screen ( well windows isn't ). I need something to force it to redraw the entire screen, I've tried the following approaches:

UpdateWindow(GetDesktopWindow() );

InvalidateRect( GetDesktopWindow(), NULL, TRUE );

SendMessage( GetDesktopWindow(), WM_PAINT, NULL, NULL );

None of them seem to work, I just need the entire screen to redraw.

Yonathan
  • 1,253
  • 1
  • 17
  • 29
  • Why are you doing all of those things to the desktop window instead of your own window? The desktop window is the thing that displays your wallpaper and every other window appears on top of it... – Cogwheel Jul 12 '10 at 20:43
  • Because I don't have my own window and I know what it does. I am drawing on the desktop itself using the desktop's handle. – Yonathan Jul 12 '10 at 20:48
  • 1
    Why don't create a full screen transparent window? – onof Jul 12 '10 at 20:51
  • I will look at it but I wanted it to be without a form/window. – Yonathan Jul 12 '10 at 20:57
  • Please tell me what application you're working on so I can avoid it in the future. Drawing on a window you don't own is just asking for trouble. – Mark Ransom Jul 12 '10 at 21:44

3 Answers3

2

If you still want to force entire desktop to be repainted, you may use

RECT rect;
::GetClientRect(::GetDesktopWindow(), &rect);
::RedrawWindow(::GetDesktopWindow(), &rect, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN);
sergiol
  • 4,122
  • 4
  • 47
  • 81
rusxg
  • 98
  • 6
  • Not even with `RDW_ERASENOW` instead of `RDW_ERASE` and `NULL` instead of `::GetDesktopWindow()` it is working! – sergiol Oct 10 '17 at 14:50
1

You can use RedrawWindow with hWnd set to NULL.

Survarium
  • 190
  • 2
  • 6
1

The best way might be to save the previous pixel state/color and restore it when you move the pixel. Redrawing the whole screen seems like too much effort and an aweful waste of resources.

Jay
  • 288
  • 3
  • 13
  • 1
    I agree with Jay... With full refresh your screen would flicker crazily! – bits Jul 12 '10 at 20:46
  • Saving every pixels position the whole time and the change would most likely make everything incredibly slow don't you think? There must be some way to force windows to redraw only a section which can be the previous position for all I care. – Yonathan Jul 12 '10 at 20:49