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

RegisterScaleChangeNotifications

関数
スケール変更通知の受信を登録する。
DLLapi-ms-win-shcore-scaling-l1-1-0.dll呼出規約winapi対応OSwindows8.0

シグネチャ

// api-ms-win-shcore-scaling-l1-1-0.dll
#include <windows.h>

HRESULT RegisterScaleChangeNotifications(
    DISPLAY_DEVICE_TYPE displayDevice,
    HWND hwndNotify,
    DWORD uMsgNotify,
    DWORD* pdwCookie
);

パラメーター

名前方向説明
displayDeviceDISPLAY_DEVICE_TYPEin通知を受け取る対象のディスプレイデバイスを示す列挙値です。
hwndNotifyHWNDin通知を受け取るウィンドウのハンドルです。
uMsgNotifyDWORDinスケーリング情報が変化したときに、hwndNotify で指定されたウィンドウに渡される、アプリケーション定義のメッセージです。通常は WM_APP+x(x は整数値)に設定します。
pdwCookieDWORD*outこの関数が成功した場合に登録トークンを受け取る値へのポインターです。このトークンは、RevokeScaleChangeNotifications を呼び出して通知を取り消す際に使用します。

戻り値の型: HRESULT

公式ドキュメント

スケーリング情報が変化したときにコールバックを受け取るウィンドウを登録します。

戻り値

型: STDAPI

この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。

解説(Remarks)

uMsgNotify で指定されたメッセージは、PostMessage を通じて登録済みのウィンドウにポストされます。メッセージの wParam には、発生した変化を示す SCALE_CHANGE_FLAGS の組み合わせを含めることができます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// api-ms-win-shcore-scaling-l1-1-0.dll
#include <windows.h>

HRESULT RegisterScaleChangeNotifications(
    DISPLAY_DEVICE_TYPE displayDevice,
    HWND hwndNotify,
    DWORD uMsgNotify,
    DWORD* pdwCookie
);
[DllImport("api-ms-win-shcore-scaling-l1-1-0.dll", ExactSpelling = true)]
static extern int RegisterScaleChangeNotifications(
    int displayDevice,   // DISPLAY_DEVICE_TYPE
    IntPtr hwndNotify,   // HWND
    uint uMsgNotify,   // DWORD
    out uint pdwCookie   // DWORD* out
);
<DllImport("api-ms-win-shcore-scaling-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function RegisterScaleChangeNotifications(
    displayDevice As Integer,   ' DISPLAY_DEVICE_TYPE
    hwndNotify As IntPtr,   ' HWND
    uMsgNotify As UInteger,   ' DWORD
    <Out> ByRef pdwCookie As UInteger   ' DWORD* out
) As Integer
End Function
' displayDevice : DISPLAY_DEVICE_TYPE
' hwndNotify : HWND
' uMsgNotify : DWORD
' pdwCookie : DWORD* out
Declare PtrSafe Function RegisterScaleChangeNotifications Lib "api-ms-win-shcore-scaling-l1-1-0" ( _
    ByVal displayDevice As Long, _
    ByVal hwndNotify As LongPtr, _
    ByVal uMsgNotify As Long, _
    ByRef pdwCookie As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegisterScaleChangeNotifications = ctypes.windll.LoadLibrary("api-ms-win-shcore-scaling-l1-1-0.dll").RegisterScaleChangeNotifications
RegisterScaleChangeNotifications.restype = ctypes.c_int
RegisterScaleChangeNotifications.argtypes = [
    ctypes.c_int,  # displayDevice : DISPLAY_DEVICE_TYPE
    wintypes.HANDLE,  # hwndNotify : HWND
    wintypes.DWORD,  # uMsgNotify : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pdwCookie : DWORD* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-shcore-scaling-l1-1-0.dll')
RegisterScaleChangeNotifications = Fiddle::Function.new(
  lib['RegisterScaleChangeNotifications'],
  [
    Fiddle::TYPE_INT,  # displayDevice : DISPLAY_DEVICE_TYPE
    Fiddle::TYPE_VOIDP,  # hwndNotify : HWND
    -Fiddle::TYPE_INT,  # uMsgNotify : DWORD
    Fiddle::TYPE_VOIDP,  # pdwCookie : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-shcore-scaling-l1-1-0")]
extern "system" {
    fn RegisterScaleChangeNotifications(
        displayDevice: i32,  // DISPLAY_DEVICE_TYPE
        hwndNotify: *mut core::ffi::c_void,  // HWND
        uMsgNotify: u32,  // DWORD
        pdwCookie: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-shcore-scaling-l1-1-0.dll")]
public static extern int RegisterScaleChangeNotifications(int displayDevice, IntPtr hwndNotify, uint uMsgNotify, out uint pdwCookie);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-shcore-scaling-l1-1-0_RegisterScaleChangeNotifications' -Namespace Win32 -PassThru
# $api::RegisterScaleChangeNotifications(displayDevice, hwndNotify, uMsgNotify, pdwCookie)
#uselib "api-ms-win-shcore-scaling-l1-1-0.dll"
#func global RegisterScaleChangeNotifications "RegisterScaleChangeNotifications" sptr, sptr, sptr, sptr
; RegisterScaleChangeNotifications displayDevice, hwndNotify, uMsgNotify, varptr(pdwCookie)   ; 戻り値は stat
; displayDevice : DISPLAY_DEVICE_TYPE -> "sptr"
; hwndNotify : HWND -> "sptr"
; uMsgNotify : DWORD -> "sptr"
; pdwCookie : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-shcore-scaling-l1-1-0.dll"
#cfunc global RegisterScaleChangeNotifications "RegisterScaleChangeNotifications" int, sptr, int, var
; res = RegisterScaleChangeNotifications(displayDevice, hwndNotify, uMsgNotify, pdwCookie)
; displayDevice : DISPLAY_DEVICE_TYPE -> "int"
; hwndNotify : HWND -> "sptr"
; uMsgNotify : DWORD -> "int"
; pdwCookie : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT RegisterScaleChangeNotifications(DISPLAY_DEVICE_TYPE displayDevice, HWND hwndNotify, DWORD uMsgNotify, DWORD* pdwCookie)
#uselib "api-ms-win-shcore-scaling-l1-1-0.dll"
#cfunc global RegisterScaleChangeNotifications "RegisterScaleChangeNotifications" int, intptr, int, var
; res = RegisterScaleChangeNotifications(displayDevice, hwndNotify, uMsgNotify, pdwCookie)
; displayDevice : DISPLAY_DEVICE_TYPE -> "int"
; hwndNotify : HWND -> "intptr"
; uMsgNotify : DWORD -> "int"
; pdwCookie : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_shcore_scaling_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-shcore-scaling-l1-1-0.dll")
	procRegisterScaleChangeNotifications = api_ms_win_shcore_scaling_l1_1_0.NewProc("RegisterScaleChangeNotifications")
)

// displayDevice (DISPLAY_DEVICE_TYPE), hwndNotify (HWND), uMsgNotify (DWORD), pdwCookie (DWORD* out)
r1, _, err := procRegisterScaleChangeNotifications.Call(
	uintptr(displayDevice),
	uintptr(hwndNotify),
	uintptr(uMsgNotify),
	uintptr(pdwCookie),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function RegisterScaleChangeNotifications(
  displayDevice: Integer;   // DISPLAY_DEVICE_TYPE
  hwndNotify: THandle;   // HWND
  uMsgNotify: DWORD;   // DWORD
  pdwCookie: Pointer   // DWORD* out
): Integer; stdcall;
  external 'api-ms-win-shcore-scaling-l1-1-0.dll' name 'RegisterScaleChangeNotifications';
result := DllCall("api-ms-win-shcore-scaling-l1-1-0\RegisterScaleChangeNotifications"
    , "Int", displayDevice   ; DISPLAY_DEVICE_TYPE
    , "Ptr", hwndNotify   ; HWND
    , "UInt", uMsgNotify   ; DWORD
    , "Ptr", pdwCookie   ; DWORD* out
    , "Int")   ; return: HRESULT
●RegisterScaleChangeNotifications(displayDevice, hwndNotify, uMsgNotify, pdwCookie) = DLL("api-ms-win-shcore-scaling-l1-1-0.dll", "int RegisterScaleChangeNotifications(int, void*, dword, void*)")
# 呼び出し: RegisterScaleChangeNotifications(displayDevice, hwndNotify, uMsgNotify, pdwCookie)
# displayDevice : DISPLAY_DEVICE_TYPE -> "int"
# hwndNotify : HWND -> "void*"
# uMsgNotify : DWORD -> "dword"
# pdwCookie : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "api-ms-win-shcore-scaling-l1-1-0" fn RegisterScaleChangeNotifications(
    displayDevice: i32, // DISPLAY_DEVICE_TYPE
    hwndNotify: ?*anyopaque, // HWND
    uMsgNotify: u32, // DWORD
    pdwCookie: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) i32;
proc RegisterScaleChangeNotifications(
    displayDevice: int32,  # DISPLAY_DEVICE_TYPE
    hwndNotify: pointer,  # HWND
    uMsgNotify: uint32,  # DWORD
    pdwCookie: ptr uint32  # DWORD* out
): int32 {.importc: "RegisterScaleChangeNotifications", stdcall, dynlib: "api-ms-win-shcore-scaling-l1-1-0.dll".}
pragma(lib, "api-ms-win-shcore-scaling-l1-1-0");
extern(Windows)
int RegisterScaleChangeNotifications(
    int displayDevice,   // DISPLAY_DEVICE_TYPE
    void* hwndNotify,   // HWND
    uint uMsgNotify,   // DWORD
    uint* pdwCookie   // DWORD* out
);
ccall((:RegisterScaleChangeNotifications, "api-ms-win-shcore-scaling-l1-1-0.dll"), stdcall, Int32,
      (Int32, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
      displayDevice, hwndNotify, uMsgNotify, pdwCookie)
# displayDevice : DISPLAY_DEVICE_TYPE -> Int32
# hwndNotify : HWND -> Ptr{Cvoid}
# uMsgNotify : DWORD -> UInt32
# pdwCookie : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t RegisterScaleChangeNotifications(
    int32_t displayDevice,
    void* hwndNotify,
    uint32_t uMsgNotify,
    uint32_t* pdwCookie);
]]
local api-ms-win-shcore-scaling-l1-1-0 = ffi.load("api-ms-win-shcore-scaling-l1-1-0")
-- api-ms-win-shcore-scaling-l1-1-0.RegisterScaleChangeNotifications(displayDevice, hwndNotify, uMsgNotify, pdwCookie)
-- displayDevice : DISPLAY_DEVICE_TYPE
-- hwndNotify : HWND
-- uMsgNotify : DWORD
-- pdwCookie : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('api-ms-win-shcore-scaling-l1-1-0.dll');
const RegisterScaleChangeNotifications = lib.func('__stdcall', 'RegisterScaleChangeNotifications', 'int32_t', ['int32_t', 'void *', 'uint32_t', 'uint32_t *']);
// RegisterScaleChangeNotifications(displayDevice, hwndNotify, uMsgNotify, pdwCookie)
// displayDevice : DISPLAY_DEVICE_TYPE -> 'int32_t'
// hwndNotify : HWND -> 'void *'
// uMsgNotify : DWORD -> 'uint32_t'
// pdwCookie : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("api-ms-win-shcore-scaling-l1-1-0.dll", {
  RegisterScaleChangeNotifications: { parameters: ["i32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.RegisterScaleChangeNotifications(displayDevice, hwndNotify, uMsgNotify, pdwCookie)
// displayDevice : DISPLAY_DEVICE_TYPE -> "i32"
// hwndNotify : HWND -> "pointer"
// uMsgNotify : DWORD -> "u32"
// pdwCookie : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t RegisterScaleChangeNotifications(
    int32_t displayDevice,
    void* hwndNotify,
    uint32_t uMsgNotify,
    uint32_t* pdwCookie);
C, "api-ms-win-shcore-scaling-l1-1-0.dll");
// $ffi->RegisterScaleChangeNotifications(displayDevice, hwndNotify, uMsgNotify, pdwCookie);
// displayDevice : DISPLAY_DEVICE_TYPE
// hwndNotify : HWND
// uMsgNotify : DWORD
// pdwCookie : DWORD* 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 Api-ms-win-shcore-scaling-l1-1-0 extends StdCallLibrary {
    Api-ms-win-shcore-scaling-l1-1-0 INSTANCE = Native.load("api-ms-win-shcore-scaling-l1-1-0", Api-ms-win-shcore-scaling-l1-1-0.class);
    int RegisterScaleChangeNotifications(
        int displayDevice,   // DISPLAY_DEVICE_TYPE
        Pointer hwndNotify,   // HWND
        int uMsgNotify,   // DWORD
        IntByReference pdwCookie   // DWORD* out
    );
}
@[Link("api-ms-win-shcore-scaling-l1-1-0")]
lib Libapi-ms-win-shcore-scaling-l1-1-0
  fun RegisterScaleChangeNotifications = RegisterScaleChangeNotifications(
    displayDevice : Int32,   # DISPLAY_DEVICE_TYPE
    hwndNotify : Void*,   # HWND
    uMsgNotify : UInt32,   # DWORD
    pdwCookie : UInt32*   # DWORD* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RegisterScaleChangeNotificationsNative = Int32 Function(Int32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef RegisterScaleChangeNotificationsDart = int Function(int, Pointer<Void>, int, Pointer<Uint32>);
final RegisterScaleChangeNotifications = DynamicLibrary.open('api-ms-win-shcore-scaling-l1-1-0.dll')
    .lookupFunction<RegisterScaleChangeNotificationsNative, RegisterScaleChangeNotificationsDart>('RegisterScaleChangeNotifications');
// displayDevice : DISPLAY_DEVICE_TYPE -> Int32
// hwndNotify : HWND -> Pointer<Void>
// uMsgNotify : DWORD -> Uint32
// pdwCookie : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RegisterScaleChangeNotifications(
  displayDevice: Integer;   // DISPLAY_DEVICE_TYPE
  hwndNotify: THandle;   // HWND
  uMsgNotify: DWORD;   // DWORD
  pdwCookie: Pointer   // DWORD* out
): Integer; stdcall;
  external 'api-ms-win-shcore-scaling-l1-1-0.dll' name 'RegisterScaleChangeNotifications';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RegisterScaleChangeNotifications"
  c_RegisterScaleChangeNotifications :: Int32 -> Ptr () -> Word32 -> Ptr Word32 -> IO Int32
-- displayDevice : DISPLAY_DEVICE_TYPE -> Int32
-- hwndNotify : HWND -> Ptr ()
-- uMsgNotify : DWORD -> Word32
-- pdwCookie : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let registerscalechangenotifications =
  foreign "RegisterScaleChangeNotifications"
    (int32_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* displayDevice : DISPLAY_DEVICE_TYPE -> int32_t *)
(* hwndNotify : HWND -> (ptr void) *)
(* uMsgNotify : DWORD -> uint32_t *)
(* pdwCookie : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library api-ms-win-shcore-scaling-l1-1-0 (t "api-ms-win-shcore-scaling-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-shcore-scaling-l1-1-0)

(cffi:defcfun ("RegisterScaleChangeNotifications" register-scale-change-notifications :convention :stdcall) :int32
  (display-device :int32)   ; DISPLAY_DEVICE_TYPE
  (hwnd-notify :pointer)   ; HWND
  (u-msg-notify :uint32)   ; DWORD
  (pdw-cookie :pointer))   ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RegisterScaleChangeNotifications = Win32::API::More->new('api-ms-win-shcore-scaling-l1-1-0',
    'int RegisterScaleChangeNotifications(int displayDevice, HANDLE hwndNotify, DWORD uMsgNotify, LPVOID pdwCookie)');
# my $ret = $RegisterScaleChangeNotifications->Call($displayDevice, $hwndNotify, $uMsgNotify, $pdwCookie);
# displayDevice : DISPLAY_DEVICE_TYPE -> int
# hwndNotify : HWND -> HANDLE
# uMsgNotify : DWORD -> DWORD
# pdwCookie : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型