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

SetClassWord

関数
ウィンドウクラスの追加メモリにWORD値を設定する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

WORD SetClassWord(
    HWND hWnd,
    INT nIndex,
    WORD wNewWord
);

パラメーター

名前方向
hWndHWNDin
nIndexINTin
wNewWordWORDin

戻り値の型: WORD

各言語での呼び出し定義

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

WORD SetClassWord(
    HWND hWnd,
    INT nIndex,
    WORD wNewWord
);
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern ushort SetClassWord(
    IntPtr hWnd,   // HWND
    int nIndex,   // INT
    ushort wNewWord   // WORD
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetClassWord(
    hWnd As IntPtr,   ' HWND
    nIndex As Integer,   ' INT
    wNewWord As UShort   ' WORD
) As UShort
End Function
' hWnd : HWND
' nIndex : INT
' wNewWord : WORD
Declare PtrSafe Function SetClassWord Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal nIndex As Long, _
    ByVal wNewWord As Integer) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetClassWord = ctypes.windll.user32.SetClassWord
SetClassWord.restype = ctypes.c_ushort
SetClassWord.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_int,  # nIndex : INT
    ctypes.c_ushort,  # wNewWord : WORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
SetClassWord = Fiddle::Function.new(
  lib['SetClassWord'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    Fiddle::TYPE_INT,  # nIndex : INT
    -Fiddle::TYPE_SHORT,  # wNewWord : WORD
  ],
  -Fiddle::TYPE_SHORT)
#[link(name = "user32")]
extern "system" {
    fn SetClassWord(
        hWnd: *mut core::ffi::c_void,  // HWND
        nIndex: i32,  // INT
        wNewWord: u16  // WORD
    ) -> u16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", SetLastError = true)]
public static extern ushort SetClassWord(IntPtr hWnd, int nIndex, ushort wNewWord);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetClassWord' -Namespace Win32 -PassThru
# $api::SetClassWord(hWnd, nIndex, wNewWord)
#uselib "USER32.dll"
#func global SetClassWord "SetClassWord" sptr, sptr, sptr
; SetClassWord hWnd, nIndex, wNewWord   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; nIndex : INT -> "sptr"
; wNewWord : WORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global SetClassWord "SetClassWord" sptr, int, int
; res = SetClassWord(hWnd, nIndex, wNewWord)
; hWnd : HWND -> "sptr"
; nIndex : INT -> "int"
; wNewWord : WORD -> "int"
; WORD SetClassWord(HWND hWnd, INT nIndex, WORD wNewWord)
#uselib "USER32.dll"
#cfunc global SetClassWord "SetClassWord" intptr, int, int
; res = SetClassWord(hWnd, nIndex, wNewWord)
; hWnd : HWND -> "intptr"
; nIndex : INT -> "int"
; wNewWord : WORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSetClassWord = user32.NewProc("SetClassWord")
)

// hWnd (HWND), nIndex (INT), wNewWord (WORD)
r1, _, err := procSetClassWord.Call(
	uintptr(hWnd),
	uintptr(nIndex),
	uintptr(wNewWord),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WORD
function SetClassWord(
  hWnd: THandle;   // HWND
  nIndex: Integer;   // INT
  wNewWord: Word   // WORD
): Word; stdcall;
  external 'USER32.dll' name 'SetClassWord';
result := DllCall("USER32\SetClassWord"
    , "Ptr", hWnd   ; HWND
    , "Int", nIndex   ; INT
    , "UShort", wNewWord   ; WORD
    , "UShort")   ; return: WORD
●SetClassWord(hWnd, nIndex, wNewWord) = DLL("USER32.dll", "int SetClassWord(void*, int, int)")
# 呼び出し: SetClassWord(hWnd, nIndex, wNewWord)
# hWnd : HWND -> "void*"
# nIndex : INT -> "int"
# wNewWord : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。