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

SHQueryUserNotificationState

関数
通知表示が可能かを示すユーザー通知状態を取得する。
DLLSHELL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// SHELL32.dll
#include <windows.h>

HRESULT SHQueryUserNotificationState(
    QUERY_USER_NOTIFICATION_STATE* pquns
);

パラメーター

名前方向説明
pqunsQUERY_USER_NOTIFICATION_STATE*outこの関数が返るとき、QUERY_USER_NOTIFICATION_STATE 列挙体の値のいずれかへのポインターを格納します。

戻り値の型: HRESULT

公式ドキュメント

現在のユーザーに対して通知を送信することが適切かどうかを判断するために、コンピューターの状態を確認します。

戻り値

型: HRESULT

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

解説(Remarks)

アプリケーションは、Shell_NotifyIcon によって生成されるバルーン通知に類似した通知 UI を表示する前に、SHQueryUserNotificationState を呼び出して戻り値を確認する必要があります。通知は、この API が QNS_ACCEPTS_NOTIFICATIONS を返した場合にのみ表示すべきです。これにより、中断すべきでないプロセスをユーザーが実行しているかどうかをアプリケーションに通知します。トップレベル ウィンドウは、ユーザーがプレゼンテーション設定をオンまたはオフにしたとき、およびユーザーのセッションがロックまたはロック解除されたときに WM_SETTINGCHANGE メッセージを受け取ります。ユーザーがフルスクリーン アプリケーションを開始または終了したときには通知が送信されないことに注意してください。

この関数が QUNS_QUIET_TIME を返した場合、通知は重要な場合にのみ表示すべきです。

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

各言語での呼び出し定義

// SHELL32.dll
#include <windows.h>

HRESULT SHQueryUserNotificationState(
    QUERY_USER_NOTIFICATION_STATE* pquns
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHQueryUserNotificationState(
    out int pquns   // QUERY_USER_NOTIFICATION_STATE* out
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHQueryUserNotificationState(
    <Out> ByRef pquns As Integer   ' QUERY_USER_NOTIFICATION_STATE* out
) As Integer
End Function
' pquns : QUERY_USER_NOTIFICATION_STATE* out
Declare PtrSafe Function SHQueryUserNotificationState Lib "shell32" ( _
    ByRef pquns As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHQueryUserNotificationState = ctypes.windll.shell32.SHQueryUserNotificationState
SHQueryUserNotificationState.restype = ctypes.c_int
SHQueryUserNotificationState.argtypes = [
    ctypes.c_void_p,  # pquns : QUERY_USER_NOTIFICATION_STATE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
SHQueryUserNotificationState = Fiddle::Function.new(
  lib['SHQueryUserNotificationState'],
  [
    Fiddle::TYPE_VOIDP,  # pquns : QUERY_USER_NOTIFICATION_STATE* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "shell32")]
extern "system" {
    fn SHQueryUserNotificationState(
        pquns: *mut i32  // QUERY_USER_NOTIFICATION_STATE* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll")]
public static extern int SHQueryUserNotificationState(out int pquns);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHQueryUserNotificationState' -Namespace Win32 -PassThru
# $api::SHQueryUserNotificationState(pquns)
#uselib "SHELL32.dll"
#func global SHQueryUserNotificationState "SHQueryUserNotificationState" sptr
; SHQueryUserNotificationState varptr(pquns)   ; 戻り値は stat
; pquns : QUERY_USER_NOTIFICATION_STATE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global SHQueryUserNotificationState "SHQueryUserNotificationState" var
; res = SHQueryUserNotificationState(pquns)
; pquns : QUERY_USER_NOTIFICATION_STATE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SHQueryUserNotificationState(QUERY_USER_NOTIFICATION_STATE* pquns)
#uselib "SHELL32.dll"
#cfunc global SHQueryUserNotificationState "SHQueryUserNotificationState" var
; res = SHQueryUserNotificationState(pquns)
; pquns : QUERY_USER_NOTIFICATION_STATE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHQueryUserNotificationState = shell32.NewProc("SHQueryUserNotificationState")
)

// pquns (QUERY_USER_NOTIFICATION_STATE* out)
r1, _, err := procSHQueryUserNotificationState.Call(
	uintptr(pquns),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHQueryUserNotificationState(
  pquns: Pointer   // QUERY_USER_NOTIFICATION_STATE* out
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHQueryUserNotificationState';
result := DllCall("SHELL32\SHQueryUserNotificationState"
    , "Ptr", pquns   ; QUERY_USER_NOTIFICATION_STATE* out
    , "Int")   ; return: HRESULT
●SHQueryUserNotificationState(pquns) = DLL("SHELL32.dll", "int SHQueryUserNotificationState(void*)")
# 呼び出し: SHQueryUserNotificationState(pquns)
# pquns : QUERY_USER_NOTIFICATION_STATE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef SHQueryUserNotificationStateNative = Int32 Function(Pointer<Int32>);
typedef SHQueryUserNotificationStateDart = int Function(Pointer<Int32>);
final SHQueryUserNotificationState = DynamicLibrary.open('SHELL32.dll')
    .lookupFunction<SHQueryUserNotificationStateNative, SHQueryUserNotificationStateDart>('SHQueryUserNotificationState');
// pquns : QUERY_USER_NOTIFICATION_STATE* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SHQueryUserNotificationState(
  pquns: Pointer   // QUERY_USER_NOTIFICATION_STATE* out
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHQueryUserNotificationState';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SHQueryUserNotificationState"
  c_SHQueryUserNotificationState :: Ptr Int32 -> IO Int32
-- pquns : QUERY_USER_NOTIFICATION_STATE* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let shqueryusernotificationstate =
  foreign "SHQueryUserNotificationState"
    ((ptr int32_t) @-> returning int32_t)
(* pquns : QUERY_USER_NOTIFICATION_STATE* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)

(cffi:defcfun ("SHQueryUserNotificationState" shquery-user-notification-state :convention :stdcall) :int32
  (pquns :pointer))   ; QUERY_USER_NOTIFICATION_STATE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SHQueryUserNotificationState = Win32::API::More->new('SHELL32',
    'int SHQueryUserNotificationState(LPVOID pquns)');
# my $ret = $SHQueryUserNotificationState->Call($pquns);
# pquns : QUERY_USER_NOTIFICATION_STATE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型