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

  • When individual departments procure cloud service for their own use, they usually don't consider the hazardous organization-wide implications. Read this paper to learn best practices for setting up an internal, IT-based cloud brokerage function that service the entire organization. Find out how this approach enables you to retain top-down visibility and control of network security and manage the impact of cloud traffic on your WAN.

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there is simply not enough quality talent to go around. Tiempo Development is a nearshore software development company. Our headquarters are in AZ, but we are a pioneer and leader in outsourcing to Mexico, based on our three software development centers there. We have a proven process and we are experts at providing our customers with powerful solutions. We transform ideas into reality.

Most Popular Programming Stories

More for Developers

RSS Feeds

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