ホーム › System.Power › RegisterSuspendResumeNotification
RegisterSuspendResumeNotification
関数サスペンド・再開の電源通知を受け取るよう登録する。
シグネチャ
// USER32.dll
#include <windows.h>
HPOWERNOTIFY RegisterSuspendResumeNotification(
HANDLE hRecipient,
REGISTER_NOTIFICATION_FLAGS Flags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hRecipient | HANDLE | in | このパラメーターには、電源通知を購読するためのパラメーター、または購読するプロセスを表すウィンドウハンドルが含まれます。 Flags が DEVICE_NOTIFY_CALLBACK の場合、hRecipient は DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS 構造体へのポインターとして解釈されます。この場合、コールバック関数は DeviceNotifyCallbackRoutine です。Callback 関数が実行されるとき、Type パラメーターには発生したイベントの種類を示す値が設定されます。設定され得る値には PBT_APMSUSPEND、PBT_APMRESUMESUSPEND、PBT_APMRESUMEAUTOMATIC があります。詳細については Power Management Events を参照してください。Setting パラメーターはサスペンド/再開通知では使用されません。 Flags が DEVICE_NOTIFY_WINDOW_HANDLE の場合、hRecipient はイベントの配信先となるウィンドウのハンドルです。 |
| Flags | REGISTER_NOTIFICATION_FLAGS | in | このパラメーターには DEVICE_NOTIFY_WINDOW_HANDLE または DEVICE_NOTIFY_CALLBACK を指定できます。 |
戻り値の型: HPOWERNOTIFY
公式ドキュメント
システムがサスペンドまたは再開されたときに通知を受け取るための登録を行います。PowerRegisterSuspendResumeNotification と似ていますが、ユーザーモードで動作し、ウィンドウハンドルを受け取ることができます。
戻り値
登録に対するハンドル。このハンドルを使用して通知の登録を解除します。
関数が失敗した場合、戻り値は NULL です。拡張エラー情報を取得するには GetLastError を呼び出します。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
HPOWERNOTIFY RegisterSuspendResumeNotification(
HANDLE hRecipient,
REGISTER_NOTIFICATION_FLAGS Flags
);[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr RegisterSuspendResumeNotification(
IntPtr hRecipient, // HANDLE
uint Flags // REGISTER_NOTIFICATION_FLAGS
);<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RegisterSuspendResumeNotification(
hRecipient As IntPtr, ' HANDLE
Flags As UInteger ' REGISTER_NOTIFICATION_FLAGS
) As IntPtr
End Function' hRecipient : HANDLE
' Flags : REGISTER_NOTIFICATION_FLAGS
Declare PtrSafe Function RegisterSuspendResumeNotification Lib "user32" ( _
ByVal hRecipient As LongPtr, _
ByVal Flags As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RegisterSuspendResumeNotification = ctypes.windll.user32.RegisterSuspendResumeNotification
RegisterSuspendResumeNotification.restype = ctypes.c_ssize_t
RegisterSuspendResumeNotification.argtypes = [
wintypes.HANDLE, # hRecipient : HANDLE
wintypes.DWORD, # Flags : REGISTER_NOTIFICATION_FLAGS
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
RegisterSuspendResumeNotification = Fiddle::Function.new(
lib['RegisterSuspendResumeNotification'],
[
Fiddle::TYPE_VOIDP, # hRecipient : HANDLE
-Fiddle::TYPE_INT, # Flags : REGISTER_NOTIFICATION_FLAGS
],
Fiddle::TYPE_INTPTR_T)#[link(name = "user32")]
extern "system" {
fn RegisterSuspendResumeNotification(
hRecipient: *mut core::ffi::c_void, // HANDLE
Flags: u32 // REGISTER_NOTIFICATION_FLAGS
) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", SetLastError = true)]
public static extern IntPtr RegisterSuspendResumeNotification(IntPtr hRecipient, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_RegisterSuspendResumeNotification' -Namespace Win32 -PassThru
# $api::RegisterSuspendResumeNotification(hRecipient, Flags)#uselib "USER32.dll"
#func global RegisterSuspendResumeNotification "RegisterSuspendResumeNotification" sptr, sptr
; RegisterSuspendResumeNotification hRecipient, Flags ; 戻り値は stat
; hRecipient : HANDLE -> "sptr"
; Flags : REGISTER_NOTIFICATION_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global RegisterSuspendResumeNotification "RegisterSuspendResumeNotification" sptr, int
; res = RegisterSuspendResumeNotification(hRecipient, Flags)
; hRecipient : HANDLE -> "sptr"
; Flags : REGISTER_NOTIFICATION_FLAGS -> "int"; HPOWERNOTIFY RegisterSuspendResumeNotification(HANDLE hRecipient, REGISTER_NOTIFICATION_FLAGS Flags)
#uselib "USER32.dll"
#cfunc global RegisterSuspendResumeNotification "RegisterSuspendResumeNotification" intptr, int
; res = RegisterSuspendResumeNotification(hRecipient, Flags)
; hRecipient : HANDLE -> "intptr"
; Flags : REGISTER_NOTIFICATION_FLAGS -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procRegisterSuspendResumeNotification = user32.NewProc("RegisterSuspendResumeNotification")
)
// hRecipient (HANDLE), Flags (REGISTER_NOTIFICATION_FLAGS)
r1, _, err := procRegisterSuspendResumeNotification.Call(
uintptr(hRecipient),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HPOWERNOTIFYfunction RegisterSuspendResumeNotification(
hRecipient: THandle; // HANDLE
Flags: DWORD // REGISTER_NOTIFICATION_FLAGS
): NativeInt; stdcall;
external 'USER32.dll' name 'RegisterSuspendResumeNotification';result := DllCall("USER32\RegisterSuspendResumeNotification"
, "Ptr", hRecipient ; HANDLE
, "UInt", Flags ; REGISTER_NOTIFICATION_FLAGS
, "Ptr") ; return: HPOWERNOTIFY●RegisterSuspendResumeNotification(hRecipient, Flags) = DLL("USER32.dll", "int RegisterSuspendResumeNotification(void*, dword)")
# 呼び出し: RegisterSuspendResumeNotification(hRecipient, Flags)
# hRecipient : HANDLE -> "void*"
# Flags : REGISTER_NOTIFICATION_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn RegisterSuspendResumeNotification(
hRecipient: ?*anyopaque, // HANDLE
Flags: u32 // REGISTER_NOTIFICATION_FLAGS
) callconv(std.os.windows.WINAPI) isize;proc RegisterSuspendResumeNotification(
hRecipient: pointer, # HANDLE
Flags: uint32 # REGISTER_NOTIFICATION_FLAGS
): int {.importc: "RegisterSuspendResumeNotification", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
ptrdiff_t RegisterSuspendResumeNotification(
void* hRecipient, // HANDLE
uint Flags // REGISTER_NOTIFICATION_FLAGS
);ccall((:RegisterSuspendResumeNotification, "USER32.dll"), stdcall, Int,
(Ptr{Cvoid}, UInt32),
hRecipient, Flags)
# hRecipient : HANDLE -> Ptr{Cvoid}
# Flags : REGISTER_NOTIFICATION_FLAGS -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
intptr_t RegisterSuspendResumeNotification(
void* hRecipient,
uint32_t Flags);
]]
local user32 = ffi.load("user32")
-- user32.RegisterSuspendResumeNotification(hRecipient, Flags)
-- hRecipient : HANDLE
-- Flags : REGISTER_NOTIFICATION_FLAGS
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const RegisterSuspendResumeNotification = lib.func('__stdcall', 'RegisterSuspendResumeNotification', 'intptr_t', ['void *', 'uint32_t']);
// RegisterSuspendResumeNotification(hRecipient, Flags)
// hRecipient : HANDLE -> 'void *'
// Flags : REGISTER_NOTIFICATION_FLAGS -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
RegisterSuspendResumeNotification: { parameters: ["pointer", "u32"], result: "isize" },
});
// lib.symbols.RegisterSuspendResumeNotification(hRecipient, Flags)
// hRecipient : HANDLE -> "pointer"
// Flags : REGISTER_NOTIFICATION_FLAGS -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
intptr_t RegisterSuspendResumeNotification(
void* hRecipient,
uint32_t Flags);
C, "USER32.dll");
// $ffi->RegisterSuspendResumeNotification(hRecipient, Flags);
// hRecipient : HANDLE
// Flags : REGISTER_NOTIFICATION_FLAGS
// 構造体/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);
long RegisterSuspendResumeNotification(
Pointer hRecipient, // HANDLE
int Flags // REGISTER_NOTIFICATION_FLAGS
);
}@[Link("user32")]
lib LibUSER32
fun RegisterSuspendResumeNotification = RegisterSuspendResumeNotification(
hRecipient : Void*, # HANDLE
Flags : UInt32 # REGISTER_NOTIFICATION_FLAGS
) : LibC::SSizeT
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RegisterSuspendResumeNotificationNative = IntPtr Function(Pointer<Void>, Uint32);
typedef RegisterSuspendResumeNotificationDart = int Function(Pointer<Void>, int);
final RegisterSuspendResumeNotification = DynamicLibrary.open('USER32.dll')
.lookupFunction<RegisterSuspendResumeNotificationNative, RegisterSuspendResumeNotificationDart>('RegisterSuspendResumeNotification');
// hRecipient : HANDLE -> Pointer<Void>
// Flags : REGISTER_NOTIFICATION_FLAGS -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RegisterSuspendResumeNotification(
hRecipient: THandle; // HANDLE
Flags: DWORD // REGISTER_NOTIFICATION_FLAGS
): NativeInt; stdcall;
external 'USER32.dll' name 'RegisterSuspendResumeNotification';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RegisterSuspendResumeNotification"
c_RegisterSuspendResumeNotification :: Ptr () -> Word32 -> IO CIntPtr
-- hRecipient : HANDLE -> Ptr ()
-- Flags : REGISTER_NOTIFICATION_FLAGS -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let registersuspendresumenotification =
foreign "RegisterSuspendResumeNotification"
((ptr void) @-> uint32_t @-> returning intptr_t)
(* hRecipient : HANDLE -> (ptr void) *)
(* Flags : REGISTER_NOTIFICATION_FLAGS -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("RegisterSuspendResumeNotification" register-suspend-resume-notification :convention :stdcall) :int64
(h-recipient :pointer) ; HANDLE
(flags :uint32)) ; REGISTER_NOTIFICATION_FLAGS
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RegisterSuspendResumeNotification = Win32::API::More->new('USER32',
'LPARAM RegisterSuspendResumeNotification(HANDLE hRecipient, DWORD Flags)');
# my $ret = $RegisterSuspendResumeNotification->Call($hRecipient, $Flags);
# hRecipient : HANDLE -> HANDLE
# Flags : REGISTER_NOTIFICATION_FLAGS -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- s DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS
- f UnregisterSuspendResumeNotification — サスペンド・再開通知の登録を解除する。