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

GetThemeString

関数
指定プロパティのテーマ文字列値を取得する。
DLLUXTHEME.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT GetThemeString(
    HTHEME hTheme,
    INT iPartId,
    INT iStateId,
    INT iPropId,
    LPWSTR pszBuff,
    INT cchMaxBuffChars
);

パラメーター

名前方向説明
hThemeHTHEMEinウィンドウの指定されたテーマデータへのハンドル。HTHEME を作成するには OpenThemeData を使用します。
iPartIdINTin文字列プロパティを含むパートを指定する int 型の値。Parts and States を参照してください。
iStateIdINTinパートの状態を指定する int 型の値。Parts and States を参照してください。
iPropIdINTin取得するプロパティを指定する int 型の値。指定可能な値の一覧については、Property Identifiers を参照してください。
pszBuffLPWSTRout文字列値を受け取るバッファへのポインター。
cchMaxBuffCharsINTinpszBuff が格納できる最大文字数を指定する int 型の値。

戻り値の型: HRESULT

公式ドキュメント

文字列プロパティの値を取得します。

戻り値

型: HRESULT

この関数が成功すると S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

HRESULT GetThemeString(
    HTHEME hTheme,
    INT iPartId,
    INT iStateId,
    INT iPropId,
    LPWSTR pszBuff,
    INT cchMaxBuffChars
);
[DllImport("UXTHEME.dll", ExactSpelling = true)]
static extern int GetThemeString(
    IntPtr hTheme,   // HTHEME
    int iPartId,   // INT
    int iStateId,   // INT
    int iPropId,   // INT
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszBuff,   // LPWSTR out
    int cchMaxBuffChars   // INT
);
<DllImport("UXTHEME.dll", ExactSpelling:=True)>
Public Shared Function GetThemeString(
    hTheme As IntPtr,   ' HTHEME
    iPartId As Integer,   ' INT
    iStateId As Integer,   ' INT
    iPropId As Integer,   ' INT
    <MarshalAs(UnmanagedType.LPWStr)> pszBuff As System.Text.StringBuilder,   ' LPWSTR out
    cchMaxBuffChars As Integer   ' INT
) As Integer
End Function
' hTheme : HTHEME
' iPartId : INT
' iStateId : INT
' iPropId : INT
' pszBuff : LPWSTR out
' cchMaxBuffChars : INT
Declare PtrSafe Function GetThemeString Lib "uxtheme" ( _
    ByVal hTheme As LongPtr, _
    ByVal iPartId As Long, _
    ByVal iStateId As Long, _
    ByVal iPropId As Long, _
    ByVal pszBuff As LongPtr, _
    ByVal cchMaxBuffChars As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetThemeString = ctypes.windll.uxtheme.GetThemeString
GetThemeString.restype = ctypes.c_int
GetThemeString.argtypes = [
    ctypes.c_ssize_t,  # hTheme : HTHEME
    ctypes.c_int,  # iPartId : INT
    ctypes.c_int,  # iStateId : INT
    ctypes.c_int,  # iPropId : INT
    wintypes.LPWSTR,  # pszBuff : LPWSTR out
    ctypes.c_int,  # cchMaxBuffChars : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('UXTHEME.dll')
GetThemeString = Fiddle::Function.new(
  lib['GetThemeString'],
  [
    Fiddle::TYPE_INTPTR_T,  # hTheme : HTHEME
    Fiddle::TYPE_INT,  # iPartId : INT
    Fiddle::TYPE_INT,  # iStateId : INT
    Fiddle::TYPE_INT,  # iPropId : INT
    Fiddle::TYPE_VOIDP,  # pszBuff : LPWSTR out
    Fiddle::TYPE_INT,  # cchMaxBuffChars : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "uxtheme")]
extern "system" {
    fn GetThemeString(
        hTheme: isize,  // HTHEME
        iPartId: i32,  // INT
        iStateId: i32,  // INT
        iPropId: i32,  // INT
        pszBuff: *mut u16,  // LPWSTR out
        cchMaxBuffChars: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("UXTHEME.dll")]
public static extern int GetThemeString(IntPtr hTheme, int iPartId, int iStateId, int iPropId, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszBuff, int cchMaxBuffChars);
"@
$api = Add-Type -MemberDefinition $sig -Name 'UXTHEME_GetThemeString' -Namespace Win32 -PassThru
# $api::GetThemeString(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars)
#uselib "UXTHEME.dll"
#func global GetThemeString "GetThemeString" sptr, sptr, sptr, sptr, sptr, sptr
; GetThemeString hTheme, iPartId, iStateId, iPropId, varptr(pszBuff), cchMaxBuffChars   ; 戻り値は stat
; hTheme : HTHEME -> "sptr"
; iPartId : INT -> "sptr"
; iStateId : INT -> "sptr"
; iPropId : INT -> "sptr"
; pszBuff : LPWSTR out -> "sptr"
; cchMaxBuffChars : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "UXTHEME.dll"
#cfunc global GetThemeString "GetThemeString" sptr, int, int, int, var, int
; res = GetThemeString(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars)
; hTheme : HTHEME -> "sptr"
; iPartId : INT -> "int"
; iStateId : INT -> "int"
; iPropId : INT -> "int"
; pszBuff : LPWSTR out -> "var"
; cchMaxBuffChars : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT GetThemeString(HTHEME hTheme, INT iPartId, INT iStateId, INT iPropId, LPWSTR pszBuff, INT cchMaxBuffChars)
#uselib "UXTHEME.dll"
#cfunc global GetThemeString "GetThemeString" intptr, int, int, int, var, int
; res = GetThemeString(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars)
; hTheme : HTHEME -> "intptr"
; iPartId : INT -> "int"
; iStateId : INT -> "int"
; iPropId : INT -> "int"
; pszBuff : LPWSTR out -> "var"
; cchMaxBuffChars : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	uxtheme = windows.NewLazySystemDLL("UXTHEME.dll")
	procGetThemeString = uxtheme.NewProc("GetThemeString")
)

// hTheme (HTHEME), iPartId (INT), iStateId (INT), iPropId (INT), pszBuff (LPWSTR out), cchMaxBuffChars (INT)
r1, _, err := procGetThemeString.Call(
	uintptr(hTheme),
	uintptr(iPartId),
	uintptr(iStateId),
	uintptr(iPropId),
	uintptr(pszBuff),
	uintptr(cchMaxBuffChars),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function GetThemeString(
  hTheme: NativeInt;   // HTHEME
  iPartId: Integer;   // INT
  iStateId: Integer;   // INT
  iPropId: Integer;   // INT
  pszBuff: PWideChar;   // LPWSTR out
  cchMaxBuffChars: Integer   // INT
): Integer; stdcall;
  external 'UXTHEME.dll' name 'GetThemeString';
result := DllCall("UXTHEME\GetThemeString"
    , "Ptr", hTheme   ; HTHEME
    , "Int", iPartId   ; INT
    , "Int", iStateId   ; INT
    , "Int", iPropId   ; INT
    , "Ptr", pszBuff   ; LPWSTR out
    , "Int", cchMaxBuffChars   ; INT
    , "Int")   ; return: HRESULT
●GetThemeString(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars) = DLL("UXTHEME.dll", "int GetThemeString(int, int, int, int, char*, int)")
# 呼び出し: GetThemeString(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars)
# hTheme : HTHEME -> "int"
# iPartId : INT -> "int"
# iStateId : INT -> "int"
# iPropId : INT -> "int"
# pszBuff : LPWSTR out -> "char*"
# cchMaxBuffChars : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "uxtheme" fn GetThemeString(
    hTheme: isize, // HTHEME
    iPartId: i32, // INT
    iStateId: i32, // INT
    iPropId: i32, // INT
    pszBuff: [*c]u16, // LPWSTR out
    cchMaxBuffChars: i32 // INT
) callconv(std.os.windows.WINAPI) i32;
proc GetThemeString(
    hTheme: int,  # HTHEME
    iPartId: int32,  # INT
    iStateId: int32,  # INT
    iPropId: int32,  # INT
    pszBuff: ptr uint16,  # LPWSTR out
    cchMaxBuffChars: int32  # INT
): int32 {.importc: "GetThemeString", stdcall, dynlib: "UXTHEME.dll".}
pragma(lib, "uxtheme");
extern(Windows)
int GetThemeString(
    ptrdiff_t hTheme,   // HTHEME
    int iPartId,   // INT
    int iStateId,   // INT
    int iPropId,   // INT
    wchar* pszBuff,   // LPWSTR out
    int cchMaxBuffChars   // INT
);
ccall((:GetThemeString, "UXTHEME.dll"), stdcall, Int32,
      (Int, Int32, Int32, Int32, Ptr{UInt16}, Int32),
      hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars)
# hTheme : HTHEME -> Int
# iPartId : INT -> Int32
# iStateId : INT -> Int32
# iPropId : INT -> Int32
# pszBuff : LPWSTR out -> Ptr{UInt16}
# cchMaxBuffChars : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetThemeString(
    intptr_t hTheme,
    int32_t iPartId,
    int32_t iStateId,
    int32_t iPropId,
    uint16_t* pszBuff,
    int32_t cchMaxBuffChars);
]]
local uxtheme = ffi.load("uxtheme")
-- uxtheme.GetThemeString(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars)
-- hTheme : HTHEME
-- iPartId : INT
-- iStateId : INT
-- iPropId : INT
-- pszBuff : LPWSTR out
-- cchMaxBuffChars : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('UXTHEME.dll');
const GetThemeString = lib.func('__stdcall', 'GetThemeString', 'int32_t', ['intptr_t', 'int32_t', 'int32_t', 'int32_t', 'uint16_t *', 'int32_t']);
// GetThemeString(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars)
// hTheme : HTHEME -> 'intptr_t'
// iPartId : INT -> 'int32_t'
// iStateId : INT -> 'int32_t'
// iPropId : INT -> 'int32_t'
// pszBuff : LPWSTR out -> 'uint16_t *'
// cchMaxBuffChars : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("UXTHEME.dll", {
  GetThemeString: { parameters: ["isize", "i32", "i32", "i32", "buffer", "i32"], result: "i32" },
});
// lib.symbols.GetThemeString(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars)
// hTheme : HTHEME -> "isize"
// iPartId : INT -> "i32"
// iStateId : INT -> "i32"
// iPropId : INT -> "i32"
// pszBuff : LPWSTR out -> "buffer"
// cchMaxBuffChars : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetThemeString(
    intptr_t hTheme,
    int32_t iPartId,
    int32_t iStateId,
    int32_t iPropId,
    uint16_t* pszBuff,
    int32_t cchMaxBuffChars);
C, "UXTHEME.dll");
// $ffi->GetThemeString(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars);
// hTheme : HTHEME
// iPartId : INT
// iStateId : INT
// iPropId : INT
// pszBuff : LPWSTR out
// cchMaxBuffChars : INT
// 構造体/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 GetThemeString(
        long hTheme,   // HTHEME
        int iPartId,   // INT
        int iStateId,   // INT
        int iPropId,   // INT
        char[] pszBuff,   // LPWSTR out
        int cchMaxBuffChars   // INT
    );
}
@[Link("uxtheme")]
lib LibUXTHEME
  fun GetThemeString = GetThemeString(
    hTheme : LibC::SSizeT,   # HTHEME
    iPartId : Int32,   # INT
    iStateId : Int32,   # INT
    iPropId : Int32,   # INT
    pszBuff : UInt16*,   # LPWSTR out
    cchMaxBuffChars : Int32   # INT
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetThemeStringNative = Int32 Function(IntPtr, Int32, Int32, Int32, Pointer<Utf16>, Int32);
typedef GetThemeStringDart = int Function(int, int, int, int, Pointer<Utf16>, int);
final GetThemeString = DynamicLibrary.open('UXTHEME.dll')
    .lookupFunction<GetThemeStringNative, GetThemeStringDart>('GetThemeString');
// hTheme : HTHEME -> IntPtr
// iPartId : INT -> Int32
// iStateId : INT -> Int32
// iPropId : INT -> Int32
// pszBuff : LPWSTR out -> Pointer<Utf16>
// cchMaxBuffChars : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetThemeString(
  hTheme: NativeInt;   // HTHEME
  iPartId: Integer;   // INT
  iStateId: Integer;   // INT
  iPropId: Integer;   // INT
  pszBuff: PWideChar;   // LPWSTR out
  cchMaxBuffChars: Integer   // INT
): Integer; stdcall;
  external 'UXTHEME.dll' name 'GetThemeString';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetThemeString"
  c_GetThemeString :: CIntPtr -> Int32 -> Int32 -> Int32 -> CWString -> Int32 -> IO Int32
-- hTheme : HTHEME -> CIntPtr
-- iPartId : INT -> Int32
-- iStateId : INT -> Int32
-- iPropId : INT -> Int32
-- pszBuff : LPWSTR out -> CWString
-- cchMaxBuffChars : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getthemestring =
  foreign "GetThemeString"
    (intptr_t @-> int32_t @-> int32_t @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* hTheme : HTHEME -> intptr_t *)
(* iPartId : INT -> int32_t *)
(* iStateId : INT -> int32_t *)
(* iPropId : INT -> int32_t *)
(* pszBuff : LPWSTR out -> (ptr uint16_t) *)
(* cchMaxBuffChars : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library uxtheme (t "UXTHEME.dll"))
(cffi:use-foreign-library uxtheme)

(cffi:defcfun ("GetThemeString" get-theme-string :convention :stdcall) :int32
  (h-theme :int64)   ; HTHEME
  (i-part-id :int32)   ; INT
  (i-state-id :int32)   ; INT
  (i-prop-id :int32)   ; INT
  (psz-buff :pointer)   ; LPWSTR out
  (cch-max-buff-chars :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetThemeString = Win32::API::More->new('UXTHEME',
    'int GetThemeString(LPARAM hTheme, int iPartId, int iStateId, int iPropId, LPWSTR pszBuff, int cchMaxBuffChars)');
# my $ret = $GetThemeString->Call($hTheme, $iPartId, $iStateId, $iPropId, $pszBuff, $cchMaxBuffChars);
# hTheme : HTHEME -> LPARAM
# iPartId : INT -> int
# iStateId : INT -> int
# iPropId : INT -> int
# pszBuff : LPWSTR out -> LPWSTR
# cchMaxBuffChars : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。