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

GetClassLongA

関数
ウィンドウクラスの属性値を取得する(ANSI版)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (ANSI / -A)
#include <windows.h>

DWORD GetClassLongA(
    HWND hWnd,
    GET_CLASS_LONG_INDEX nIndex
);

パラメーター

名前方向
hWndHWNDin
nIndexGET_CLASS_LONG_INDEXin

戻り値の型: DWORD

各言語での呼び出し定義

// USER32.dll  (ANSI / -A)
#include <windows.h>

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

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

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetClassLongA = user32.NewProc("GetClassLongA")
)

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