ホーム › UI.WindowsAndMessaging › SetWindowWord
SetWindowWord
関数ウィンドウの追加メモリにWORD値を設定する旧式関数。
シグネチャ
// USER32.dll
#include <windows.h>
WORD SetWindowWord(
HWND hWnd,
INT nIndex,
WORD wNewWord
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | 値を設定する対象ウィンドウのハンドル。 |
| nIndex | INT | in | 設定する追加ウィンドウメモリのバイトオフセット。 |
| wNewWord | WORD | in | 設定する新しいWORD値。 |
戻り値の型: 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 // WORDfunction 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)。const std = @import("std");
extern "user32" fn SetWindowWord(
hWnd: ?*anyopaque, // HWND
nIndex: i32, // INT
wNewWord: u16 // WORD
) callconv(std.os.windows.WINAPI) u16;proc SetWindowWord(
hWnd: pointer, # HWND
nIndex: int32, # INT
wNewWord: uint16 # WORD
): uint16 {.importc: "SetWindowWord", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
ushort SetWindowWord(
void* hWnd, // HWND
int nIndex, // INT
ushort wNewWord // WORD
);ccall((:SetWindowWord, "USER32.dll"), stdcall, UInt16,
(Ptr{Cvoid}, Int32, UInt16),
hWnd, nIndex, wNewWord)
# hWnd : HWND -> Ptr{Cvoid}
# nIndex : INT -> Int32
# wNewWord : WORD -> UInt16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint16_t SetWindowWord(
void* hWnd,
int32_t nIndex,
uint16_t wNewWord);
]]
local user32 = ffi.load("user32")
-- user32.SetWindowWord(hWnd, nIndex, wNewWord)
-- hWnd : HWND
-- nIndex : INT
-- wNewWord : WORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const SetWindowWord = lib.func('__stdcall', 'SetWindowWord', 'uint16_t', ['void *', 'int32_t', 'uint16_t']);
// SetWindowWord(hWnd, nIndex, wNewWord)
// hWnd : HWND -> 'void *'
// nIndex : INT -> 'int32_t'
// wNewWord : WORD -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
SetWindowWord: { parameters: ["pointer", "i32", "u16"], result: "u16" },
});
// lib.symbols.SetWindowWord(hWnd, nIndex, wNewWord)
// hWnd : HWND -> "pointer"
// nIndex : INT -> "i32"
// wNewWord : WORD -> "u16"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint16_t SetWindowWord(
void* hWnd,
int32_t nIndex,
uint16_t wNewWord);
C, "USER32.dll");
// $ffi->SetWindowWord(hWnd, nIndex, wNewWord);
// hWnd : HWND
// nIndex : INT
// wNewWord : WORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class);
short SetWindowWord(
Pointer hWnd, // HWND
int nIndex, // INT
short wNewWord // WORD
);
}@[Link("user32")]
lib LibUSER32
fun SetWindowWord = SetWindowWord(
hWnd : Void*, # HWND
nIndex : Int32, # INT
wNewWord : UInt16 # WORD
) : UInt16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetWindowWordNative = Uint16 Function(Pointer<Void>, Int32, Uint16);
typedef SetWindowWordDart = int Function(Pointer<Void>, int, int);
final SetWindowWord = DynamicLibrary.open('USER32.dll')
.lookupFunction<SetWindowWordNative, SetWindowWordDart>('SetWindowWord');
// hWnd : HWND -> Pointer<Void>
// nIndex : INT -> Int32
// wNewWord : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetWindowWord(
hWnd: THandle; // HWND
nIndex: Integer; // INT
wNewWord: Word // WORD
): Word; stdcall;
external 'USER32.dll' name 'SetWindowWord';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetWindowWord"
c_SetWindowWord :: Ptr () -> Int32 -> Word16 -> IO Word16
-- hWnd : HWND -> Ptr ()
-- nIndex : INT -> Int32
-- wNewWord : WORD -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setwindowword =
foreign "SetWindowWord"
((ptr void) @-> int32_t @-> uint16_t @-> returning uint16_t)
(* hWnd : HWND -> (ptr void) *)
(* nIndex : INT -> int32_t *)
(* wNewWord : WORD -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("SetWindowWord" set-window-word :convention :stdcall) :uint16
(h-wnd :pointer) ; HWND
(n-index :int32) ; INT
(w-new-word :uint16)) ; WORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetWindowWord = Win32::API::More->new('USER32',
'WORD SetWindowWord(HANDLE hWnd, int nIndex, WORD wNewWord)');
# my $ret = $SetWindowWord->Call($hWnd, $nIndex, $wNewWord);
# hWnd : HWND -> HANDLE
# nIndex : INT -> int
# wNewWord : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。