windows 强制窗口重绘整个屏幕
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3232094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Forcing windows to redraw the entire screen
提问by Yonathan
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:
我目前正在使用 GDI 绘制图形,但我需要能够重绘整个桌面/屏幕。我的图形是在屏幕上绘制的,但是当我移动一个绘制的像素时,它会变成一条线,因为我没有重新绘制屏幕(窗口不是)。我需要一些东西来强制它重绘整个屏幕,我尝试了以下方法:
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.
它们似乎都不起作用,我只需要重绘整个屏幕。
回答by rusxg
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);
回答by Jay
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.
最好的方法可能是保存以前的像素状态/颜色并在移动像素时恢复它。重绘整个屏幕似乎太费力,而且是对资源的极大浪费。
回答by Survarium
You can use RedrawWindowwith hWnd set to NULL.
您可以在 hWnd 设置为 NULL 的情况下使用RedrawWindow。