I want to notify the user that my application wants to start an elevated process using the standard MessageBox
. Is there a way of achieving this short of reimplementing the MessageBox
?
For example, for standard buttons, you can send the BCM_SETSHIELD
message. Is there something similar for message boxes?
In order to get the shield icon onto the buttons of a system provided message dialog you are going to need to handle a callback from the dialog.
For example, I will illustrate with the TaskDialogIndirect()
API introduced in Vista.
The basic dialog allows you to specify the main icon, but not the shield icon for the buttons on the dialog. To do this you need to provide a callback function that responds to the TDN_CREATED
notification.
That callback might look like this:
HRESULT CALLBACK TaskDialogCallbackProc(
HWND hwnd,
UINT uNotification,
WPARAM wParam,
LPARAM lParam,
LONG_PTR dwRefData
)
{
if (TDN_CREATED == uNotification)
{
SendMessage(
hwnd,
TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE,
ID_FOR_MY_BUTTON_SPECIFIED_IN_TASKDIALOGCONFIG_STRUCT,
1
);
}
return S_OK;
}
The magic is contained in the TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE
message.
As far as I can tell, this is the way you are intended to achieve the effect you desire.
Buttons in a message dialog are standard buttons, you can send them a BCM_SETSHIELD
message.
For this, you need to be aware when a message dialog box is activated. One way can be to set a temporary WH_CBT
hook and in its callback watch for an 'nCode' of HCBT_ACTIVATE
for a window having the dialog class (#32770).
Another way can be to handle WM_ACTIVATE
after 'MessageBox' is called, 'wParam' should be WA_ACTIVE
and 'lParam' should be a window handle again of the dialog class. Then you can send the 'BCM_SETSHIELD' message to the button f.i. having control id IDOK
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With