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!

Example

Using the settings shown in the figure above, the add-in produced the following!
if(MessageBox(_T("This is an Error Message !!!\nReturn ?"), 
              _T("Error"),
               MB_ICONHAND|MB_YESNO|MB_DEFBUTTON1)
               == 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

Downloads

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


Comments

  • 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.

    Cheers

    Reply
  • 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, ' ');

    switch(m_iCondition)
    {
    case bcNo:
    csSpace = _T(" ");
    break;

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

    switch(m_iType)
    {
    case btGeneric:
    csCode += _T("::MessageBox(NULL, ");
    break;

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

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

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

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

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

    csCode += _T(", ");

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

    csCode += m_csCaption;

    if(m_bCaptionVar)
    csCode += _T("\"),");
    }

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

    if(m_iCondition)
    {
    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 ");
    else
    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}");
    }
    else
    {
    csCode += ';';
    }

    csResult = csCode;
    }

    Reply
  • 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"));

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

Top White Papers and Webcasts

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds