views:

659

answers:

5

In C++/MFC, what's the simplest way to show a message box with a "Don't show this again" option?

In my case, I just want a simple MB_OK message box (one OK button).

+5  A: 

Probably just subclass a CDialog with a label, button(s), and a check box in the window.

If the user checks the box, then save this information in a config file that's loaded each time the application's run. Then, before calling the DoModal() method, check to see whether the user opted out.

John at CashCommons
You might also consider setting a flag in the registry (under HKEY_CURRENT_USER) to ignore the dialog for the current Windows user
John Sibly
That would be the hard way, I guess. I was looking for something already built in the framework.
djeidot
I know what to do with the option value after I retrieve it, I was thinking of using @John Sibly's suggestion.
djeidot
+4  A: 

If your on Vista and up you can use the new TaskDialog API.
Here is a sample usage with the "Don't show again" checkbox.

Shay Erlichmen
That's great, I wonder if would work well on XP...
djeidot
No, Vista and up.
Shay Erlichmen
There seem to be a lot of options, though, I just want a simple checkbox...
djeidot
+9  A: 

Or just use the SHMessageBoxCheck() function.

Stefan
Learn something new every day! Too bad they warn you that the function might not be carried forward to new versions of Windows (no mention of Vista, for instance).
Mark Ransom
@Mark This function can be easy reimplemented using TaskDialog API
Shay Erlichmen
Yes, that's exactly what I wanted!
djeidot
Warning: this works for me because I want a simple MB_OK message box. It can be more complicated if the message box has more than one button. The docs tell us not to confuse "Do not show this dialog box" with "Remember this answer".
djeidot
+1  A: 

BCGSoft has a message box with this option: http://www.bcgsoft.com/featuretour/tour255.htm

Robert
+2  A: 

Thanks for all the answers. I will add one more, although I ended up selecting @Stefan's answer for being the simplest way to do it.

Before I saw Stefan's answer, I was using XMessageBox. It had a lot of options that I didn't want, but it worked on all systems, it's worth checking. You can find XMessageBox on http://www.codeproject.com/KB/dialog/xmessagebox.aspx.

djeidot