Question

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?

Was it helpful?

Solution 4

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

OTHER TIPS

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.

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 :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top