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

GetThemeSysString

関数
テーマで定義されたシステム文字列を取得する。
DLLUXTHEME.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT GetThemeSysString(
    HTHEME hTheme,
    INT iStringId,
    LPWSTR pszStringBuff,
    INT cchMaxStringChars
);

パラメーター

名前方向説明
hThemeHTHEMEinテーマデータへのハンドルです。
iStringIdINTin

システム文字列を指定する int 型の値です。次のいずれかの値を指定できます。

意味
TMT_CSSNAME
hTheme で指定されたテーマに関連付けられた CSS ファイルの名前です。
TMT_XMLNAME
hTheme で指定されたテーマに関連付けられた XML ファイルの名前です。
pszStringBuffLPWSTRoutこの関数から文字列値を受け取るバッファへのポインタです。
cchMaxStringCharsINTin文字列バッファが保持できる最大文字数を指定する int 型の値です。

戻り値の型: HRESULT

公式ドキュメント

システム文字列の値を取得します。

戻り値

型: HRESULT

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

解説(Remarks)

テーマデータハンドルが NULL ハンドルでない場合、この関数はビジュアルスタイルの SysMetrics セクションから目的の文字列を返します。テーマデータハンドルが NULL の場合、この関数は同じ種類のグローバルシステムメトリックの値を返します。

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

各言語での呼び出し定義

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

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

GetThemeSysString = ctypes.windll.uxtheme.GetThemeSysString
GetThemeSysString.restype = ctypes.c_int
GetThemeSysString.argtypes = [
    ctypes.c_ssize_t,  # hTheme : HTHEME
    ctypes.c_int,  # iStringId : INT
    wintypes.LPWSTR,  # pszStringBuff : LPWSTR out
    ctypes.c_int,  # cchMaxStringChars : INT
]
require 'fiddle'
require 'fiddle/import'

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

var (
	uxtheme = windows.NewLazySystemDLL("UXTHEME.dll")
	procGetThemeSysString = uxtheme.NewProc("GetThemeSysString")
)

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

extern "uxtheme" fn GetThemeSysString(
    hTheme: isize, // HTHEME
    iStringId: i32, // INT
    pszStringBuff: [*c]u16, // LPWSTR out
    cchMaxStringChars: i32 // INT
) callconv(std.os.windows.WINAPI) i32;
proc GetThemeSysString(
    hTheme: int,  # HTHEME
    iStringId: int32,  # INT
    pszStringBuff: ptr uint16,  # LPWSTR out
    cchMaxStringChars: int32  # INT
): int32 {.importc: "GetThemeSysString", stdcall, dynlib: "UXTHEME.dll".}
pragma(lib, "uxtheme");
extern(Windows)
int GetThemeSysString(
    ptrdiff_t hTheme,   // HTHEME
    int iStringId,   // INT
    wchar* pszStringBuff,   // LPWSTR out
    int cchMaxStringChars   // INT
);
ccall((:GetThemeSysString, "UXTHEME.dll"), stdcall, Int32,
      (Int, Int32, Ptr{UInt16}, Int32),
      hTheme, iStringId, pszStringBuff, cchMaxStringChars)
# hTheme : HTHEME -> Int
# iStringId : INT -> Int32
# pszStringBuff : LPWSTR out -> Ptr{UInt16}
# cchMaxStringChars : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetThemeSysString(
    intptr_t hTheme,
    int32_t iStringId,
    uint16_t* pszStringBuff,
    int32_t cchMaxStringChars);
]]
local uxtheme = ffi.load("uxtheme")
-- uxtheme.GetThemeSysString(hTheme, iStringId, pszStringBuff, cchMaxStringChars)
-- hTheme : HTHEME
-- iStringId : INT
-- pszStringBuff : LPWSTR out
-- cchMaxStringChars : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('UXTHEME.dll');
const GetThemeSysString = lib.func('__stdcall', 'GetThemeSysString', 'int32_t', ['intptr_t', 'int32_t', 'uint16_t *', 'int32_t']);
// GetThemeSysString(hTheme, iStringId, pszStringBuff, cchMaxStringChars)
// hTheme : HTHEME -> 'intptr_t'
// iStringId : INT -> 'int32_t'
// pszStringBuff : LPWSTR out -> 'uint16_t *'
// cchMaxStringChars : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("UXTHEME.dll", {
  GetThemeSysString: { parameters: ["isize", "i32", "buffer", "i32"], result: "i32" },
});
// lib.symbols.GetThemeSysString(hTheme, iStringId, pszStringBuff, cchMaxStringChars)
// hTheme : HTHEME -> "isize"
// iStringId : INT -> "i32"
// pszStringBuff : LPWSTR out -> "buffer"
// cchMaxStringChars : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetThemeSysString(
    intptr_t hTheme,
    int32_t iStringId,
    uint16_t* pszStringBuff,
    int32_t cchMaxStringChars);
C, "UXTHEME.dll");
// $ffi->GetThemeSysString(hTheme, iStringId, pszStringBuff, cchMaxStringChars);
// hTheme : HTHEME
// iStringId : INT
// pszStringBuff : LPWSTR out
// cchMaxStringChars : 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 GetThemeSysString(
        long hTheme,   // HTHEME
        int iStringId,   // INT
        char[] pszStringBuff,   // LPWSTR out
        int cchMaxStringChars   // INT
    );
}
@[Link("uxtheme")]
lib LibUXTHEME
  fun GetThemeSysString = GetThemeSysString(
    hTheme : LibC::SSizeT,   # HTHEME
    iStringId : Int32,   # INT
    pszStringBuff : UInt16*,   # LPWSTR out
    cchMaxStringChars : 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 GetThemeSysStringNative = Int32 Function(IntPtr, Int32, Pointer<Utf16>, Int32);
typedef GetThemeSysStringDart = int Function(int, int, Pointer<Utf16>, int);
final GetThemeSysString = DynamicLibrary.open('UXTHEME.dll')
    .lookupFunction<GetThemeSysStringNative, GetThemeSysStringDart>('GetThemeSysString');
// hTheme : HTHEME -> IntPtr
// iStringId : INT -> Int32
// pszStringBuff : LPWSTR out -> Pointer<Utf16>
// cchMaxStringChars : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetThemeSysString(
  hTheme: NativeInt;   // HTHEME
  iStringId: Integer;   // INT
  pszStringBuff: PWideChar;   // LPWSTR out
  cchMaxStringChars: Integer   // INT
): Integer; stdcall;
  external 'UXTHEME.dll' name 'GetThemeSysString';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let getthemesysstring =
  foreign "GetThemeSysString"
    (intptr_t @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* hTheme : HTHEME -> intptr_t *)
(* iStringId : INT -> int32_t *)
(* pszStringBuff : LPWSTR out -> (ptr uint16_t) *)
(* cchMaxStringChars : 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 ("GetThemeSysString" get-theme-sys-string :convention :stdcall) :int32
  (h-theme :int64)   ; HTHEME
  (i-string-id :int32)   ; INT
  (psz-string-buff :pointer)   ; LPWSTR out
  (cch-max-string-chars :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetThemeSysString = Win32::API::More->new('UXTHEME',
    'int GetThemeSysString(LPARAM hTheme, int iStringId, LPWSTR pszStringBuff, int cchMaxStringChars)');
# my $ret = $GetThemeSysString->Call($hTheme, $iStringId, $pszStringBuff, $cchMaxStringChars);
# hTheme : HTHEME -> LPARAM
# iStringId : INT -> int
# pszStringBuff : LPWSTR out -> LPWSTR
# cchMaxStringChars : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。