Win32 API 日本語リファレンス
ホームGraphics.Gdi › SetSysColors

SetSysColors

関数
指定したシステム表示要素の色を変更する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll
#include <windows.h>

BOOL SetSysColors(
    INT cElements,
    const INT* lpaElements,
    const COLORREF* lpaRgbValues
);

パラメーター

名前方向
cElementsINTin
lpaElementsINT*in
lpaRgbValuesCOLORREF*in

戻り値の型: BOOL

各言語での呼び出し定義

// USER32.dll
#include <windows.h>

BOOL SetSysColors(
    INT cElements,
    const INT* lpaElements,
    const COLORREF* lpaRgbValues
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetSysColors(
    int cElements,   // INT
    ref int lpaElements,   // INT*
    ref uint lpaRgbValues   // COLORREF*
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetSysColors(
    cElements As Integer,   ' INT
    ByRef lpaElements As Integer,   ' INT*
    ByRef lpaRgbValues As UInteger   ' COLORREF*
) As Boolean
End Function
' cElements : INT
' lpaElements : INT*
' lpaRgbValues : COLORREF*
Declare PtrSafe Function SetSysColors Lib "user32" ( _
    ByVal cElements As Long, _
    ByRef lpaElements As Long, _
    ByRef lpaRgbValues As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetSysColors = ctypes.windll.user32.SetSysColors
SetSysColors.restype = wintypes.BOOL
SetSysColors.argtypes = [
    ctypes.c_int,  # cElements : INT
    ctypes.POINTER(ctypes.c_int),  # lpaElements : INT*
    ctypes.c_void_p,  # lpaRgbValues : COLORREF*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
SetSysColors = Fiddle::Function.new(
  lib['SetSysColors'],
  [
    Fiddle::TYPE_INT,  # cElements : INT
    Fiddle::TYPE_VOIDP,  # lpaElements : INT*
    Fiddle::TYPE_VOIDP,  # lpaRgbValues : COLORREF*
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn SetSysColors(
        cElements: i32,  // INT
        lpaElements: *const i32,  // INT*
        lpaRgbValues: *const u32  // COLORREF*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool SetSysColors(int cElements, ref int lpaElements, ref uint lpaRgbValues);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetSysColors' -Namespace Win32 -PassThru
# $api::SetSysColors(cElements, lpaElements, lpaRgbValues)
#uselib "USER32.dll"
#func global SetSysColors "SetSysColors" sptr, sptr, sptr
; SetSysColors cElements, varptr(lpaElements), lpaRgbValues   ; 戻り値は stat
; cElements : INT -> "sptr"
; lpaElements : INT* -> "sptr"
; lpaRgbValues : COLORREF* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global SetSysColors "SetSysColors" int, var, int
; res = SetSysColors(cElements, lpaElements, lpaRgbValues)
; cElements : INT -> "int"
; lpaElements : INT* -> "var"
; lpaRgbValues : COLORREF* -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetSysColors(INT cElements, INT* lpaElements, COLORREF* lpaRgbValues)
#uselib "USER32.dll"
#cfunc global SetSysColors "SetSysColors" int, var, int
; res = SetSysColors(cElements, lpaElements, lpaRgbValues)
; cElements : INT -> "int"
; lpaElements : INT* -> "var"
; lpaRgbValues : COLORREF* -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSetSysColors = user32.NewProc("SetSysColors")
)

// cElements (INT), lpaElements (INT*), lpaRgbValues (COLORREF*)
r1, _, err := procSetSysColors.Call(
	uintptr(cElements),
	uintptr(lpaElements),
	uintptr(lpaRgbValues),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetSysColors(
  cElements: Integer;   // INT
  lpaElements: Pointer;   // INT*
  lpaRgbValues: Pointer   // COLORREF*
): BOOL; stdcall;
  external 'USER32.dll' name 'SetSysColors';
result := DllCall("USER32\SetSysColors"
    , "Int", cElements   ; INT
    , "Ptr", lpaElements   ; INT*
    , "Ptr", lpaRgbValues   ; COLORREF*
    , "Int")   ; return: BOOL
●SetSysColors(cElements, lpaElements, lpaRgbValues) = DLL("USER32.dll", "bool SetSysColors(int, void*, void*)")
# 呼び出し: SetSysColors(cElements, lpaElements, lpaRgbValues)
# cElements : INT -> "int"
# lpaElements : INT* -> "void*"
# lpaRgbValues : COLORREF* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。