原文链接 -> 传送门
函数功能:
SetSysColors 函数用于设置指定显示元素的颜色。显示元素为窗口部分和系统显示屏上的显示区。
API 函数原型:
注释:_In_ 说明该参数是输入的。
BOOL WINAPI SetSysColors( _In_ int cElements, _In_ const INT *lpaElements, _In_ const COLORREF *lpaRgbValues );
参数解析:
|
参数 |
含义 |
|
cElements |
指定在 lpaElements 指向的数组中元素的数量 |
|
lpaElements |
1. 指向一个整数数组,数组规定将要改变的显示元素 |
|
lpaRgbValues |
1. COLORREF 值的一个数组,数组包含显示元素,新的红色,蓝色和蓝色的颜色值,显示元素由 lpaElements 参数指定 |
返回值:
1. 如果函数调用成功,返回值是非 0;
2. 如果函数调用失败,返回值是 0。
调用 GetLastError 函数可以获取更多错误信息。
备注:
SetSysColors 函数给所有窗口发送一个 WM_SYSCOLORCHANGE 信息,告知窗口要改变颜色。该函数也告知系统重新喷绘当前所有可见窗口的指定的部分。最好遵循用户指定的颜色设置。如果你是在写一个应用,使用户能改变颜色,那么使用这个函数很恰当。但是,这个函数只对当前区域起作用。系统结束时,新的颜色不会被保存。
演示:
下面的例子演示了 GetSysColor 函数和 SetSysColors 函数的使用。例子先获取窗口和活动标题的颜色,并显示红,绿,蓝(RGB)的十六进制值。接下来,例子使用 SetSysColor 函数将窗口的背景色变成浅灰色,把活动的标题栏变成深紫色。经过 10 秒延迟后,例子用 SetSysColors 函数恢复元素之前的颜色。
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32.lib")
void main()
{
int aElements[2] = {COLOR_WINDOW, COLOR_ACTIVECAPTION};
DWORD aOldColors[2];
DWORD aNewColors[2];
// Get the current color of the window background.
aOldColors[0] = GetSysColor(aElements[0]);
printf("Current window color: {0x%x, 0x%x, 0x%x}\n",
GetRValue(aOldColors[0]),
GetGValue(aOldColors[0]),
GetBValue(aOldColors[0]));
// Get the current color of the active caption.
aOldColors[1] = GetSysColor(aElements[1]);
printf("Current active caption color: {0x%x, 0x%x, 0x%x}\n",
GetRValue(aOldColors[1]),
GetGValue(aOldColors[1]),
GetBValue(aOldColors[1]));
// Define new colors for the elements
aNewColors[0] = RGB(0x80, 0x80, 0x80); // light gray
aNewColors[1] = RGB(0x80, 0x00, 0x80); // dark purple
printf("\nNew window color: {0x%x, 0x%x, 0x%x}\n",
GetRValue(aNewColors[0]),
GetGValue(aNewColors[0]),
GetBValue(aNewColors[0]));
printf("New active caption color: {0x%x, 0x%x, 0x%x}\n",
GetRValue(aNewColors[1]),
GetGValue(aNewColors[1]),
GetBValue(aNewColors[1]));
// Set the elements defined in aElements to the colors defined
// in aNewColors
SetSysColors(2, aElements, aNewColors);
printf("\nWindow background and active border have been changed.\n");
printf("Reverting to previous colors in 10 seconds...\n");
Sleep(10000);
// Restore the elements to their original colors
SetSysColors(2, aElements, aOldColors);
}
需求:
|
Minimum supported client |
Windows 2000 专业版 [仅桌面应用程序] |
|
Minimum supported server |
Windows 2000 服务器版 [仅桌面应用程序] |
|
Header |
Winuser.h (包含于 Windows.h) |
|
Library |
User32.lib |
|
DLL |
User32.dll |




