Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a "Yes To All" Button using WinAPI?

Tags:

dialog

winapi

We have a legacy application written in C that uses WinAPI. We'd like to add a "Yes to All" button to a few of our dialog boxes. Unfortunately, the existing MessageBox function does not allow for custom buttons or button captions.

What's the best way to do so? Is there a slick hack to easily add a custom button? Or should we create our own MessageBox replacement?

like image 963
Brown Avatar asked May 04 '09 15:05

Brown


4 Answers

Something like that maybe? http://www.codeproject.com/KB/dialog/CRHYesNoToAllDialog.aspx

Or this: Using Windows Hooks to Enhance MessageBox in .NET

Marc

like image 142
marc_s Avatar answered Oct 17 '22 02:10

marc_s


There is another kind of a message box in WinAPI, since Windows 2000. It's SHMessageBoxCheck.

It allows you to display a standard MB_OKCANCEL/MB_YESNO/MB_OK-type MessageBox with the option to Never show it again, by specifying which the default option in that case is.

Maybe it's not exactly what you're looking for, but it's fairly consistent with Windows UI.

In Vista most of the shell's "Yes to all" dialogs actually work this way - there's no additional button saying "Yes/No to all" - there's a "Perform chosen action on all items" checkbox instead.

However the Note in documentation worries me:

This function is available through Microsoft Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions of Windows.

like image 27
macbirdie Avatar answered Oct 17 '22 02:10

macbirdie


You may also need to take care of the text wrapping to make it similar to MessageBox. Also MessageBox uses a different font compared to the default GUI font. And don't forget to play the sound when the dialog pops up :)

like image 2
Vishal Avatar answered Oct 17 '22 04:10

Vishal


We ended just creating our own DIALOGEX replacement resource template, then simply call DialogBox() and check the return value.

Reference: http://msdn.microsoft.com/library/ms644996(v=VS.85).aspx#modal_box

like image 1
Brown Avatar answered Oct 17 '22 04:10

Brown