ホーム › UI.Controls › SetWindowThemeAttribute
SetWindowThemeAttribute
関数ウィンドウのテーマ属性(非クライアント領域などの挙動)を設定する。
シグネチャ
// UXTHEME.dll
#include <windows.h>
HRESULT SetWindowThemeAttribute(
HWND hwnd,
WINDOWTHEMEATTRIBUTETYPE eAttribute,
void* pvAttribute,
DWORD cbAttribute
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||
|---|---|---|---|---|---|---|---|
| hwnd | HWND | in | 変更を適用するウィンドウへのハンドルです。 | ||||
| eAttribute | WINDOWTHEMEATTRIBUTETYPE | in | 設定する属性の種類を指定する WINDOWTHEMEATTRIBUTETYPE 型の値です。このパラメーターの値によって、pvAttribute パラメーターに渡すべきデータの型が決まります。次の値を指定できます。
| ||||
| pvAttribute | void* | in | 設定する属性を指定するポインターです。型は eAttribute の値によって決まります。 | ||||
| cbAttribute | DWORD | in | pvAttribute が指すデータのサイズをバイト単位で指定します。 |
戻り値の型: HRESULT
公式ドキュメント
指定したウィンドウにビジュアルスタイルを適用する方法を制御する属性を設定します。
戻り値
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// UXTHEME.dll
#include <windows.h>
HRESULT SetWindowThemeAttribute(
HWND hwnd,
WINDOWTHEMEATTRIBUTETYPE eAttribute,
void* pvAttribute,
DWORD cbAttribute
);[DllImport("UXTHEME.dll", ExactSpelling = true)]
static extern int SetWindowThemeAttribute(
IntPtr hwnd, // HWND
int eAttribute, // WINDOWTHEMEATTRIBUTETYPE
IntPtr pvAttribute, // void*
uint cbAttribute // DWORD
);<DllImport("UXTHEME.dll", ExactSpelling:=True)>
Public Shared Function SetWindowThemeAttribute(
hwnd As IntPtr, ' HWND
eAttribute As Integer, ' WINDOWTHEMEATTRIBUTETYPE
pvAttribute As IntPtr, ' void*
cbAttribute As UInteger ' DWORD
) As Integer
End Function' hwnd : HWND
' eAttribute : WINDOWTHEMEATTRIBUTETYPE
' pvAttribute : void*
' cbAttribute : DWORD
Declare PtrSafe Function SetWindowThemeAttribute Lib "uxtheme" ( _
ByVal hwnd As LongPtr, _
ByVal eAttribute As Long, _
ByVal pvAttribute As LongPtr, _
ByVal cbAttribute As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetWindowThemeAttribute = ctypes.windll.uxtheme.SetWindowThemeAttribute
SetWindowThemeAttribute.restype = ctypes.c_int
SetWindowThemeAttribute.argtypes = [
wintypes.HANDLE, # hwnd : HWND
ctypes.c_int, # eAttribute : WINDOWTHEMEATTRIBUTETYPE
ctypes.POINTER(None), # pvAttribute : void*
wintypes.DWORD, # cbAttribute : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('UXTHEME.dll')
SetWindowThemeAttribute = Fiddle::Function.new(
lib['SetWindowThemeAttribute'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND
Fiddle::TYPE_INT, # eAttribute : WINDOWTHEMEATTRIBUTETYPE
Fiddle::TYPE_VOIDP, # pvAttribute : void*
-Fiddle::TYPE_INT, # cbAttribute : DWORD
],
Fiddle::TYPE_INT)#[link(name = "uxtheme")]
extern "system" {
fn SetWindowThemeAttribute(
hwnd: *mut core::ffi::c_void, // HWND
eAttribute: i32, // WINDOWTHEMEATTRIBUTETYPE
pvAttribute: *mut (), // void*
cbAttribute: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("UXTHEME.dll")]
public static extern int SetWindowThemeAttribute(IntPtr hwnd, int eAttribute, IntPtr pvAttribute, uint cbAttribute);
"@
$api = Add-Type -MemberDefinition $sig -Name 'UXTHEME_SetWindowThemeAttribute' -Namespace Win32 -PassThru
# $api::SetWindowThemeAttribute(hwnd, eAttribute, pvAttribute, cbAttribute)#uselib "UXTHEME.dll"
#func global SetWindowThemeAttribute "SetWindowThemeAttribute" sptr, sptr, sptr, sptr
; SetWindowThemeAttribute hwnd, eAttribute, pvAttribute, cbAttribute ; 戻り値は stat
; hwnd : HWND -> "sptr"
; eAttribute : WINDOWTHEMEATTRIBUTETYPE -> "sptr"
; pvAttribute : void* -> "sptr"
; cbAttribute : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "UXTHEME.dll"
#cfunc global SetWindowThemeAttribute "SetWindowThemeAttribute" sptr, int, sptr, int
; res = SetWindowThemeAttribute(hwnd, eAttribute, pvAttribute, cbAttribute)
; hwnd : HWND -> "sptr"
; eAttribute : WINDOWTHEMEATTRIBUTETYPE -> "int"
; pvAttribute : void* -> "sptr"
; cbAttribute : DWORD -> "int"; HRESULT SetWindowThemeAttribute(HWND hwnd, WINDOWTHEMEATTRIBUTETYPE eAttribute, void* pvAttribute, DWORD cbAttribute)
#uselib "UXTHEME.dll"
#cfunc global SetWindowThemeAttribute "SetWindowThemeAttribute" intptr, int, intptr, int
; res = SetWindowThemeAttribute(hwnd, eAttribute, pvAttribute, cbAttribute)
; hwnd : HWND -> "intptr"
; eAttribute : WINDOWTHEMEATTRIBUTETYPE -> "int"
; pvAttribute : void* -> "intptr"
; cbAttribute : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
uxtheme = windows.NewLazySystemDLL("UXTHEME.dll")
procSetWindowThemeAttribute = uxtheme.NewProc("SetWindowThemeAttribute")
)
// hwnd (HWND), eAttribute (WINDOWTHEMEATTRIBUTETYPE), pvAttribute (void*), cbAttribute (DWORD)
r1, _, err := procSetWindowThemeAttribute.Call(
uintptr(hwnd),
uintptr(eAttribute),
uintptr(pvAttribute),
uintptr(cbAttribute),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SetWindowThemeAttribute(
hwnd: THandle; // HWND
eAttribute: Integer; // WINDOWTHEMEATTRIBUTETYPE
pvAttribute: Pointer; // void*
cbAttribute: DWORD // DWORD
): Integer; stdcall;
external 'UXTHEME.dll' name 'SetWindowThemeAttribute';result := DllCall("UXTHEME\SetWindowThemeAttribute"
, "Ptr", hwnd ; HWND
, "Int", eAttribute ; WINDOWTHEMEATTRIBUTETYPE
, "Ptr", pvAttribute ; void*
, "UInt", cbAttribute ; DWORD
, "Int") ; return: HRESULT●SetWindowThemeAttribute(hwnd, eAttribute, pvAttribute, cbAttribute) = DLL("UXTHEME.dll", "int SetWindowThemeAttribute(void*, int, void*, dword)")
# 呼び出し: SetWindowThemeAttribute(hwnd, eAttribute, pvAttribute, cbAttribute)
# hwnd : HWND -> "void*"
# eAttribute : WINDOWTHEMEATTRIBUTETYPE -> "int"
# pvAttribute : void* -> "void*"
# cbAttribute : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "uxtheme" fn SetWindowThemeAttribute(
hwnd: ?*anyopaque, // HWND
eAttribute: i32, // WINDOWTHEMEATTRIBUTETYPE
pvAttribute: ?*anyopaque, // void*
cbAttribute: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc SetWindowThemeAttribute(
hwnd: pointer, # HWND
eAttribute: int32, # WINDOWTHEMEATTRIBUTETYPE
pvAttribute: pointer, # void*
cbAttribute: uint32 # DWORD
): int32 {.importc: "SetWindowThemeAttribute", stdcall, dynlib: "UXTHEME.dll".}pragma(lib, "uxtheme");
extern(Windows)
int SetWindowThemeAttribute(
void* hwnd, // HWND
int eAttribute, // WINDOWTHEMEATTRIBUTETYPE
void* pvAttribute, // void*
uint cbAttribute // DWORD
);ccall((:SetWindowThemeAttribute, "UXTHEME.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Ptr{Cvoid}, UInt32),
hwnd, eAttribute, pvAttribute, cbAttribute)
# hwnd : HWND -> Ptr{Cvoid}
# eAttribute : WINDOWTHEMEATTRIBUTETYPE -> Int32
# pvAttribute : void* -> Ptr{Cvoid}
# cbAttribute : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetWindowThemeAttribute(
void* hwnd,
int32_t eAttribute,
void* pvAttribute,
uint32_t cbAttribute);
]]
local uxtheme = ffi.load("uxtheme")
-- uxtheme.SetWindowThemeAttribute(hwnd, eAttribute, pvAttribute, cbAttribute)
-- hwnd : HWND
-- eAttribute : WINDOWTHEMEATTRIBUTETYPE
-- pvAttribute : void*
-- cbAttribute : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('UXTHEME.dll');
const SetWindowThemeAttribute = lib.func('__stdcall', 'SetWindowThemeAttribute', 'int32_t', ['void *', 'int32_t', 'void *', 'uint32_t']);
// SetWindowThemeAttribute(hwnd, eAttribute, pvAttribute, cbAttribute)
// hwnd : HWND -> 'void *'
// eAttribute : WINDOWTHEMEATTRIBUTETYPE -> 'int32_t'
// pvAttribute : void* -> 'void *'
// cbAttribute : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("UXTHEME.dll", {
SetWindowThemeAttribute: { parameters: ["pointer", "i32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetWindowThemeAttribute(hwnd, eAttribute, pvAttribute, cbAttribute)
// hwnd : HWND -> "pointer"
// eAttribute : WINDOWTHEMEATTRIBUTETYPE -> "i32"
// pvAttribute : void* -> "pointer"
// cbAttribute : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetWindowThemeAttribute(
void* hwnd,
int32_t eAttribute,
void* pvAttribute,
uint32_t cbAttribute);
C, "UXTHEME.dll");
// $ffi->SetWindowThemeAttribute(hwnd, eAttribute, pvAttribute, cbAttribute);
// hwnd : HWND
// eAttribute : WINDOWTHEMEATTRIBUTETYPE
// pvAttribute : void*
// cbAttribute : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Uxtheme extends StdCallLibrary {
Uxtheme INSTANCE = Native.load("uxtheme", Uxtheme.class);
int SetWindowThemeAttribute(
Pointer hwnd, // HWND
int eAttribute, // WINDOWTHEMEATTRIBUTETYPE
Pointer pvAttribute, // void*
int cbAttribute // DWORD
);
}@[Link("uxtheme")]
lib LibUXTHEME
fun SetWindowThemeAttribute = SetWindowThemeAttribute(
hwnd : Void*, # HWND
eAttribute : Int32, # WINDOWTHEMEATTRIBUTETYPE
pvAttribute : Void*, # void*
cbAttribute : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetWindowThemeAttributeNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Uint32);
typedef SetWindowThemeAttributeDart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final SetWindowThemeAttribute = DynamicLibrary.open('UXTHEME.dll')
.lookupFunction<SetWindowThemeAttributeNative, SetWindowThemeAttributeDart>('SetWindowThemeAttribute');
// hwnd : HWND -> Pointer<Void>
// eAttribute : WINDOWTHEMEATTRIBUTETYPE -> Int32
// pvAttribute : void* -> Pointer<Void>
// cbAttribute : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetWindowThemeAttribute(
hwnd: THandle; // HWND
eAttribute: Integer; // WINDOWTHEMEATTRIBUTETYPE
pvAttribute: Pointer; // void*
cbAttribute: DWORD // DWORD
): Integer; stdcall;
external 'UXTHEME.dll' name 'SetWindowThemeAttribute';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetWindowThemeAttribute"
c_SetWindowThemeAttribute :: Ptr () -> Int32 -> Ptr () -> Word32 -> IO Int32
-- hwnd : HWND -> Ptr ()
-- eAttribute : WINDOWTHEMEATTRIBUTETYPE -> Int32
-- pvAttribute : void* -> Ptr ()
-- cbAttribute : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setwindowthemeattribute =
foreign "SetWindowThemeAttribute"
((ptr void) @-> int32_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hwnd : HWND -> (ptr void) *)
(* eAttribute : WINDOWTHEMEATTRIBUTETYPE -> int32_t *)
(* pvAttribute : void* -> (ptr void) *)
(* cbAttribute : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library uxtheme (t "UXTHEME.dll"))
(cffi:use-foreign-library uxtheme)
(cffi:defcfun ("SetWindowThemeAttribute" set-window-theme-attribute :convention :stdcall) :int32
(hwnd :pointer) ; HWND
(e-attribute :int32) ; WINDOWTHEMEATTRIBUTETYPE
(pv-attribute :pointer) ; void*
(cb-attribute :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetWindowThemeAttribute = Win32::API::More->new('UXTHEME',
'int SetWindowThemeAttribute(HANDLE hwnd, int eAttribute, LPVOID pvAttribute, DWORD cbAttribute)');
# my $ret = $SetWindowThemeAttribute->Call($hwnd, $eAttribute, $pvAttribute, $cbAttribute);
# hwnd : HWND -> HANDLE
# eAttribute : WINDOWTHEMEATTRIBUTETYPE -> int
# pvAttribute : void* -> LPVOID
# cbAttribute : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。