GetWindowSubclass
関数ウィンドウのサブクラス参照データを取得する。
シグネチャ
// COMCTL32.dll
#include <windows.h>
BOOL GetWindowSubclass(
HWND hWnd,
SUBCLASSPROC pfnSubclass,
UINT_PTR uIdSubclass,
UINT_PTR* pdwRefData // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | サブクラス化されるウィンドウのハンドルです。 |
| pfnSubclass | SUBCLASSPROC | in | ウィンドウプロシージャへのポインターです。このポインターとサブクラス ID により、このサブクラスコールバックが一意に識別されます。 |
| uIdSubclass | UINT_PTR | in | UINT_PTR のサブクラス ID です。この ID とコールバックポインターにより、このサブクラスコールバックが一意に識別されます。注意: 64 ビット版の Windows では、これは 64 ビット値になります。 |
| pdwRefData | UINT_PTR* | outoptional | 参照データを返す DWORD へのポインターです。注意: 64 ビット版の Windows では、ポインターは 64 ビット値になります。 |
戻り値の型: BOOL
公式ドキュメント
指定したウィンドウサブクラスコールバックの参照データを取得します。
戻り値
型: BOOL
| 戻り値 | 説明 |
|---|---|
|
サブクラスコールバックが正常にインストールされました。 |
|
サブクラスコールバックがインストールされませんでした。 |
解説(Remarks)
GetWindowSubclass を使用するには、マニフェストで Comctl32.dll バージョン 6 を指定します。マニフェストの詳細については、Enabling Visual Styles を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// COMCTL32.dll
#include <windows.h>
BOOL GetWindowSubclass(
HWND hWnd,
SUBCLASSPROC pfnSubclass,
UINT_PTR uIdSubclass,
UINT_PTR* pdwRefData // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("COMCTL32.dll", ExactSpelling = true)]
static extern bool GetWindowSubclass(
IntPtr hWnd, // HWND
IntPtr pfnSubclass, // SUBCLASSPROC
UIntPtr uIdSubclass, // UINT_PTR
IntPtr pdwRefData // UINT_PTR* optional, out
);<DllImport("COMCTL32.dll", ExactSpelling:=True)>
Public Shared Function GetWindowSubclass(
hWnd As IntPtr, ' HWND
pfnSubclass As IntPtr, ' SUBCLASSPROC
uIdSubclass As UIntPtr, ' UINT_PTR
pdwRefData As IntPtr ' UINT_PTR* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hWnd : HWND
' pfnSubclass : SUBCLASSPROC
' uIdSubclass : UINT_PTR
' pdwRefData : UINT_PTR* optional, out
Declare PtrSafe Function GetWindowSubclass Lib "comctl32" ( _
ByVal hWnd As LongPtr, _
ByVal pfnSubclass As LongPtr, _
ByVal uIdSubclass As LongPtr, _
ByVal pdwRefData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetWindowSubclass = ctypes.windll.comctl32.GetWindowSubclass
GetWindowSubclass.restype = wintypes.BOOL
GetWindowSubclass.argtypes = [
wintypes.HANDLE, # hWnd : HWND
ctypes.c_void_p, # pfnSubclass : SUBCLASSPROC
ctypes.c_size_t, # uIdSubclass : UINT_PTR
ctypes.POINTER(ctypes.c_size_t), # pdwRefData : UINT_PTR* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('COMCTL32.dll')
GetWindowSubclass = Fiddle::Function.new(
lib['GetWindowSubclass'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
Fiddle::TYPE_VOIDP, # pfnSubclass : SUBCLASSPROC
Fiddle::TYPE_UINTPTR_T, # uIdSubclass : UINT_PTR
Fiddle::TYPE_VOIDP, # pdwRefData : UINT_PTR* optional, out
],
Fiddle::TYPE_INT)#[link(name = "comctl32")]
extern "system" {
fn GetWindowSubclass(
hWnd: *mut core::ffi::c_void, // HWND
pfnSubclass: *const core::ffi::c_void, // SUBCLASSPROC
uIdSubclass: usize, // UINT_PTR
pdwRefData: *mut usize // UINT_PTR* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("COMCTL32.dll")]
public static extern bool GetWindowSubclass(IntPtr hWnd, IntPtr pfnSubclass, UIntPtr uIdSubclass, IntPtr pdwRefData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMCTL32_GetWindowSubclass' -Namespace Win32 -PassThru
# $api::GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, pdwRefData)#uselib "COMCTL32.dll"
#func global GetWindowSubclass "GetWindowSubclass" sptr, sptr, sptr, sptr
; GetWindowSubclass hWnd, pfnSubclass, uIdSubclass, varptr(pdwRefData) ; 戻り値は stat
; hWnd : HWND -> "sptr"
; pfnSubclass : SUBCLASSPROC -> "sptr"
; uIdSubclass : UINT_PTR -> "sptr"
; pdwRefData : UINT_PTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "COMCTL32.dll" #cfunc global GetWindowSubclass "GetWindowSubclass" sptr, sptr, sptr, var ; res = GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, pdwRefData) ; hWnd : HWND -> "sptr" ; pfnSubclass : SUBCLASSPROC -> "sptr" ; uIdSubclass : UINT_PTR -> "sptr" ; pdwRefData : UINT_PTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "COMCTL32.dll" #cfunc global GetWindowSubclass "GetWindowSubclass" sptr, sptr, sptr, sptr ; res = GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, varptr(pdwRefData)) ; hWnd : HWND -> "sptr" ; pfnSubclass : SUBCLASSPROC -> "sptr" ; uIdSubclass : UINT_PTR -> "sptr" ; pdwRefData : UINT_PTR* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, UINT_PTR uIdSubclass, UINT_PTR* pdwRefData) #uselib "COMCTL32.dll" #cfunc global GetWindowSubclass "GetWindowSubclass" intptr, intptr, intptr, var ; res = GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, pdwRefData) ; hWnd : HWND -> "intptr" ; pfnSubclass : SUBCLASSPROC -> "intptr" ; uIdSubclass : UINT_PTR -> "intptr" ; pdwRefData : UINT_PTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, UINT_PTR uIdSubclass, UINT_PTR* pdwRefData) #uselib "COMCTL32.dll" #cfunc global GetWindowSubclass "GetWindowSubclass" intptr, intptr, intptr, intptr ; res = GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, varptr(pdwRefData)) ; hWnd : HWND -> "intptr" ; pfnSubclass : SUBCLASSPROC -> "intptr" ; uIdSubclass : UINT_PTR -> "intptr" ; pdwRefData : UINT_PTR* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
comctl32 = windows.NewLazySystemDLL("COMCTL32.dll")
procGetWindowSubclass = comctl32.NewProc("GetWindowSubclass")
)
// hWnd (HWND), pfnSubclass (SUBCLASSPROC), uIdSubclass (UINT_PTR), pdwRefData (UINT_PTR* optional, out)
r1, _, err := procGetWindowSubclass.Call(
uintptr(hWnd),
uintptr(pfnSubclass),
uintptr(uIdSubclass),
uintptr(pdwRefData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetWindowSubclass(
hWnd: THandle; // HWND
pfnSubclass: Pointer; // SUBCLASSPROC
uIdSubclass: NativeUInt; // UINT_PTR
pdwRefData: Pointer // UINT_PTR* optional, out
): BOOL; stdcall;
external 'COMCTL32.dll' name 'GetWindowSubclass';result := DllCall("COMCTL32\GetWindowSubclass"
, "Ptr", hWnd ; HWND
, "Ptr", pfnSubclass ; SUBCLASSPROC
, "UPtr", uIdSubclass ; UINT_PTR
, "Ptr", pdwRefData ; UINT_PTR* optional, out
, "Int") ; return: BOOL●GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, pdwRefData) = DLL("COMCTL32.dll", "bool GetWindowSubclass(void*, void*, int, void*)")
# 呼び出し: GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, pdwRefData)
# hWnd : HWND -> "void*"
# pfnSubclass : SUBCLASSPROC -> "void*"
# uIdSubclass : UINT_PTR -> "int"
# pdwRefData : UINT_PTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "comctl32" fn GetWindowSubclass(
hWnd: ?*anyopaque, // HWND
pfnSubclass: ?*anyopaque, // SUBCLASSPROC
uIdSubclass: usize, // UINT_PTR
pdwRefData: [*c]usize // UINT_PTR* optional, out
) callconv(std.os.windows.WINAPI) i32;proc GetWindowSubclass(
hWnd: pointer, # HWND
pfnSubclass: pointer, # SUBCLASSPROC
uIdSubclass: uint, # UINT_PTR
pdwRefData: ptr uint # UINT_PTR* optional, out
): int32 {.importc: "GetWindowSubclass", stdcall, dynlib: "COMCTL32.dll".}pragma(lib, "comctl32");
extern(Windows)
int GetWindowSubclass(
void* hWnd, // HWND
void* pfnSubclass, // SUBCLASSPROC
size_t uIdSubclass, // UINT_PTR
size_t* pdwRefData // UINT_PTR* optional, out
);ccall((:GetWindowSubclass, "COMCTL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Csize_t, Ptr{Csize_t}),
hWnd, pfnSubclass, uIdSubclass, pdwRefData)
# hWnd : HWND -> Ptr{Cvoid}
# pfnSubclass : SUBCLASSPROC -> Ptr{Cvoid}
# uIdSubclass : UINT_PTR -> Csize_t
# pdwRefData : UINT_PTR* optional, out -> Ptr{Csize_t}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetWindowSubclass(
void* hWnd,
void* pfnSubclass,
uintptr_t uIdSubclass,
uintptr_t* pdwRefData);
]]
local comctl32 = ffi.load("comctl32")
-- comctl32.GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, pdwRefData)
-- hWnd : HWND
-- pfnSubclass : SUBCLASSPROC
-- uIdSubclass : UINT_PTR
-- pdwRefData : UINT_PTR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('COMCTL32.dll');
const GetWindowSubclass = lib.func('__stdcall', 'GetWindowSubclass', 'int32_t', ['void *', 'void *', 'uintptr_t', 'uintptr_t *']);
// GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, pdwRefData)
// hWnd : HWND -> 'void *'
// pfnSubclass : SUBCLASSPROC -> 'void *'
// uIdSubclass : UINT_PTR -> 'uintptr_t'
// pdwRefData : UINT_PTR* optional, out -> 'uintptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("COMCTL32.dll", {
GetWindowSubclass: { parameters: ["pointer", "pointer", "usize", "pointer"], result: "i32" },
});
// lib.symbols.GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, pdwRefData)
// hWnd : HWND -> "pointer"
// pfnSubclass : SUBCLASSPROC -> "pointer"
// uIdSubclass : UINT_PTR -> "usize"
// pdwRefData : UINT_PTR* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetWindowSubclass(
void* hWnd,
void* pfnSubclass,
size_t uIdSubclass,
size_t* pdwRefData);
C, "COMCTL32.dll");
// $ffi->GetWindowSubclass(hWnd, pfnSubclass, uIdSubclass, pdwRefData);
// hWnd : HWND
// pfnSubclass : SUBCLASSPROC
// uIdSubclass : UINT_PTR
// pdwRefData : UINT_PTR* optional, out
// 構造体/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 Comctl32 extends StdCallLibrary {
Comctl32 INSTANCE = Native.load("comctl32", Comctl32.class);
boolean GetWindowSubclass(
Pointer hWnd, // HWND
Callback pfnSubclass, // SUBCLASSPROC
long uIdSubclass, // UINT_PTR
LongByReference pdwRefData // UINT_PTR* optional, out
);
}@[Link("comctl32")]
lib LibCOMCTL32
fun GetWindowSubclass = GetWindowSubclass(
hWnd : Void*, # HWND
pfnSubclass : Void*, # SUBCLASSPROC
uIdSubclass : LibC::SizeT, # UINT_PTR
pdwRefData : LibC::SizeT* # UINT_PTR* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetWindowSubclassNative = Int32 Function(Pointer<Void>, Pointer<Void>, UintPtr, Pointer<UintPtr>);
typedef GetWindowSubclassDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<UintPtr>);
final GetWindowSubclass = DynamicLibrary.open('COMCTL32.dll')
.lookupFunction<GetWindowSubclassNative, GetWindowSubclassDart>('GetWindowSubclass');
// hWnd : HWND -> Pointer<Void>
// pfnSubclass : SUBCLASSPROC -> Pointer<Void>
// uIdSubclass : UINT_PTR -> UintPtr
// pdwRefData : UINT_PTR* optional, out -> Pointer<UintPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetWindowSubclass(
hWnd: THandle; // HWND
pfnSubclass: Pointer; // SUBCLASSPROC
uIdSubclass: NativeUInt; // UINT_PTR
pdwRefData: Pointer // UINT_PTR* optional, out
): BOOL; stdcall;
external 'COMCTL32.dll' name 'GetWindowSubclass';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetWindowSubclass"
c_GetWindowSubclass :: Ptr () -> Ptr () -> CUIntPtr -> Ptr CUIntPtr -> IO CInt
-- hWnd : HWND -> Ptr ()
-- pfnSubclass : SUBCLASSPROC -> Ptr ()
-- uIdSubclass : UINT_PTR -> CUIntPtr
-- pdwRefData : UINT_PTR* optional, out -> Ptr CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getwindowsubclass =
foreign "GetWindowSubclass"
((ptr void) @-> (ptr void) @-> size_t @-> (ptr size_t) @-> returning int32_t)
(* hWnd : HWND -> (ptr void) *)
(* pfnSubclass : SUBCLASSPROC -> (ptr void) *)
(* uIdSubclass : UINT_PTR -> size_t *)
(* pdwRefData : UINT_PTR* optional, out -> (ptr size_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library comctl32 (t "COMCTL32.dll"))
(cffi:use-foreign-library comctl32)
(cffi:defcfun ("GetWindowSubclass" get-window-subclass :convention :stdcall) :int32
(h-wnd :pointer) ; HWND
(pfn-subclass :pointer) ; SUBCLASSPROC
(u-id-subclass :uint64) ; UINT_PTR
(pdw-ref-data :pointer)) ; UINT_PTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetWindowSubclass = Win32::API::More->new('COMCTL32',
'BOOL GetWindowSubclass(HANDLE hWnd, LPVOID pfnSubclass, WPARAM uIdSubclass, LPVOID pdwRefData)');
# my $ret = $GetWindowSubclass->Call($hWnd, $pfnSubclass, $uIdSubclass, $pdwRefData);
# hWnd : HWND -> HANDLE
# pfnSubclass : SUBCLASSPROC -> LPVOID
# uIdSubclass : UINT_PTR -> WPARAM
# pdwRefData : UINT_PTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。関連項目
公式の関連項目
- f DefSubclassProc — サブクラスチェーンの次の処理へメッセージを渡す。
- f RemoveWindowSubclass — ウィンドウからサブクラスプロシージャを削除する。
- f SetWindowSubclass — ウィンドウにサブクラスプロシージャを設定する。
使用する型