SetSysColors 関数 (winuser.h)

指定した表示要素の色を設定します。 Display 要素は、ウィンドウのさまざまな部分と、システム表示画面に表示されるディスプレイです。

構文

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メッセージを送信します。 また、現在表示されているすべてのウィンドウの影響を受ける部分を再描画するようにシステムに指示します。

ユーザーが指定した色の設定を考慮することをお勧めします。 ユーザーが色を変更できるようにアプリケーションを作成する場合は、この関数を使用するのが適切です。 ただし、この関数は現在のセッションにのみ影響します。 システムが終了しても、新しい色は保存されません。

次の例では、 GetSysColor 関数と SetSysColors 関数の使用方法 示します。 最初に、GetSysColor を使用してウィンドウの背景とアクティブなキャプションの色を取得し、赤、緑、青 (RGB) の値を 16 進数表記で表示します。 次に、 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 を含む)
Library User32.lib
[DLL] User32.dll

関連項目

COLORREF

GetSysColor

RGB