function
TCustomTaskDialog
.
DoExecute(ParentWnd: HWND):
Boolean
;
const
CTaskDlgFlags:
array
[TTaskDialogFlag]
of
Cardinal
= (
TDF_Enable_Hyperlinks, TDF_Use_Hicon_Main,
tdf_Use_Hicon_Footer, TDF_ALLOW_DIALOG_CANCELLATION,
TDF_USE_COMMAND_LINKS, TDF_USE_COMMAND_LINKS_NO_ICON,
TDF_EXPAND_FOOTER_AREA, TDF_EXPANDED_BY_DEFAULT,
TDF_VERIFICATION_FLAG_CHECKED, TDF_SHOW_PROGRESS_BAR,
TDF_SHOW_MARQUEE_PROGRESS_BAR, TDF_CALLBACK_TIMER,
TDF_POSITION_RELATIVE_TO_WINDOW, TDF_RTL_LAYOUT,
TDF_NO_DEFAULT_RADIO_BUTTON, TDF_CAN_BE_MINIMIZED);
CTaskDlgCommonButtons:
array
[TTaskDialogCommonButton]
of
Cardinal
= (
TDCBF_OK_BUTTON, TDCBF_YES_BUTTON, TDCBF_NO_BUTTON,
TDCBF_CANCEL_BUTTON, TDCBF_RETRY_BUTTON, TDCBF_CLOSE_BUTTON);
CTaskDlgDefaultButtons:
array
[TTaskDialogCommonButton]
of
Integer
= (
IDOK, IDYES, IDNO, IDCANCEL, IDRETRY, IDCLOSE);
var
LWindowList: TTaskWindowList;
LModalResult:
Integer
;
LRadioButton:
Integer
;
LFlag: TTaskDialogFlag;
LFocusState: TFocusState;
LVerificationChecked: LongBool;
LTaskDialog: TTaskDialogConfig;
LCommonButton: TTaskDialogCommonButton;
begin
if
Win32MajorVersion <
6
then
raise
EPlatformVersionException
.
CreateResFmt(
{$IFNDEF CLR}@{$ENDIF}
SWindowsVistaRequired, [ClassName]);
if
not
ThemeServices
.
ThemesEnabled
then
raise
Exception
.
CreateResFmt(
{$IFNDEF CLR}@{$ENDIF}
SXPThemesRequired, [ClassName]);
{$IF NOT DEFINED(CLR)}
FillChar(LTaskDialog, SizeOf(LTaskDialog),
0
);
{
$IFEND
}
with
LTaskDialog
do
begin
cbSize := SizeOf(LTaskDialog);
hwndParent := ParentWnd;
dwFlags :=
0
;
for
LFlag := Low(TTaskDialogFlag)
to
High(TTaskDialogFlag)
do
if
LFlag
in
FFlags
then
dwFlags := dwFlags
or
CTaskDlgFlags[LFlag];
dwCommonButtons :=
0
;
for
LCommonButton := Low(TTaskDialogCommonButton)
to
High(TTaskDialogCommonButton)
do
if
LCommonButton
in
FCommonButtons
then
dwCommonButtons := dwCommonButtons
or
CTaskDlgCommonButtons[LCommonButton];
if
FText <>
''
then
pszContent :=
{$IFNDEF CLR}PWideChar{$ENDIF}
(
WideString
(FText));
if
FTitle <>
''
then
pszMainInstruction :=
{$IFNDEF CLR}PWideChar{$ENDIF}
(
WideString
(FTitle));
if
FCaption <>
''
then
pszWindowTitle :=
{$IFNDEF CLR}PWideChar{$ENDIF}
(
WideString
(FCaption));
if
tfUseHiconMain
in
FFlags
then
hMainIcon := FCustomMainIcon
.
Handle
else
begin
if
FMainIcon
in
[tdiNone
..
tdiShield]
then
pszMainIcon := LPCWSTR(CTaskDlgIcons[FMainIcon])
else
pszMainIcon := LPCWSTR(MakeIntResourceW(
Word
(FMainIcon)));
end
;
nDefaultButton := CTaskDlgDefaultButtons[FDefaultButton];
if
FFooterText <>
''
then
pszFooter :=
{$IFNDEF CLR}PWideChar{$ENDIF}
(
WideString
(FFooterText));
if
tfUseHiconFooter
in
FFlags
then
hFooterIcon := FCustomFooterIcon
.
Handle
else
begin
if
FFooterIcon
in
[tdiNone
..
tdiShield]
then
pszFooterIcon := LPCWSTR(CTaskDlgIcons[FFooterIcon])
else
pszFooterIcon := LPCWSTR(MakeIntResourceW(
Word
(FFooterIcon)));
end
;
if
FVerificationText <>
''
then
pszVerificationText :=
{$IFNDEF CLR}PWideChar{$ENDIF}
(
WideString
(FVerificationText));
if
FExpandedText <>
''
then
pszExpandedInformation :=
{$IFNDEF CLR}PWideChar{$ENDIF}
(
WideString
(FExpandedText));
if
FExpandButtonCaption <>
''
then
pszCollapsedControlText :=
{$IFNDEF CLR}PWideChar{$ENDIF}
(
WideString
(FExpandButtonCaption));
cButtons := FButtons
.
Count;
if
cButtons >
0
then
pButtons := FButtons
.
Buttons;
if
FButtons
.
DefaultButton <>
nil
then
nDefaultButton := FButtons
.
DefaultButton
.
ModalResult;
cRadioButtons := FRadioButtons
.
Count;
if
cRadioButtons >
0
then
pRadioButtons := FRadioButtons
.
Buttons;
if
not
(tfNoDefaultRadioButton
in
FFlags)
and
(FRadioButtons
.
DefaultButton <>
nil
)
then
nDefaultRadioButton := FRadioButtons
.
DefaultButton
.
ModalResult;
{$IF DEFINED(CLR)}
pfCallBack := @CallbackProc;
{
$ELSE
}
lpCallbackData := LONG_PTR(Self);
pfCallback := @TaskDialogCallbackProc;
{
$IFEND
}
end
;
LWindowList := DisableTaskWindows(ParentWnd);
LFocusState := SaveFocusState;
try
Result := TaskDialogIndirect(LTaskDialog,
{$IFNDEF CLR}@{$ENDIF}
LModalResult,
{$IFNDEF CLR}@{$ENDIF}LRadioButton, {$IFNDEF CLR}@{$ENDIF}
LVerificationChecked) = S_OK;
FModalResult := LModalResult;
if
Result
then
begin
FButton := TTaskDialogButtonItem(FButtons
.
FindButton(FModalResult));
FRadioButton := TTaskDialogRadioButtonItem(FRadioButtons
.
FindButton(LRadioButton));
if
LVerificationChecked
then
Include(FFlags, tfVerificationFlagChecked)
else
Exclude(FFlags, tfVerificationFlagChecked);
end
;
finally
EnableTaskWindows(LWindowList);
SetActiveWindow(ParentWnd);
RestoreFocusState(LFocusState);
end
;
end
;
请发表评论