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

SetWindowLongPtrW

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

シグネチャ

// USER32.dll  (Unicode / -W)
#include <windows.h>

INT_PTR SetWindowLongPtrW(
    HWND hWnd,
    WINDOW_LONG_PTR_INDEX nIndex,
    INT_PTR dwNewLong
);

パラメーター

名前方向
hWndHWNDin
nIndexWINDOW_LONG_PTR_INDEXin
dwNewLongINT_PTRin

戻り値の型: INT_PTR

各言語での呼び出し定義

// USER32.dll  (Unicode / -W)
#include <windows.h>

INT_PTR SetWindowLongPtrW(
    HWND hWnd,
    WINDOW_LONG_PTR_INDEX nIndex,
    INT_PTR dwNewLong
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr SetWindowLongPtrW(
    IntPtr hWnd,   // HWND
    int nIndex,   // WINDOW_LONG_PTR_INDEX
    IntPtr dwNewLong   // INT_PTR
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetWindowLongPtrW(
    hWnd As IntPtr,   ' HWND
    nIndex As Integer,   ' WINDOW_LONG_PTR_INDEX
    dwNewLong As IntPtr   ' INT_PTR
) As IntPtr
End Function
' hWnd : HWND
' nIndex : WINDOW_LONG_PTR_INDEX
' dwNewLong : INT_PTR
Declare PtrSafe Function SetWindowLongPtrW Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As LongPtr) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetWindowLongPtrW = ctypes.windll.user32.SetWindowLongPtrW
SetWindowLongPtrW.restype = ctypes.c_ssize_t
SetWindowLongPtrW.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_int,  # nIndex : WINDOW_LONG_PTR_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')
SetWindowLongPtrW = Fiddle::Function.new(
  lib['SetWindowLongPtrW'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    Fiddle::TYPE_INT,  # nIndex : WINDOW_LONG_PTR_INDEX
    Fiddle::TYPE_INTPTR_T,  # dwNewLong : INT_PTR
  ],
  Fiddle::TYPE_INTPTR_T)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn SetWindowLongPtrW(
        hWnd: *mut core::ffi::c_void,  // HWND
        nIndex: i32,  // WINDOW_LONG_PTR_INDEX
        dwNewLong: isize  // INT_PTR
    ) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr SetWindowLongPtrW(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetWindowLongPtrW' -Namespace Win32 -PassThru
# $api::SetWindowLongPtrW(hWnd, nIndex, dwNewLong)
#uselib "USER32.dll"
#func global SetWindowLongPtrW "SetWindowLongPtrW" wptr, wptr, wptr
; SetWindowLongPtrW hWnd, nIndex, dwNewLong   ; 戻り値は stat
; hWnd : HWND -> "wptr"
; nIndex : WINDOW_LONG_PTR_INDEX -> "wptr"
; dwNewLong : INT_PTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global SetWindowLongPtrW "SetWindowLongPtrW" sptr, int, sptr
; res = SetWindowLongPtrW(hWnd, nIndex, dwNewLong)
; hWnd : HWND -> "sptr"
; nIndex : WINDOW_LONG_PTR_INDEX -> "int"
; dwNewLong : INT_PTR -> "sptr"
; INT_PTR SetWindowLongPtrW(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex, INT_PTR dwNewLong)
#uselib "USER32.dll"
#cfunc global SetWindowLongPtrW "SetWindowLongPtrW" intptr, int, intptr
; res = SetWindowLongPtrW(hWnd, nIndex, dwNewLong)
; hWnd : HWND -> "intptr"
; nIndex : WINDOW_LONG_PTR_INDEX -> "int"
; dwNewLong : INT_PTR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW")
)

// hWnd (HWND), nIndex (WINDOW_LONG_PTR_INDEX), dwNewLong (INT_PTR)
r1, _, err := procSetWindowLongPtrW.Call(
	uintptr(hWnd),
	uintptr(nIndex),
	uintptr(dwNewLong),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT_PTR
function SetWindowLongPtrW(
  hWnd: THandle;   // HWND
  nIndex: Integer;   // WINDOW_LONG_PTR_INDEX
  dwNewLong: NativeInt   // INT_PTR
): NativeInt; stdcall;
  external 'USER32.dll' name 'SetWindowLongPtrW';
result := DllCall("USER32\SetWindowLongPtrW"
    , "Ptr", hWnd   ; HWND
    , "Int", nIndex   ; WINDOW_LONG_PTR_INDEX
    , "Ptr", dwNewLong   ; INT_PTR
    , "Ptr")   ; return: INT_PTR
●SetWindowLongPtrW(hWnd, nIndex, dwNewLong) = DLL("USER32.dll", "int SetWindowLongPtrW(void*, int, int)")
# 呼び出し: SetWindowLongPtrW(hWnd, nIndex, dwNewLong)
# hWnd : HWND -> "void*"
# nIndex : WINDOW_LONG_PTR_INDEX -> "int"
# dwNewLong : INT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。