ホーム › UI.WindowsAndMessaging › SetClassWord
SetClassWord
関数ウィンドウクラスの追加メモリにWORD値を設定する。
シグネチャ
// USER32.dll
#include <windows.h>
WORD SetClassWord(
HWND hWnd,
INT nIndex,
WORD wNewWord
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | ウィンドウへのハンドル。間接的に、そのウィンドウが属するクラスを示します。 |
| nIndex | INT | in | 置き換える値のゼロベースのバイトオフセット。有効な値の範囲は、ゼロからクラスメモリのバイト数マイナス 2 までです。たとえば、追加クラスメモリを 10 バイト以上指定した場合、値 8 は 5 番目の 16 ビット整数へのインデックスになります。 |
| wNewWord | WORD | in | 置き換え後の値。 |
戻り値の型: WORD
公式ドキュメント
指定したウィンドウが属するウィンドウクラスの追加クラスメモリ内の、指定したオフセット位置にある 16 ビット (WORD) 値を置き換えます。
戻り値
Type: WORD
関数が成功した場合、戻り値は指定した 16 ビット整数の以前の値です。値が以前に設定されていなかった場合、戻り値はゼロです。
関数が失敗した場合、戻り値はゼロです。拡張エラー情報を取得するには、GetLastError を呼び出します。
解説(Remarks)
追加クラスメモリを予約するには、RegisterClass 関数で使用する WNDCLASS 構造体の cbClsExtra メンバーにゼロ以外の値を指定します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
WORD SetClassWord(
HWND hWnd,
INT nIndex,
WORD wNewWord
);[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern ushort SetClassWord(
IntPtr hWnd, // HWND
int nIndex, // INT
ushort wNewWord // WORD
);<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetClassWord(
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 SetClassWord 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
SetClassWord = ctypes.windll.user32.SetClassWord
SetClassWord.restype = ctypes.c_ushort
SetClassWord.argtypes = [
wintypes.HANDLE, # hWnd : HWND
ctypes.c_int, # nIndex : INT
ctypes.c_ushort, # wNewWord : WORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
SetClassWord = Fiddle::Function.new(
lib['SetClassWord'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
Fiddle::TYPE_INT, # nIndex : INT
-Fiddle::TYPE_SHORT, # wNewWord : WORD
],
-Fiddle::TYPE_SHORT)#[link(name = "user32")]
extern "system" {
fn SetClassWord(
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", SetLastError = true)]
public static extern ushort SetClassWord(IntPtr hWnd, int nIndex, ushort wNewWord);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetClassWord' -Namespace Win32 -PassThru
# $api::SetClassWord(hWnd, nIndex, wNewWord)#uselib "USER32.dll"
#func global SetClassWord "SetClassWord" sptr, sptr, sptr
; SetClassWord hWnd, nIndex, wNewWord ; 戻り値は stat
; hWnd : HWND -> "sptr"
; nIndex : INT -> "sptr"
; wNewWord : WORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global SetClassWord "SetClassWord" sptr, int, int
; res = SetClassWord(hWnd, nIndex, wNewWord)
; hWnd : HWND -> "sptr"
; nIndex : INT -> "int"
; wNewWord : WORD -> "int"; WORD SetClassWord(HWND hWnd, INT nIndex, WORD wNewWord)
#uselib "USER32.dll"
#cfunc global SetClassWord "SetClassWord" intptr, int, int
; res = SetClassWord(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")
procSetClassWord = user32.NewProc("SetClassWord")
)
// hWnd (HWND), nIndex (INT), wNewWord (WORD)
r1, _, err := procSetClassWord.Call(
uintptr(hWnd),
uintptr(nIndex),
uintptr(wNewWord),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WORDfunction SetClassWord(
hWnd: THandle; // HWND
nIndex: Integer; // INT
wNewWord: Word // WORD
): Word; stdcall;
external 'USER32.dll' name 'SetClassWord';result := DllCall("USER32\SetClassWord"
, "Ptr", hWnd ; HWND
, "Int", nIndex ; INT
, "UShort", wNewWord ; WORD
, "UShort") ; return: WORD●SetClassWord(hWnd, nIndex, wNewWord) = DLL("USER32.dll", "int SetClassWord(void*, int, int)")
# 呼び出し: SetClassWord(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 SetClassWord(
hWnd: ?*anyopaque, // HWND
nIndex: i32, // INT
wNewWord: u16 // WORD
) callconv(std.os.windows.WINAPI) u16;proc SetClassWord(
hWnd: pointer, # HWND
nIndex: int32, # INT
wNewWord: uint16 # WORD
): uint16 {.importc: "SetClassWord", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
ushort SetClassWord(
void* hWnd, // HWND
int nIndex, // INT
ushort wNewWord // WORD
);ccall((:SetClassWord, "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 SetClassWord(
void* hWnd,
int32_t nIndex,
uint16_t wNewWord);
]]
local user32 = ffi.load("user32")
-- user32.SetClassWord(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 SetClassWord = lib.func('__stdcall', 'SetClassWord', 'uint16_t', ['void *', 'int32_t', 'uint16_t']);
// SetClassWord(hWnd, nIndex, wNewWord)
// hWnd : HWND -> 'void *'
// nIndex : INT -> 'int32_t'
// wNewWord : WORD -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
SetClassWord: { parameters: ["pointer", "i32", "u16"], result: "u16" },
});
// lib.symbols.SetClassWord(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 SetClassWord(
void* hWnd,
int32_t nIndex,
uint16_t wNewWord);
C, "USER32.dll");
// $ffi->SetClassWord(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 SetClassWord(
Pointer hWnd, // HWND
int nIndex, // INT
short wNewWord // WORD
);
}@[Link("user32")]
lib LibUSER32
fun SetClassWord = SetClassWord(
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 SetClassWordNative = Uint16 Function(Pointer<Void>, Int32, Uint16);
typedef SetClassWordDart = int Function(Pointer<Void>, int, int);
final SetClassWord = DynamicLibrary.open('USER32.dll')
.lookupFunction<SetClassWordNative, SetClassWordDart>('SetClassWord');
// hWnd : HWND -> Pointer<Void>
// nIndex : INT -> Int32
// wNewWord : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetClassWord(
hWnd: THandle; // HWND
nIndex: Integer; // INT
wNewWord: Word // WORD
): Word; stdcall;
external 'USER32.dll' name 'SetClassWord';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetClassWord"
c_SetClassWord :: 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 setclassword =
foreign "SetClassWord"
((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 ("SetClassWord" set-class-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 $SetClassWord = Win32::API::More->new('USER32',
'WORD SetClassWord(HANDLE hWnd, int nIndex, WORD wNewWord)');
# my $ret = $SetClassWord->Call($hWnd, $nIndex, $wNewWord);
# hWnd : HWND -> HANDLE
# nIndex : INT -> int
# wNewWord : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetClassWord — ウィンドウクラスの追加メモリからWORD値を取得する。
- f RegisterClassW — ウィンドウクラスを登録する(Unicode)。
- f SetClassLongW — ウィンドウクラスの属性値を設定する(Unicode版)。
- s WNDCLASSW