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

SetClassLongPtrA

関数
ウィンドウクラスの情報をポインタ幅で設定する(ANSI)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

UINT_PTR SetClassLongPtrA(
    HWND hWnd,
    GET_CLASS_LONG_INDEX nIndex,
    INT_PTR dwNewLong
);

パラメーター

名前方向
hWndHWNDin
nIndexGET_CLASS_LONG_INDEXin
dwNewLongINT_PTRin

戻り値の型: UINT_PTR

各言語での呼び出し定義

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

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

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

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSetClassLongPtrA = user32.NewProc("SetClassLongPtrA")
)

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