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

  • Following an IT incident through to resolution is more than just acknowledging an alert and restarting a server. The recent State of On-Call Report found that it takes most companies an average of 10-30 minutes to resolve an incident with an average of 5 people involved. Imagine how much money and time companies are spending to deal with incident resolution. But what if you had a tool that offered solutions baked in? Or a tool that sent alerts to the right person or team every time? These are the kind of …

  • Organizations are increasingly gravitating toward mobile-first application development as they assess the need to revamp their application portfolios to support touch computing and mobility. Consumerization has brought higher expectations for application usability along with the mobile devices themselves. Enterprises are increasingly shifting their new application acquisitions and development efforts toward mobile platforms. With this backdrop, it is natural to expect application platform vendors to invest in …

Most Popular Programming Stories

More for Developers

RSS Feeds

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