MessageBox Visual Studio Add-In

Environment: Visual Studio 6

How many times have you had to go through the same gyrations to create a message box? Is it the first argument or the second that's the title as opposed to the text. What are the exact constants again for an OK button and a Cancel button? What are the valid return values? Well no more! This very useful add-in saves you from having to remember that from now on! Using this add-in, you can visually set any of the following:

  • Icon type
  • Buttons
  • Caption (notice the built-in values provided for you!)
  • Text message
  • Modality
  • Default button
  • You can even specify the conditional expression!
When you're finished selecting your settings, simply click the "Copy to Clipboard and Close" button. You'll be returned to your previous source window. Just paste the code from the clipboard and you're done!


Using the settings shown in the figure above, the add-in produced the following!
if(MessageBox(_T("This is an Error Message !!!\nReturn ?"), 
               == IDNO)

Installing the Add-In

To install the add-in, follow these steps:
  1. Download the DLL (remember to unzip the file) or download the source and build the DLL
  2. Copy the DLL to the Visual Studio AddIn folder (the default location is the
  3. c:\program files\microsoft visual studio\Common\MSDev98\AddIns' folder).
  4. Click the Tools->Customize menu option
  5. Click the Add-ins and Macro Files tab
  6. Check the "MsgBox Developer Studio Add-In" add-in
  7. Now you can assign it to a key or place it on a toolbar as you like


Download MsgBox Add-In - 17 Kb
Download source - 47 Kb


  • Can these be used with VS.Net

    Posted by Legacy on 09/12/2002 12:00am

    Originally posted by: AndyC

    This is a great help, but can they be used with VS.Net.
    I hope so.


  • Nice Work, I have an improvement

    Posted by Legacy on 03/24/2002 12:00am

    Originally posted by: Nathan Schultz

    This is a great add-in, thanks for sharing it.

    I have a minor improvement that handles the if-then-else case better if the user chooses Abort-Retry-Ignore or Yes-No-Cancel. Replace the CMsgDlg::CreateCode function with the following code.

    Thanks again,

    Nathan Schultz

    void CMsgDlg::CreateCode(CString& csResult)
    UINT uiStyle=0;
    CString csCode(_T(""));
    CString csStyle(_T(""));
    CString csSpace;

    SetSymbol(uiStyle, csStyle);
    SetButtons(uiStyle, csStyle);
    SetDefButton(uiStyle, csStyle);
    csStyle.SetAt(0, ' ');

    case bcNo:
    csSpace = _T(" ");

    case bcIf:
    case bcIfThenElse:
    csSpace = _T(" ");
    if (m_iButtons == bbAbortRetryIgnore || m_iButtons == bbYesNoCancel)
    csCode += "int l_nRet = ";
    csCode += _T("if(");

    case btGeneric:
    csCode += _T("::MessageBox(NULL, ");

    case btCWnd:
    csCode += _T("MessageBox(");

    case btAfx:
    csCode += _T("AfxMessageBox(");

    csCode += _T("_T(\"");

    CString csMsg(m_csMsg);
    csMsg.Replace(_T("\r\n"), _T("\\n"));
    csCode += csMsg;

    csCode += _T("\")");

    csCode += _T(", ");

    if(m_iType != btAfx)
    csCode += _T("\r\n") + csSpace;
    csCode += _T("_T(\"");

    csCode += m_csCaption;

    csCode += _T("\"),");

    csCode += _T("\r\n") + csSpace;
    csCode += csStyle;
    csCode += ')';

    int iReturn=0;
    CString csReturn(_T(""));
    SetReturn(iReturn, csReturn);

    if(m_iCondition == bcIfThenElse && (m_iButtons == bbAbortRetryIgnore || m_iButtons == bbYesNoCancel))
    csCode += _T(";\r\nif (l_nRet ");
    csCode += _T("\r\n") + csSpace;
    csCode += csReturn;
    csCode += _T(")\r\n{\r\n}");

    if(m_iCondition == bcIfThenElse && (m_iButtons == bbAbortRetryIgnore || m_iButtons == bbYesNoCancel))
    csCode += _T("\r\nelse if (l_nRet == )\r\n{\r\n}");

    if(m_iCondition == bcIfThenElse)
    csCode += _T("\r\nelse\r\n{\r\n}");
    csCode += ';';

    csResult = csCode;

  • Test Dialog font bug

    Posted by Legacy on 10/17/2001 12:00am

    Originally posted by: Kestas

    Very usefull code. Thanks.

    In CViewDlg function OnInitDialog() font must be created with size of 120 (12 pt):

    m_cf.CreatePointFont(120, _T("Courier"));

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • By providing developers with the right tools to detect, understand, and fix problems early, your business can simplify software development, shorten development lifecycles, and improve the quality of software code. The end result is increased innovation, secure applications, and a faster time to market — all at a lower cost.

  • On-demand Event Event Date: September 23, 2015 The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this webcast to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code reviews, build automation, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date