Win32 API 日本語リファレンス
ホームSystem.Ole › IsAccelerator

IsAccelerator

関数
メッセージがアクセラレータテーブルに該当するか判定する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL IsAccelerator(
    HACCEL hAccel,
    INT cAccelEntries,
    MSG* lpMsg,
    WORD* lpwCmd
);

パラメーター

名前方向説明
hAccelHACCELinアクセラレータテーブルへのハンドルです。
cAccelEntriesINTinアクセラレータテーブル内のエントリ数です。
lpMsgMSG*in変換対象のキーストロークメッセージへのポインタです。
lpwCmdWORD*outキーストロークに対応するアクセラレータが存在する場合に、対応するコマンド識別子を受け取る変数へのポインタです。このパラメータは NULL でもかまいません。

戻り値の型: BOOL

公式ドキュメント

指定されたキーストロークが、指定されたアクセラレータテーブル内のアクセラレータに対応するかどうかを判定します。

戻り値

メッセージがオブジェクトアプリケーション宛てである場合、戻り値は TRUE です。メッセージがオブジェクト宛てではなく、コンテナへ転送すべき場合、戻り値は FALSE です。

解説(Remarks)

オブジェクトがインプレースでアクティブな間は、オブジェクトが常に最初にキーストロークをアクセラレータへ変換する機会を持ちます。キーストロークがそのアクセラレータのいずれかに対応する場合、たとえ TranslateAccelerator 関数の呼び出しが失敗したとしても、オブジェクトは OleTranslateAccelerator 関数を呼び出してはなりません。この方法でキーストロークを処理しないと、一貫性のない動作につながる可能性があります。

キーストロークがオブジェクトのアクセラレータのいずれにも該当しない場合、オブジェクトは OleTranslateAccelerator を呼び出し、コンテナにアクセラレータ変換を試行させる必要があります。

オブジェクトのサーバーは、アクセラレータメッセージが自分宛てかどうかを判定するために IsAccelerator を呼び出すことができます。一部のサーバーは独自にアクセラレータ変換を行い、TranslateAccelerator を呼び出しません。そのようなアプリケーションは、すでに必要な情報を持っているため、IsAccelerator を呼び出しません。

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

各言語での呼び出し定義

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

BOOL IsAccelerator(
    HACCEL hAccel,
    INT cAccelEntries,
    MSG* lpMsg,
    WORD* lpwCmd
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("OLE32.dll", ExactSpelling = true)]
static extern bool IsAccelerator(
    IntPtr hAccel,   // HACCEL
    int cAccelEntries,   // INT
    IntPtr lpMsg,   // MSG*
    out ushort lpwCmd   // WORD* out
);
<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function IsAccelerator(
    hAccel As IntPtr,   ' HACCEL
    cAccelEntries As Integer,   ' INT
    lpMsg As IntPtr,   ' MSG*
    <Out> ByRef lpwCmd As UShort   ' WORD* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hAccel : HACCEL
' cAccelEntries : INT
' lpMsg : MSG*
' lpwCmd : WORD* out
Declare PtrSafe Function IsAccelerator Lib "ole32" ( _
    ByVal hAccel As LongPtr, _
    ByVal cAccelEntries As Long, _
    ByVal lpMsg As LongPtr, _
    ByRef lpwCmd As Integer) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

IsAccelerator = ctypes.windll.ole32.IsAccelerator
IsAccelerator.restype = wintypes.BOOL
IsAccelerator.argtypes = [
    wintypes.HANDLE,  # hAccel : HACCEL
    ctypes.c_int,  # cAccelEntries : INT
    ctypes.c_void_p,  # lpMsg : MSG*
    ctypes.POINTER(ctypes.c_ushort),  # lpwCmd : WORD* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLE32.dll')
IsAccelerator = Fiddle::Function.new(
  lib['IsAccelerator'],
  [
    Fiddle::TYPE_VOIDP,  # hAccel : HACCEL
    Fiddle::TYPE_INT,  # cAccelEntries : INT
    Fiddle::TYPE_VOIDP,  # lpMsg : MSG*
    Fiddle::TYPE_VOIDP,  # lpwCmd : WORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ole32")]
extern "system" {
    fn IsAccelerator(
        hAccel: *mut core::ffi::c_void,  // HACCEL
        cAccelEntries: i32,  // INT
        lpMsg: *mut MSG,  // MSG*
        lpwCmd: *mut u16  // WORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("OLE32.dll")]
public static extern bool IsAccelerator(IntPtr hAccel, int cAccelEntries, IntPtr lpMsg, out ushort lpwCmd);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_IsAccelerator' -Namespace Win32 -PassThru
# $api::IsAccelerator(hAccel, cAccelEntries, lpMsg, lpwCmd)
#uselib "OLE32.dll"
#func global IsAccelerator "IsAccelerator" sptr, sptr, sptr, sptr
; IsAccelerator hAccel, cAccelEntries, varptr(lpMsg), varptr(lpwCmd)   ; 戻り値は stat
; hAccel : HACCEL -> "sptr"
; cAccelEntries : INT -> "sptr"
; lpMsg : MSG* -> "sptr"
; lpwCmd : WORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "OLE32.dll"
#cfunc global IsAccelerator "IsAccelerator" sptr, int, var, var
; res = IsAccelerator(hAccel, cAccelEntries, lpMsg, lpwCmd)
; hAccel : HACCEL -> "sptr"
; cAccelEntries : INT -> "int"
; lpMsg : MSG* -> "var"
; lpwCmd : WORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL IsAccelerator(HACCEL hAccel, INT cAccelEntries, MSG* lpMsg, WORD* lpwCmd)
#uselib "OLE32.dll"
#cfunc global IsAccelerator "IsAccelerator" intptr, int, var, var
; res = IsAccelerator(hAccel, cAccelEntries, lpMsg, lpwCmd)
; hAccel : HACCEL -> "intptr"
; cAccelEntries : INT -> "int"
; lpMsg : MSG* -> "var"
; lpwCmd : WORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procIsAccelerator = ole32.NewProc("IsAccelerator")
)

// hAccel (HACCEL), cAccelEntries (INT), lpMsg (MSG*), lpwCmd (WORD* out)
r1, _, err := procIsAccelerator.Call(
	uintptr(hAccel),
	uintptr(cAccelEntries),
	uintptr(lpMsg),
	uintptr(lpwCmd),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function IsAccelerator(
  hAccel: THandle;   // HACCEL
  cAccelEntries: Integer;   // INT
  lpMsg: Pointer;   // MSG*
  lpwCmd: Pointer   // WORD* out
): BOOL; stdcall;
  external 'OLE32.dll' name 'IsAccelerator';
result := DllCall("OLE32\IsAccelerator"
    , "Ptr", hAccel   ; HACCEL
    , "Int", cAccelEntries   ; INT
    , "Ptr", lpMsg   ; MSG*
    , "Ptr", lpwCmd   ; WORD* out
    , "Int")   ; return: BOOL
●IsAccelerator(hAccel, cAccelEntries, lpMsg, lpwCmd) = DLL("OLE32.dll", "bool IsAccelerator(void*, int, void*, void*)")
# 呼び出し: IsAccelerator(hAccel, cAccelEntries, lpMsg, lpwCmd)
# hAccel : HACCEL -> "void*"
# cAccelEntries : INT -> "int"
# lpMsg : MSG* -> "void*"
# lpwCmd : WORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef IsAcceleratorNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Pointer<Uint16>);
typedef IsAcceleratorDart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Uint16>);
final IsAccelerator = DynamicLibrary.open('OLE32.dll')
    .lookupFunction<IsAcceleratorNative, IsAcceleratorDart>('IsAccelerator');
// hAccel : HACCEL -> Pointer<Void>
// cAccelEntries : INT -> Int32
// lpMsg : MSG* -> Pointer<Void>
// lpwCmd : WORD* out -> Pointer<Uint16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function IsAccelerator(
  hAccel: THandle;   // HACCEL
  cAccelEntries: Integer;   // INT
  lpMsg: Pointer;   // MSG*
  lpwCmd: Pointer   // WORD* out
): BOOL; stdcall;
  external 'OLE32.dll' name 'IsAccelerator';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "IsAccelerator"
  c_IsAccelerator :: Ptr () -> Int32 -> Ptr () -> Ptr Word16 -> IO CInt
-- hAccel : HACCEL -> Ptr ()
-- cAccelEntries : INT -> Int32
-- lpMsg : MSG* -> Ptr ()
-- lpwCmd : WORD* out -> Ptr Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let isaccelerator =
  foreign "IsAccelerator"
    ((ptr void) @-> int32_t @-> (ptr void) @-> (ptr uint16_t) @-> returning int32_t)
(* hAccel : HACCEL -> (ptr void) *)
(* cAccelEntries : INT -> int32_t *)
(* lpMsg : MSG* -> (ptr void) *)
(* lpwCmd : WORD* out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ole32 (t "OLE32.dll"))
(cffi:use-foreign-library ole32)

(cffi:defcfun ("IsAccelerator" is-accelerator :convention :stdcall) :int32
  (h-accel :pointer)   ; HACCEL
  (c-accel-entries :int32)   ; INT
  (lp-msg :pointer)   ; MSG*
  (lpw-cmd :pointer))   ; WORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $IsAccelerator = Win32::API::More->new('OLE32',
    'BOOL IsAccelerator(HANDLE hAccel, int cAccelEntries, LPVOID lpMsg, LPVOID lpwCmd)');
# my $ret = $IsAccelerator->Call($hAccel, $cAccelEntries, $lpMsg, $lpwCmd);
# hAccel : HACCEL -> HANDLE
# cAccelEntries : INT -> int
# lpMsg : MSG* -> LPVOID
# lpwCmd : WORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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