How to add a UAC screen icon to a standard message box?

I want to notify the user that my application wants to start an elevated process using the standard MessageBox . Is there a way to achieve this so as not to override the MessageBox ?

For example, for standard buttons, you can send the message BCM_SETSHIELD . Is there something similar for message boxes?

+4
source share
2 answers

The buttons in the message dialog are standard buttons, you can send them a message BCM_SETSHIELD .

To do this, you need to know when the message dialog is activated. One way could be to set a temporary WH_CBT and in its callback see "nCode" HCBT_ACTIVATE for a window that has a dialog class (# 32770).

Another way could be to handle WM_ACTIVATE after calling 'MessageBox', 'wParam' should be WA_ACTIVE and 'lParam' should be a window class handle to the dialog class. Then you can send the message "BCM_SETSHIELD" to the fi button with the IDOK control identifier.

messsage box with shielded button

+5
source

To get the screen icon on the buttons of the dialog box with the system message, you need to process the callback from the dialog.

For example, I will illustrate using the TaskDialogIndirect() API introduced in Vista.

In the basic dialog box, you can specify the main icon, but not the screen icon for the buttons in the dialog box. To do this, you need to provide a callback function that responds to the TDN_CREATED notification.

This 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, so you intend to achieve the desired effect.

+8
source

Source: https://habr.com/ru/post/1344249/


All Articles