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

ShellMessageBoxA

関数可変長引数
リソース文字列を用いてメッセージボックスを表示する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約cdeclSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

INT ShellMessageBoxA(
    HINSTANCE hAppInst,   // optional
    HWND hWnd,   // optional
    LPCSTR lpcText,
    LPCSTR lpcTitle,   // optional
    MESSAGEBOX_STYLE fuStyle,
    ...
);
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。

パラメーター

名前方向
hAppInstHINSTANCEinoptional
hWndHWNDinoptional
lpcTextLPCSTRin
lpcTitleLPCSTRinoptional
fuStyleMESSAGEBOX_STYLEin

戻り値の型: INT

各言語での呼び出し定義

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

INT ShellMessageBoxA(
    HINSTANCE hAppInst,   // optional
    HWND hWnd,   // optional
    LPCSTR lpcText,
    LPCSTR lpcTitle,   // optional
    MESSAGEBOX_STYLE fuStyle,
    ...
);
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int ShellMessageBoxA(
    IntPtr hAppInst,   // HINSTANCE optional
    IntPtr hWnd,   // HWND optional
    [MarshalAs(UnmanagedType.LPStr)] string lpcText,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string lpcTitle,   // LPCSTR optional
    uint fuStyle,   // MESSAGEBOX_STYLE
    __arglist
);
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ShellMessageBoxA(
    hAppInst As IntPtr,   ' HINSTANCE optional
    hWnd As IntPtr,   ' HWND optional
    <MarshalAs(UnmanagedType.LPStr)> lpcText As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> lpcTitle As String,   ' LPCSTR optional
    fuStyle As UInteger   ' MESSAGEBOX_STYLE
) As Integer
End Function
' ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
' hAppInst : HINSTANCE optional
' hWnd : HWND optional
' lpcText : LPCSTR
' lpcTitle : LPCSTR optional
' fuStyle : MESSAGEBOX_STYLE
Declare PtrSafe Function ShellMessageBoxA Lib "shlwapi" ( _
    ByVal hAppInst As LongPtr, _
    ByVal hWnd As LongPtr, _
    ByVal lpcText As String, _
    ByVal lpcTitle As String, _
    ByVal fuStyle As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
' ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
import ctypes
from ctypes import wintypes

ShellMessageBoxA = ctypes.cdll.shlwapi.ShellMessageBoxA
ShellMessageBoxA.restype = ctypes.c_int
ShellMessageBoxA.argtypes = [
    wintypes.HANDLE,  # hAppInst : HINSTANCE optional
    wintypes.HANDLE,  # hWnd : HWND optional
    wintypes.LPCSTR,  # lpcText : LPCSTR
    wintypes.LPCSTR,  # lpcTitle : LPCSTR optional
    wintypes.DWORD,  # fuStyle : MESSAGEBOX_STYLE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
ShellMessageBoxA = Fiddle::Function.new(
  lib['ShellMessageBoxA'],
  [
    Fiddle::TYPE_VOIDP,  # hAppInst : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # hWnd : HWND optional
    Fiddle::TYPE_VOIDP,  # lpcText : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpcTitle : LPCSTR optional
    -Fiddle::TYPE_INT,  # fuStyle : MESSAGEBOX_STYLE
  ],
  Fiddle::TYPE_INT, Fiddle::Function::CDECL)
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
#[link(name = "shlwapi")]
extern "C" {
    fn ShellMessageBoxA(
        hAppInst: *mut core::ffi::c_void,  // HINSTANCE optional
        hWnd: *mut core::ffi::c_void,  // HWND optional
        lpcText: *const u8,  // LPCSTR
        lpcTitle: *const u8,  // LPCSTR optional
        fuStyle: u32,  // MESSAGEBOX_STYLE
        ...
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int ShellMessageBoxA(IntPtr hAppInst, IntPtr hWnd, [MarshalAs(UnmanagedType.LPStr)] string lpcText, [MarshalAs(UnmanagedType.LPStr)] string lpcTitle, uint fuStyle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_ShellMessageBoxA' -Namespace Win32 -PassThru
# $api::ShellMessageBoxA(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
#uselib "SHLWAPI.dll"
#func global ShellMessageBoxA "ShellMessageBoxA" sptr, sptr, sptr, sptr, sptr
; ShellMessageBoxA hAppInst, hWnd, lpcText, lpcTitle, fuStyle   ; 戻り値は stat
; hAppInst : HINSTANCE optional -> "sptr"
; hWnd : HWND optional -> "sptr"
; lpcText : LPCSTR -> "sptr"
; lpcTitle : LPCSTR optional -> "sptr"
; fuStyle : MESSAGEBOX_STYLE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
; ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
#uselib "SHLWAPI.dll"
#cfunc global ShellMessageBoxA "ShellMessageBoxA" sptr, sptr, str, str, int
; res = ShellMessageBoxA(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
; hAppInst : HINSTANCE optional -> "sptr"
; hWnd : HWND optional -> "sptr"
; lpcText : LPCSTR -> "str"
; lpcTitle : LPCSTR optional -> "str"
; fuStyle : MESSAGEBOX_STYLE -> "int"
; ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
; INT ShellMessageBoxA(HINSTANCE hAppInst, HWND hWnd, LPCSTR lpcText, LPCSTR lpcTitle, MESSAGEBOX_STYLE fuStyle)
#uselib "SHLWAPI.dll"
#cfunc global ShellMessageBoxA "ShellMessageBoxA" intptr, intptr, str, str, int
; res = ShellMessageBoxA(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
; hAppInst : HINSTANCE optional -> "intptr"
; hWnd : HWND optional -> "intptr"
; lpcText : LPCSTR -> "str"
; lpcTitle : LPCSTR optional -> "str"
; fuStyle : MESSAGEBOX_STYLE -> "int"
; ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procShellMessageBoxA = shlwapi.NewProc("ShellMessageBoxA")
)

// hAppInst (HINSTANCE optional), hWnd (HWND optional), lpcText (LPCSTR), lpcTitle (LPCSTR optional), fuStyle (MESSAGEBOX_STYLE)
r1, _, err := procShellMessageBoxA.Call(
	uintptr(hAppInst),
	uintptr(hWnd),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpcText))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpcTitle))),
	uintptr(fuStyle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
function ShellMessageBoxA(
  hAppInst: THandle;   // HINSTANCE optional
  hWnd: THandle;   // HWND optional
  lpcText: PAnsiChar;   // LPCSTR
  lpcTitle: PAnsiChar;   // LPCSTR optional
  fuStyle: DWORD   // MESSAGEBOX_STYLE
): Integer; cdecl; varargs;
  external 'SHLWAPI.dll' name 'ShellMessageBoxA';
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
result := DllCall("SHLWAPI\ShellMessageBoxA"
    , "Ptr", hAppInst   ; HINSTANCE optional
    , "Ptr", hWnd   ; HWND optional
    , "AStr", lpcText   ; LPCSTR
    , "AStr", lpcTitle   ; LPCSTR optional
    , "UInt", fuStyle   ; MESSAGEBOX_STYLE
    , "Cdecl Int")   ; return: INT
; ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
●ShellMessageBoxA(hAppInst, hWnd, lpcText, lpcTitle, fuStyle) = DLL("SHLWAPI.dll", "int ShellMessageBoxA(void*, void*, char*, char*, dword)")
# 呼び出し: ShellMessageBoxA(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
# hAppInst : HINSTANCE optional -> "void*"
# hWnd : HWND optional -> "void*"
# lpcText : LPCSTR -> "char*"
# lpcTitle : LPCSTR optional -> "char*"
# fuStyle : MESSAGEBOX_STYLE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。
# ※可変長引数。DLL()は固定引数のみ。追加引数は EXEC_PTR で渡してください。
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。