Share via


SetSysColors 函式 (winuser.h)

設定指定之顯示專案的色彩。 顯示元素是視窗的各個部分,以及出現在系統顯示畫面上的顯示器。

語法

BOOL SetSysColors(
  [in] int            cElements,
  [in] const INT      *lpaElements,
  [in] const COLORREF *lpaRgbValues
);

參數

[in] cElements

類型: int

lpaElements陣列中的顯示元素數目。

[in] lpaElements

類型: const INT*

整數的陣列,指定要變更的顯示專案。 如需顯示元素的清單,請參閱 GetSysColor

[in] lpaRgbValues

類型: const COLORREF*

COLORREF值的陣列,其中包含lpaElements參數所指向之陣列中顯示元素的新紅色、綠色、藍色 (RGB) 色彩值。

若要產生 COLORREF,請使用 RGB 宏。

傳回值

類型: BOOL

如果函式成功,則傳回值是非零值。

如果此函式失敗,則傳回值為零。 若要取得擴充的錯誤資訊,請呼叫 GetLastError

備註

SetSysColors函式會將WM_SYSCOLORCHANGE訊息傳送至所有視窗,以通知其色彩變更。 它也會指示系統重新繪製所有目前可見視窗的受影響部分。

最好遵守使用者指定的色彩設定。 如果您要撰寫應用程式來讓使用者變更色彩,則適合使用此函式。 不過,此函式只會影響目前的會話。 系統終止時不會儲存新的色彩。

範例

下列範例示範如何使用 GetSysColorSetSysColors 函式。 首先,此範例會使用GetSysColor來擷取視窗背景和使用中標題的色彩,並以十六進位標記法顯示紅色、綠色、藍色 (RGB) 值。 接下來,範例會使用 SetSysColors 將視窗背景的色彩變更為淺灰色,並將使用中標題列變更為深紫色。 在 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); 
}

規格需求

   
最低支援的用戶端 Windows 2000 專業版 [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限傳統型應用程式]
目標平台 Windows
標頭 winuser.h (包括 Windows.h)
程式庫 User32.lib
Dll User32.dll

另請參閱

COLORREF

GetSysColor

RGB