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

TaskDialog

関数
簡易な引数指定でタスクダイアログを表示する。
DLLCOMCTL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT TaskDialog(
    HWND hwndOwner,   // optional
    HINSTANCE hInstance,   // optional
    LPCWSTR pszWindowTitle,   // optional
    LPCWSTR pszMainInstruction,   // optional
    LPCWSTR pszContent,   // optional
    TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons,
    LPCWSTR pszIcon,   // optional
    INT* pnButton   // optional
);

パラメーター

名前方向
hwndOwnerHWNDinoptional
hInstanceHINSTANCEinoptional
pszWindowTitleLPCWSTRinoptional
pszMainInstructionLPCWSTRinoptional
pszContentLPCWSTRinoptional
dwCommonButtonsTASKDIALOG_COMMON_BUTTON_FLAGSin
pszIconLPCWSTRinoptional
pnButtonINT*outoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT TaskDialog(
    HWND hwndOwner,   // optional
    HINSTANCE hInstance,   // optional
    LPCWSTR pszWindowTitle,   // optional
    LPCWSTR pszMainInstruction,   // optional
    LPCWSTR pszContent,   // optional
    TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons,
    LPCWSTR pszIcon,   // optional
    INT* pnButton   // optional
);
[DllImport("COMCTL32.dll", ExactSpelling = true)]
static extern int TaskDialog(
    IntPtr hwndOwner,   // HWND optional
    IntPtr hInstance,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszWindowTitle,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszMainInstruction,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszContent,   // LPCWSTR optional
    int dwCommonButtons,   // TASKDIALOG_COMMON_BUTTON_FLAGS
    [MarshalAs(UnmanagedType.LPWStr)] string pszIcon,   // LPCWSTR optional
    IntPtr pnButton   // INT* optional, out
);
<DllImport("COMCTL32.dll", ExactSpelling:=True)>
Public Shared Function TaskDialog(
    hwndOwner As IntPtr,   ' HWND optional
    hInstance As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPWStr)> pszWindowTitle As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> pszMainInstruction As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> pszContent As String,   ' LPCWSTR optional
    dwCommonButtons As Integer,   ' TASKDIALOG_COMMON_BUTTON_FLAGS
    <MarshalAs(UnmanagedType.LPWStr)> pszIcon As String,   ' LPCWSTR optional
    pnButton As IntPtr   ' INT* optional, out
) As Integer
End Function
' hwndOwner : HWND optional
' hInstance : HINSTANCE optional
' pszWindowTitle : LPCWSTR optional
' pszMainInstruction : LPCWSTR optional
' pszContent : LPCWSTR optional
' dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS
' pszIcon : LPCWSTR optional
' pnButton : INT* optional, out
Declare PtrSafe Function TaskDialog Lib "comctl32" ( _
    ByVal hwndOwner As LongPtr, _
    ByVal hInstance As LongPtr, _
    ByVal pszWindowTitle As LongPtr, _
    ByVal pszMainInstruction As LongPtr, _
    ByVal pszContent As LongPtr, _
    ByVal dwCommonButtons As Long, _
    ByVal pszIcon As LongPtr, _
    ByVal pnButton As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

TaskDialog = ctypes.windll.comctl32.TaskDialog
TaskDialog.restype = ctypes.c_int
TaskDialog.argtypes = [
    wintypes.HANDLE,  # hwndOwner : HWND optional
    wintypes.HANDLE,  # hInstance : HINSTANCE optional
    wintypes.LPCWSTR,  # pszWindowTitle : LPCWSTR optional
    wintypes.LPCWSTR,  # pszMainInstruction : LPCWSTR optional
    wintypes.LPCWSTR,  # pszContent : LPCWSTR optional
    ctypes.c_int,  # dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS
    wintypes.LPCWSTR,  # pszIcon : LPCWSTR optional
    ctypes.POINTER(ctypes.c_int),  # pnButton : INT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('COMCTL32.dll')
TaskDialog = Fiddle::Function.new(
  lib['TaskDialog'],
  [
    Fiddle::TYPE_VOIDP,  # hwndOwner : HWND optional
    Fiddle::TYPE_VOIDP,  # hInstance : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # pszWindowTitle : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pszMainInstruction : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pszContent : LPCWSTR optional
    Fiddle::TYPE_INT,  # dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS
    Fiddle::TYPE_VOIDP,  # pszIcon : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pnButton : INT* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "comctl32")]
extern "system" {
    fn TaskDialog(
        hwndOwner: *mut core::ffi::c_void,  // HWND optional
        hInstance: *mut core::ffi::c_void,  // HINSTANCE optional
        pszWindowTitle: *const u16,  // LPCWSTR optional
        pszMainInstruction: *const u16,  // LPCWSTR optional
        pszContent: *const u16,  // LPCWSTR optional
        dwCommonButtons: i32,  // TASKDIALOG_COMMON_BUTTON_FLAGS
        pszIcon: *const u16,  // LPCWSTR optional
        pnButton: *mut i32  // INT* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("COMCTL32.dll")]
public static extern int TaskDialog(IntPtr hwndOwner, IntPtr hInstance, [MarshalAs(UnmanagedType.LPWStr)] string pszWindowTitle, [MarshalAs(UnmanagedType.LPWStr)] string pszMainInstruction, [MarshalAs(UnmanagedType.LPWStr)] string pszContent, int dwCommonButtons, [MarshalAs(UnmanagedType.LPWStr)] string pszIcon, IntPtr pnButton);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMCTL32_TaskDialog' -Namespace Win32 -PassThru
# $api::TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)
#uselib "COMCTL32.dll"
#func global TaskDialog "TaskDialog" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; TaskDialog hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, varptr(pnButton)   ; 戻り値は stat
; hwndOwner : HWND optional -> "sptr"
; hInstance : HINSTANCE optional -> "sptr"
; pszWindowTitle : LPCWSTR optional -> "sptr"
; pszMainInstruction : LPCWSTR optional -> "sptr"
; pszContent : LPCWSTR optional -> "sptr"
; dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "sptr"
; pszIcon : LPCWSTR optional -> "sptr"
; pnButton : INT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "COMCTL32.dll"
#cfunc global TaskDialog "TaskDialog" sptr, sptr, wstr, wstr, wstr, int, wstr, var
; res = TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)
; hwndOwner : HWND optional -> "sptr"
; hInstance : HINSTANCE optional -> "sptr"
; pszWindowTitle : LPCWSTR optional -> "wstr"
; pszMainInstruction : LPCWSTR optional -> "wstr"
; pszContent : LPCWSTR optional -> "wstr"
; dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "int"
; pszIcon : LPCWSTR optional -> "wstr"
; pnButton : INT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT TaskDialog(HWND hwndOwner, HINSTANCE hInstance, LPCWSTR pszWindowTitle, LPCWSTR pszMainInstruction, LPCWSTR pszContent, TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons, LPCWSTR pszIcon, INT* pnButton)
#uselib "COMCTL32.dll"
#cfunc global TaskDialog "TaskDialog" intptr, intptr, wstr, wstr, wstr, int, wstr, var
; res = TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)
; hwndOwner : HWND optional -> "intptr"
; hInstance : HINSTANCE optional -> "intptr"
; pszWindowTitle : LPCWSTR optional -> "wstr"
; pszMainInstruction : LPCWSTR optional -> "wstr"
; pszContent : LPCWSTR optional -> "wstr"
; dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "int"
; pszIcon : LPCWSTR optional -> "wstr"
; pnButton : INT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	comctl32 = windows.NewLazySystemDLL("COMCTL32.dll")
	procTaskDialog = comctl32.NewProc("TaskDialog")
)

// hwndOwner (HWND optional), hInstance (HINSTANCE optional), pszWindowTitle (LPCWSTR optional), pszMainInstruction (LPCWSTR optional), pszContent (LPCWSTR optional), dwCommonButtons (TASKDIALOG_COMMON_BUTTON_FLAGS), pszIcon (LPCWSTR optional), pnButton (INT* optional, out)
r1, _, err := procTaskDialog.Call(
	uintptr(hwndOwner),
	uintptr(hInstance),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszWindowTitle))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszMainInstruction))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszContent))),
	uintptr(dwCommonButtons),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszIcon))),
	uintptr(pnButton),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function TaskDialog(
  hwndOwner: THandle;   // HWND optional
  hInstance: THandle;   // HINSTANCE optional
  pszWindowTitle: PWideChar;   // LPCWSTR optional
  pszMainInstruction: PWideChar;   // LPCWSTR optional
  pszContent: PWideChar;   // LPCWSTR optional
  dwCommonButtons: Integer;   // TASKDIALOG_COMMON_BUTTON_FLAGS
  pszIcon: PWideChar;   // LPCWSTR optional
  pnButton: Pointer   // INT* optional, out
): Integer; stdcall;
  external 'COMCTL32.dll' name 'TaskDialog';
result := DllCall("COMCTL32\TaskDialog"
    , "Ptr", hwndOwner   ; HWND optional
    , "Ptr", hInstance   ; HINSTANCE optional
    , "WStr", pszWindowTitle   ; LPCWSTR optional
    , "WStr", pszMainInstruction   ; LPCWSTR optional
    , "WStr", pszContent   ; LPCWSTR optional
    , "Int", dwCommonButtons   ; TASKDIALOG_COMMON_BUTTON_FLAGS
    , "WStr", pszIcon   ; LPCWSTR optional
    , "Ptr", pnButton   ; INT* optional, out
    , "Int")   ; return: HRESULT
●TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton) = DLL("COMCTL32.dll", "int TaskDialog(void*, void*, char*, char*, char*, int, char*, void*)")
# 呼び出し: TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)
# hwndOwner : HWND optional -> "void*"
# hInstance : HINSTANCE optional -> "void*"
# pszWindowTitle : LPCWSTR optional -> "char*"
# pszMainInstruction : LPCWSTR optional -> "char*"
# pszContent : LPCWSTR optional -> "char*"
# dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "int"
# pszIcon : LPCWSTR optional -> "char*"
# pnButton : INT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。