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

  • Do you spend a lot of time thinking about your enemies? Attacker attribution - figuring out who's out to get you - is one of the most important things an organization can do to protect itself.  Because you have no hope of defending yourself if you don't understand who the attackers are. Good news? Every organization isn't targeted by all the attackers. Bad news? No one can identify your potential attackers as well as you. Read this graphics-rich threat summary for 2014 to determine who might be your next …

  • Cloud computing isn't new, but it's still a hot topic in technology circles. Moving to the cloud has done great things for many businesses. When it comes to handling a basic business necessity, cloud computing has brought many improvements to overall business continuity. Using the cloud for DR makes a lot of sense for many, but it's not exactly the most simple concept. Read this eBook to find answers to all the key questions IT professionals have about cloud-based disaster recovery, and helpful info around the …

Most Popular Programming Stories

More for Developers

RSS Feeds

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