Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created Mar 23, 2017
Embed
What would you like to do?
TaskDialogIndirect
Option Explicit
Enum ICONS
TD_WARNING_ICON = 65535
TD_ERROR_ICON = 65534
TD_INFORMATION_ICON = 65533
TD_SHIELD_ICON = 65532
End Enum
Enum TASKDIALOG_FLAGS
TDF_ENABLE_HYPERLINKS = &H1
TDF_USE_HICON_MAIN = &H2
TDF_USE_HICON_FOOTER = &H4
TDF_ALLOW_DIALOG_CANCELLATION = &H8
TDF_USE_COMMAND_LINKS = &H10
TDF_USE_COMMAND_LINKS_NO_ICON = &H20
TDF_EXPAND_FOOTER_AREA = &H40
TDF_EXPANDED_BY_DEFAULT = &H80
TDF_VERIFICATION_FLAG_CHECKED = &H100
TDF_SHOW_PROGRESS_BAR = &H200
TDF_SHOW_MARQUEE_PROGRESS_BAR = &H400
TDF_CALLBACK_TIMER = &H800
TDF_POSITION_RELATIVE_TO_WINDOW = &H1000
TDF_RTL_LAYOUT = &H2000
TDF_NO_DEFAULT_RADIO_BUTTON = &H4000
TDF_CAN_BE_MINIMIZED = &H8000&
End Enum
Enum TASKDIALOG_COMMON_BUTTON_FLAGS
TDCBF_OK_BUTTON = &H1
TDCBF_YES_BUTTON = &H2
TDCBF_NO_BUTTON = &H4
TDCBF_CANCEL_BUTTON = &H8
TDCBF_RETRY_BUTTON = &H10
TDCBF_CLOSE_BUTTON = &H20
End Enum
Type TASKDIALOG_BUTTON
nButtonID As Long
pszButtonText As Long
End Type
Type TASKDIALOGCONFIG
cbSize As Long
hwndParent As Long
hInstance As Long
dwFlags As TASKDIALOG_FLAGS
dwCommonButtons As Long
pszWindowTitle As Long
pszMainIcon As ICONS
pszMainInstruction As Long
pszContent As Long
cButtons As Long
pButtons As Long
nDefaultButton As Long
cRadioButtons As Long
pRadioButtons As Long
nDefaultRadioButton As Long
pszVerificationText As Long
pszExpandedInformation As Long
pszExpandedControlText As Long
pszCollapsedControlText As Long
pszFooterIcon As Long
pszFooter As Long
pfCallback As Long
lpCallbackData As Long
cxWidth As Long
End Type
Declare Function TaskDialogIndirect& Lib _
"C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.14393.953_none_89c2555adb023171\comctl32.dll" _
(ByVal pTaskConfig&, ByVal pnButton&, ByVal pnRadioButton&, ByVal pfVerificationFlagChecked&)
Sub hoge()
Dim st As TASKDIALOGCONFIG
Dim ret&, buttons(0 To 3) As TASKDIALOG_BUTTON
buttons(0).nButtonID = vbOK
buttons(0).pszButtonText = StrPtr("ボタン名(&A)")
buttons(1).nButtonID = vbCancel
buttons(1).pszButtonText = StrPtr("ボタン名2(&B)")
buttons(2).nButtonID = vbCancel
buttons(2).pszButtonText = StrPtr("ボタン名3")
buttons(3).nButtonID = vbCancel
buttons(3).pszButtonText = StrPtr("ボタン名4")
With st
.cbSize = Len(st)
.hwndParent = Excel.Application.Hwnd
.pszWindowTitle = StrPtr("Title")
.dwFlags = TDF_USE_COMMAND_LINKS
.pszMainIcon = TD_WARNING_ICON
.pszMainInstruction = StrPtr("hoge")
.pszContent = StrPtr("foo")
.pButtons = VarPtr(buttons(0))
.cButtons = UBound(buttons) + 1
End With
TaskDialogIndirect VarPtr(st), VarPtr(ret), 0, 0
Debug.Print ret
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment