Customized Class for MessageBox

Environment: VC6

Have you ever tried place a customized icon in a messagebox? Maybe not. This class helps you to do so. Just add the files to your existing project and add the Msgbox.h as a header to view.cpp file. That’s it, you are ready to display an icon of your choice in the MessageBox from the resources. The function name used in the project is same as the one which is used to display messagebox in Visual Basic (MsgBox) which takes 3 or 4 parameters depending on the user’s choice whether to display a customized icon or the standard ones.


//Customized class for MessageBox
//Author – Vikram Kashyap
//Created on – 10th January 2002

//Allows the user to display an icon of his own
//in the messagebox.

#include “stdafx.h”
#include “MsgBox.h”

int MsgBox( CString lpszTitle,
CString lpszText,
int nResourceID,
int nButtons)
{
MSGBOXPARAMS msgBox;
msgBox.cbSize = sizeof(MSGBOXPARAMS);
msgBox.dwStyle = MB_USERICON | nButtons;
msgBox.hInstance = AfxGetApp()->m_hInstance;
msgBox.hwndOwner = NULL;
msgBox.lpszCaption = lpszTitle;
msgBox.lpszIcon = MAKEINTRESOURCE(nResourceID);
msgBox.lpszText = lpszText;

MessageBoxIndirect(&msgBox);

return TRUE;
}

int MsgBox( CString lpszTitle,
CString lpszText,
int nButtons)
{
MSGBOXPARAMS msgBox;
msgBox.cbSize = sizeof(MSGBOXPARAMS);
msgBox.dwStyle = nButtons;
msgBox.hInstance = NULL;
msgBox.hwndOwner = NULL;
msgBox.lpszCaption = lpszTitle;
msgBox.lpszText = lpszText;

MessageBoxIndirect(&msgBox);
return TRUE;
}

Downloads

Download source – 1 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read