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*

lpaElements 매개 변수가 가리키는 배열의 표시 요소에 대한 새 빨강, 녹색, 파랑(RGB) 색 값을 포함하는 COLORREF 값의 배열입니다.

COLORREF를 생성하려면 RGB 매크로를 사용합니다.

반환 값

형식: BOOL

함수가 성공하면 반환 값은 0이 아닌 값입니다.

함수가 실패하면 반환 값은 0입니다. 확장 오류 정보를 가져오려면 GetLastError를 호출합니다.

설명

SetSysColors 함수는 모든 창에 WM_SYSCOLORCHANGE 메시지를 보내 색의 변화를 알 수 있습니다. 또한 현재 표시되는 모든 창의 영향을 받는 부분을 다시 칠하도록 시스템에 지시합니다.

사용자가 지정한 색 설정을 준수하는 것이 가장 좋습니다. 사용자가 색을 변경할 수 있도록 애플리케이션을 작성하는 경우 이 함수를 사용하는 것이 좋습니다. 그러나 이 함수는 현재 세션에만 영향을 줍니다. 시스템이 종료되면 새 색이 저장되지 않습니다.

예제

다음 예제에서는 GetSysColorSetSysColors 함수를 사용하는 방법을 보여 줍니다. 먼저 GetSysColor를 사용하여 창 배경 및 활성 캡션 색을 검색하고 16진수 표기법으로 빨강, 녹색, 파랑(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 Professional[데스크톱 앱만]
지원되는 최소 서버 Windows 2000 Server[데스크톱 앱만]
대상 플랫폼 Windows
헤더 winuser.h(Windows.h 포함)
라이브러리 User32.lib
DLL User32.dll

참고 항목

COLORREF

GetSysColor

RGB