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

SetWindowWord

関数
ウィンドウの追加メモリにWORD値を設定する旧式関数。
DLLUSER32.dll呼出規約winapi

シグネチャ

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

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

パラメーター

名前方向
hWndHWNDin
nIndexINTin
wNewWordWORDin

戻り値の型: WORD

各言語での呼び出し定義

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

WORD SetWindowWord(
    HWND hWnd,
    INT nIndex,
    WORD wNewWord
);
[DllImport("USER32.dll", ExactSpelling = true)]
static extern ushort SetWindowWord(
    IntPtr hWnd,   // HWND
    int nIndex,   // INT
    ushort wNewWord   // WORD
);
<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function SetWindowWord(
    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 SetWindowWord 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

SetWindowWord = ctypes.windll.user32.SetWindowWord
SetWindowWord.restype = ctypes.c_ushort
SetWindowWord.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_int,  # nIndex : INT
    ctypes.c_ushort,  # wNewWord : WORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
SetWindowWord = Fiddle::Function.new(
  lib['SetWindowWord'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    Fiddle::TYPE_INT,  # nIndex : INT
    -Fiddle::TYPE_SHORT,  # wNewWord : WORD
  ],
  -Fiddle::TYPE_SHORT)
#[link(name = "user32")]
extern "system" {
    fn SetWindowWord(
        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")]
public static extern ushort SetWindowWord(IntPtr hWnd, int nIndex, ushort wNewWord);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetWindowWord' -Namespace Win32 -PassThru
# $api::SetWindowWord(hWnd, nIndex, wNewWord)
#uselib "USER32.dll"
#func global SetWindowWord "SetWindowWord" sptr, sptr, sptr
; SetWindowWord hWnd, nIndex, wNewWord   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; nIndex : INT -> "sptr"
; wNewWord : WORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global SetWindowWord "SetWindowWord" sptr, int, int
; res = SetWindowWord(hWnd, nIndex, wNewWord)
; hWnd : HWND -> "sptr"
; nIndex : INT -> "int"
; wNewWord : WORD -> "int"
; WORD SetWindowWord(HWND hWnd, INT nIndex, WORD wNewWord)
#uselib "USER32.dll"
#cfunc global SetWindowWord "SetWindowWord" intptr, int, int
; res = SetWindowWord(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")
	procSetWindowWord = user32.NewProc("SetWindowWord")
)

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