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

GetClassWord

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

シグネチャ

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

WORD GetClassWord(
    HWND hWnd,
    INT nIndex
);

パラメーター

名前方向
hWndHWNDin
nIndexINTin

戻り値の型: WORD

各言語での呼び出し定義

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

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

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

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetClassWord = user32.NewProc("GetClassWord")
)

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