RECT rect;
HWND hwnd = GetDesktopWindow();
LockWindowUpdate(hwnd);
HDC hdc = GetDC(hwnd);
HBRUSH hbrush = CreateSolidBrush(RGB(255,0,0));
GetWindowRect(hwnd, &rect);
FillRect(hdc, &rect, hbrush);
这是我之前的尝试,但什么也没做。明确地说,我正在尝试将整个屏幕着色为纯色。
最佳答案
此代码使用 GDI(您似乎正在使用)工作:
#include <windows.h>
int main() {
HDC screenDC = GetDC(NULL); //NULL gets whole screen
HBRUSH brush = CreateSolidBrush(RGB(255,0,0)); //create brush
SelectObject(screenDC, brush); //select brush into DC
Rectangle(screenDC, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); //draw rectangle over whole screen
//clean up stuff here
return 0;
}
这只是一个例子,而不是一个可靠的解决方案。比如选择之前的刷回DC总是一个不错的主意。释放 DC 也是如此。另一种选择是在您可以用来绘图的所有内容之上放置一个全屏窗口。
关于c - 如何在 Win32 中为整个屏幕着色纯色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12434328/