Skip to content

Commit e07ffe0

Browse files
committed
phlib: Add ShowError2 dialog
1 parent 9458a36 commit e07ffe0

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

phlib/include/phutil.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ PhShowMessage_V(
236236
#define PhShowWarning(hWnd, Format, ...) PhShowMessage(hWnd, MB_OK | MB_ICONWARNING, Format, __VA_ARGS__)
237237
#define PhShowInformation(hWnd, Format, ...) PhShowMessage(hWnd, MB_OK | MB_ICONINFORMATION, Format, __VA_ARGS__)
238238

239+
PHLIBAPI
240+
INT
241+
NTAPI
242+
PhShowError2(
243+
_In_ HWND hWnd,
244+
_In_opt_ PWSTR Title,
245+
_In_opt_ PWSTR Message
246+
);
247+
239248
PHLIBAPI
240249
PPH_STRING
241250
NTAPI

phlib/util.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,51 @@ INT PhShowMessage_V(
405405
return result;
406406
}
407407

408+
INT PhShowError2(
409+
_In_ HWND hWnd,
410+
_In_opt_ PWSTR Title,
411+
_In_opt_ PWSTR Message
412+
)
413+
{
414+
if (TaskDialogIndirect_Import())
415+
{
416+
INT button;
417+
TASKDIALOGCONFIG config = { sizeof(config) };
418+
419+
config.hwndParent = hWnd;
420+
config.hInstance = PhLibImageBase;
421+
config.dwFlags = TDF_ALLOW_DIALOG_CANCELLATION | TDF_SIZE_TO_CONTENT | (IsWindowVisible(hWnd) ? TDF_POSITION_RELATIVE_TO_WINDOW : 0);
422+
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
423+
config.pszWindowTitle = PhApplicationName;
424+
config.pszMainIcon = TD_ERROR_ICON;
425+
config.pszMainInstruction = Title;
426+
config.pszContent = Message;
427+
428+
if (TaskDialogIndirect_Import()(
429+
&config,
430+
&button,
431+
NULL,
432+
NULL
433+
) == S_OK)
434+
{
435+
return button == IDCLOSE;
436+
}
437+
else
438+
{
439+
return FALSE;
440+
}
441+
}
442+
else
443+
{
444+
return PhShowMessage(
445+
hWnd,
446+
MB_OK | MB_ICONERROR,
447+
Title,
448+
Message
449+
) == IDOK;
450+
}
451+
}
452+
408453
PPH_STRING PhGetStatusMessage(
409454
_In_ NTSTATUS Status,
410455
_In_opt_ ULONG Win32Result
@@ -468,7 +513,7 @@ VOID PhShowStatus(
468513

469514
if (Message)
470515
{
471-
PhShowError(hWnd, L"%s: %s", Message, statusMessage->Buffer);
516+
PhShowError2(hWnd, Message, statusMessage->Buffer);
472517
}
473518
else
474519
{
@@ -517,7 +562,7 @@ BOOLEAN PhShowContinueStatus(
517562

518563
if (Message)
519564
{
520-
result = PhShowMessage(hWnd, MB_ICONERROR | MB_OKCANCEL, L"%s: %s", Message, statusMessage->Buffer);
565+
result = PhShowError2(hWnd, Message, statusMessage->Buffer);
521566
}
522567
else
523568
{

0 commit comments

Comments
 (0)