鱼C论坛

 找回密码
 立即注册
查看: 3069|回复: 0

[API档案] SetSysColors

[复制链接]
发表于 2016-7-9 02:54:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
注:本文档由 haoyycom 翻译,小甲鱼校对。

原文链接 -> 传送门

函数功能:

SetSysColors 函数用于设置指定显示元素的颜色。显示元素为窗口部分和系统显示屏上的显示区。


API 函数原型:

注释:_In_ 说明该参数是输入的。
  1. BOOL WINAPI SetSysColors(
  2.   _In_       int      cElements,
  3.   _In_ const INT      *lpaElements,
  4.   _In_ const COLORREF *lpaRgbValues
  5. );
复制代码


参数解析:

参数 含义
cElements 指定在 lpaElements 指向的数组中元素的数量
lpaElements1. 指向一个整数数组,数组规定将要改变的显示元素
2. 针对一系列的显示元素,请参考 GetSysColor 函数
lpaRgbValues1. COLORREF 值的一个数组,数组包含显示元素,新的红色,蓝色和蓝色的颜色值,显示元素由 lpaElements 参数指定
2. 使用 RBG 宏定义,得到一个 COLORREF


返回值:

1. 如果函数调用成功,返回值是非 0;

2. 如果函数调用失败,返回值是 0。

调用 GetLastError 函数可以获取更多错误信息。


备注:

SetSysColors 函数给所有窗口发送一个 WM_SYSCOLORCHANGE 信息,告知窗口要改变颜色。该函数也告知系统重新喷绘当前所有可见窗口的指定的部分。最好遵循用户指定的颜色设置。如果你是在写一个应用,使用户能改变颜色,那么使用这个函数很恰当。但是,这个函数只对当前区域起作用。系统结束时,新的颜色不会被保存。


演示:

下面的例子演示了 GetSysColor 函数和 SetSysColors 函数的使用。例子先获取窗口和活动标题的颜色,并显示红,绿,蓝(RGB)的十六进制值。接下来,例子使用 SetSysColor 函数将窗口的背景色变成浅灰色,把活动的标题栏变成深紫色。经过 10 秒延迟后,例子用 SetSysColors 函数恢复元素之前的颜色。

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #pragma comment(lib, "user32.lib")

  4. void main()
  5. {
  6.     int aElements[2] = {COLOR_WINDOW, COLOR_ACTIVECAPTION};
  7.     DWORD aOldColors[2];
  8.     DWORD aNewColors[2];

  9.     // Get the current color of the window background.

  10.     aOldColors[0] = GetSysColor(aElements[0]);

  11.     printf("Current window color: {0x%x, 0x%x, 0x%x}\n",
  12.         GetRValue(aOldColors[0]),
  13.         GetGValue(aOldColors[0]),
  14.         GetBValue(aOldColors[0]));

  15.     // Get the current color of the active caption.

  16.     aOldColors[1] = GetSysColor(aElements[1]);

  17.     printf("Current active caption color: {0x%x, 0x%x, 0x%x}\n",
  18.         GetRValue(aOldColors[1]),
  19.         GetGValue(aOldColors[1]),
  20.         GetBValue(aOldColors[1]));

  21.     // Define new colors for the elements

  22.     aNewColors[0] = RGB(0x80, 0x80, 0x80);  // light gray
  23.     aNewColors[1] = RGB(0x80, 0x00, 0x80);  // dark purple

  24.     printf("\nNew window color: {0x%x, 0x%x, 0x%x}\n",
  25.         GetRValue(aNewColors[0]),
  26.         GetGValue(aNewColors[0]),
  27.         GetBValue(aNewColors[0]));

  28.     printf("New active caption color: {0x%x, 0x%x, 0x%x}\n",
  29.         GetRValue(aNewColors[1]),
  30.         GetGValue(aNewColors[1]),
  31.         GetBValue(aNewColors[1]));

  32.     // Set the elements defined in aElements to the colors defined
  33.     // in aNewColors

  34.     SetSysColors(2, aElements, aNewColors);

  35.     printf("\nWindow background and active border have been changed.\n");
  36.     printf("Reverting to previous colors in 10 seconds...\n");

  37.     Sleep(10000);   

  38.     // Restore the elements to their original colors

  39.     SetSysColors(2, aElements, aOldColors);
  40. }
复制代码


需求:

Minimum supported client Windows 2000 专业版 [仅桌面应用程序]
Minimum supported server Windows 2000 服务器版 [仅桌面应用程序]
Header Winuser.h (包含于 Windows.h)
Library User32.lib
DLL User32.dll


【API档案】版权归鱼C工作室(www.fishc.com)所有,转载请注明来源。

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-21 20:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表