Win32 API 日本語リファレンス
ホームUI.Controls › SetWindowTheme

SetWindowTheme

関数
ウィンドウに適用するビジュアルスタイルのサブアプリ名とサブIDを設定する。
DLLUXTHEME.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT SetWindowTheme(
    HWND hwnd,
    LPCWSTR pszSubAppName,   // optional
    LPCWSTR pszSubIdList   // optional
);

パラメーター

名前方向
hwndHWNDin
pszSubAppNameLPCWSTRinoptional
pszSubIdListLPCWSTRinoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SetWindowTheme(
    HWND hwnd,
    LPCWSTR pszSubAppName,   // optional
    LPCWSTR pszSubIdList   // optional
);
[DllImport("UXTHEME.dll", ExactSpelling = true)]
static extern int SetWindowTheme(
    IntPtr hwnd,   // HWND
    [MarshalAs(UnmanagedType.LPWStr)] string pszSubAppName,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszSubIdList   // LPCWSTR optional
);
<DllImport("UXTHEME.dll", ExactSpelling:=True)>
Public Shared Function SetWindowTheme(
    hwnd As IntPtr,   ' HWND
    <MarshalAs(UnmanagedType.LPWStr)> pszSubAppName As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> pszSubIdList As String   ' LPCWSTR optional
) As Integer
End Function
' hwnd : HWND
' pszSubAppName : LPCWSTR optional
' pszSubIdList : LPCWSTR optional
Declare PtrSafe Function SetWindowTheme Lib "uxtheme" ( _
    ByVal hwnd As LongPtr, _
    ByVal pszSubAppName As LongPtr, _
    ByVal pszSubIdList As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetWindowTheme = ctypes.windll.uxtheme.SetWindowTheme
SetWindowTheme.restype = ctypes.c_int
SetWindowTheme.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND
    wintypes.LPCWSTR,  # pszSubAppName : LPCWSTR optional
    wintypes.LPCWSTR,  # pszSubIdList : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('UXTHEME.dll')
SetWindowTheme = Fiddle::Function.new(
  lib['SetWindowTheme'],
  [
    Fiddle::TYPE_VOIDP,  # hwnd : HWND
    Fiddle::TYPE_VOIDP,  # pszSubAppName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pszSubIdList : LPCWSTR optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "uxtheme")]
extern "system" {
    fn SetWindowTheme(
        hwnd: *mut core::ffi::c_void,  // HWND
        pszSubAppName: *const u16,  // LPCWSTR optional
        pszSubIdList: *const u16  // LPCWSTR optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("UXTHEME.dll")]
public static extern int SetWindowTheme(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszSubAppName, [MarshalAs(UnmanagedType.LPWStr)] string pszSubIdList);
"@
$api = Add-Type -MemberDefinition $sig -Name 'UXTHEME_SetWindowTheme' -Namespace Win32 -PassThru
# $api::SetWindowTheme(hwnd, pszSubAppName, pszSubIdList)
#uselib "UXTHEME.dll"
#func global SetWindowTheme "SetWindowTheme" sptr, sptr, sptr
; SetWindowTheme hwnd, pszSubAppName, pszSubIdList   ; 戻り値は stat
; hwnd : HWND -> "sptr"
; pszSubAppName : LPCWSTR optional -> "sptr"
; pszSubIdList : LPCWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "UXTHEME.dll"
#cfunc global SetWindowTheme "SetWindowTheme" sptr, wstr, wstr
; res = SetWindowTheme(hwnd, pszSubAppName, pszSubIdList)
; hwnd : HWND -> "sptr"
; pszSubAppName : LPCWSTR optional -> "wstr"
; pszSubIdList : LPCWSTR optional -> "wstr"
; HRESULT SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList)
#uselib "UXTHEME.dll"
#cfunc global SetWindowTheme "SetWindowTheme" intptr, wstr, wstr
; res = SetWindowTheme(hwnd, pszSubAppName, pszSubIdList)
; hwnd : HWND -> "intptr"
; pszSubAppName : LPCWSTR optional -> "wstr"
; pszSubIdList : LPCWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	uxtheme = windows.NewLazySystemDLL("UXTHEME.dll")
	procSetWindowTheme = uxtheme.NewProc("SetWindowTheme")
)

// hwnd (HWND), pszSubAppName (LPCWSTR optional), pszSubIdList (LPCWSTR optional)
r1, _, err := procSetWindowTheme.Call(
	uintptr(hwnd),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSubAppName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSubIdList))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SetWindowTheme(
  hwnd: THandle;   // HWND
  pszSubAppName: PWideChar;   // LPCWSTR optional
  pszSubIdList: PWideChar   // LPCWSTR optional
): Integer; stdcall;
  external 'UXTHEME.dll' name 'SetWindowTheme';
result := DllCall("UXTHEME\SetWindowTheme"
    , "Ptr", hwnd   ; HWND
    , "WStr", pszSubAppName   ; LPCWSTR optional
    , "WStr", pszSubIdList   ; LPCWSTR optional
    , "Int")   ; return: HRESULT
●SetWindowTheme(hwnd, pszSubAppName, pszSubIdList) = DLL("UXTHEME.dll", "int SetWindowTheme(void*, char*, char*)")
# 呼び出し: SetWindowTheme(hwnd, pszSubAppName, pszSubIdList)
# hwnd : HWND -> "void*"
# pszSubAppName : LPCWSTR optional -> "char*"
# pszSubIdList : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。