Traditionally, you would have to do this with a custom dialog and store the view setting in the registry or a file. However, last year Microsoft documented a function that does exactly what you want without the mucking around. Below is a wrapper and sample code for SHMessageBoxCheck. This page says SHMessageBoxCheck is available in shlwapi.dll version 5 and above. This means it should be available on Windows 2000/XP/ME/2003 and above and earlier platforms with IE5 or greater installed.
Code:
#include <windows.h>
/*
* This function is a wrapper for the shell function SHMessageBoxCheck.
*
* See the documentation for SHMessageBoxCheck at:
* http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/shlwapi/others/shmessageboxcheck.asp
*
* The ordinals were provided by a usenet post:
* http://groups-beta.google.com/group/microsoft.public.platformsdk.shell/msg/d638e49f001752b4
*/
int MessageBoxCheck(HWND hwnd, LPCTSTR pszText, LPCTSTR pszTitle, UINT uType, int iDefault, LPCTSTR pszRegVal)
{
typedef (WINAPI * PSHMBC) (HWND, LPCTSTR, LPCTSTR, UINT, int, LPCTSTR);
HMODULE hShlwapi = NULL;
PSHMBC shMessageBoxCheck = NULL;
int retValue = -1;
WORD ordinalSHMBC = (sizeof(TCHAR) == sizeof(WCHAR) ? 191 : 185);
hShlwapi = LoadLibrary(TEXT("shlwapi.dll"));
if (hShlwapi)
{
shMessageBoxCheck = (PSHMBC) GetProcAddress(hShlwapi, (LPCSTR) ordinalSHMBC);
if (shMessageBoxCheck)
{
/* For some reason SHMessageBoxCheck seems to require that the thread has a
* message queue to work correctly. So we call PeekMessage to force the
* creation of a message queue. */
MSG msg; PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
retValue = shMessageBoxCheck(hwnd, pszText, pszTitle, uType, iDefault, pszRegVal);
}
FreeLibrary(hShlwapi);
}
return retValue;
}
/*
* Sample showing how to use MessageBoxCheck.
* Note: You must provide a new guid before using this code in a distributed program.
*/
int main(void)
{
if (-1 == MessageBoxCheck( NULL, TEXT("Your computer is broken."), TEXT("Warning"),
MB_OK | MB_ICONEXCLAMATION, IDOK,
TEXT("{D85055F7-4AD0-49d9-9686-35F5A53B2233}") ))
{
/* If our checked box message box failed, show an ordinary message box. */
MessageBox(NULL, TEXT("Your computer is broken."), TEXT("Warning"),
MB_OK | MB_ICONEXCLAMATION);
}
}