Skip to content

Commit fd455f6

Browse files
committed
Add TaskDialog message macros
1 parent 2261ebc commit fd455f6

File tree

4 files changed

+26
-54
lines changed

4 files changed

+26
-54
lines changed

ProcessHacker/ProcessHacker.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ EXPORTS
377377
PhShellProperties
378378
PhShowConfirmMessage
379379
PhShowContinueStatus
380+
PhShowMessage2
380381
PhShowFileDialog
381382
PhShowMessage
382383
PhShowMessage_V

ProcessHacker/plugin.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ VOID PhLoadPlugins(
270270
PPH_STRING baseName;
271271

272272
PhInitializeStringBuilder(&sb, 100);
273-
PhAppendStringBuilder2(&sb, L"Unable to load the following plugin(s):\n\n");
274273

275274
for (i = 0; i < LoadErrors->Count; i++)
276275
{
@@ -283,9 +282,12 @@ VOID PhLoadPlugins(
283282

284283
PhAppendStringBuilder2(&sb, L"\nDo you want to disable the above plugin(s)?");
285284

286-
if (PhShowMessage(
285+
if (PhShowMessage2(
287286
NULL,
288-
MB_ICONERROR | MB_YESNO,
287+
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON,
288+
TD_ERROR_ICON,
289+
L"Unable to load the following plugin(s)",
290+
L"%s",
289291
sb.String->Buffer
290292
) == IDYES)
291293
{

phlib/include/phutil.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,20 @@ PhShowMessage_V(
237237
#define PhShowInformation(hWnd, Format, ...) PhShowMessage(hWnd, MB_OK | MB_ICONINFORMATION, Format, __VA_ARGS__)
238238

239239
PHLIBAPI
240-
INT
240+
INT
241241
NTAPI
242-
PhShowInformation2(
242+
PhShowMessage2(
243243
_In_ HWND hWnd,
244+
_In_ ULONG Buttons,
245+
_In_opt_ PWSTR Icon,
244246
_In_opt_ PWSTR Title,
245247
_In_ PWSTR Format,
246248
...
247249
);
248250

249-
PHLIBAPI
250-
INT
251-
NTAPI
252-
PhShowError2(
253-
_In_ HWND hWnd,
254-
_In_opt_ PWSTR Title,
255-
_In_opt_ PWSTR Message
256-
);
251+
#define PhShowError2(hWnd, Format, ...) PhShowMessage2(hWnd, TDCBF_CLOSE_BUTTON, TD_ERROR_ICON, Format, __VA_ARGS__)
252+
#define PhShowWarning2(hWnd, Format, ...) PhShowMessage2(hWnd, TDCBF_CLOSE_BUTTON, TD_WARNING_ICON, Format, __VA_ARGS__)
253+
#define PhShowInformation2(hWnd, Format, ...) PhShowMessage2(hWnd, TDCBF_CLOSE_BUTTON, TD_INFORMATION_ICON, Format, __VA_ARGS__)
257254

258255
PHLIBAPI
259256
PPH_STRING

phlib/util.c

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -406,78 +406,50 @@ INT PhShowMessage_V(
406406
return result;
407407
}
408408

409-
INT PhShowInformation2(
409+
INT PhShowMessage2(
410410
_In_ HWND hWnd,
411+
_In_ ULONG Buttons,
412+
_In_opt_ PWSTR Icon,
411413
_In_opt_ PWSTR Title,
412414
_In_ PWSTR Format,
413415
...
414416
)
415417
{
418+
INT result;
416419
va_list argptr;
417-
INT button;
418420
PPH_STRING message;
419421
TASKDIALOGCONFIG config = { sizeof(config) };
420422

421423
va_start(argptr, Format);
422424
message = PhFormatString_V(Format, argptr);
423425
va_end(argptr);
424426

427+
if (!message)
428+
return -1;
429+
425430
config.hwndParent = hWnd;
426431
config.hInstance = PhLibImageBase;
427-
config.dwFlags = TDF_ALLOW_DIALOG_CANCELLATION | (IsWindowVisible(hWnd) ? TDF_POSITION_RELATIVE_TO_WINDOW : 0);
428-
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
432+
config.dwFlags = TDF_ALLOW_DIALOG_CANCELLATION | (IsWindowVisible(hWnd) ? TDF_POSITION_RELATIVE_TO_WINDOW : 0) | TDF_SIZE_TO_CONTENT;
433+
config.dwCommonButtons = Buttons;
429434
config.pszWindowTitle = PhApplicationName;
430-
config.pszMainIcon = TD_INFORMATION_ICON;
435+
config.pszMainIcon = Icon;
431436
config.pszMainInstruction = Title;
432437
config.pszContent = message->Buffer;
433438

434439
if (TaskDialogIndirect(
435440
&config,
436-
&button,
441+
&result,
437442
NULL,
438443
NULL
439444
) == S_OK)
440445
{
441446
PhDereferenceObject(message);
442-
return button;
447+
return result;
443448
}
444449
else
445450
{
446451
PhDereferenceObject(message);
447-
return FALSE;
448-
}
449-
}
450-
451-
INT PhShowError2(
452-
_In_ HWND hWnd,
453-
_In_opt_ PWSTR Title,
454-
_In_opt_ PWSTR Message
455-
)
456-
{
457-
INT button;
458-
TASKDIALOGCONFIG config = { sizeof(config) };
459-
460-
config.hwndParent = hWnd;
461-
config.hInstance = PhLibImageBase;
462-
config.dwFlags = TDF_ALLOW_DIALOG_CANCELLATION | (IsWindowVisible(hWnd) ? TDF_POSITION_RELATIVE_TO_WINDOW : 0);
463-
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
464-
config.pszWindowTitle = PhApplicationName;
465-
config.pszMainIcon = TD_ERROR_ICON;
466-
config.pszMainInstruction = Title;
467-
config.pszContent = Message;
468-
469-
if (TaskDialogIndirect(
470-
&config,
471-
&button,
472-
NULL,
473-
NULL
474-
) == S_OK)
475-
{
476-
return button;
477-
}
478-
else
479-
{
480-
return FALSE;
452+
return -1;
481453
}
482454
}
483455

0 commit comments

Comments
 (0)