Customized Class for MessageBox

Environment: VC6

Have you ever tried place a customized icon in a messagebox? Maybe not. This class helps you to do so. Just add the files to your existing project and add the Msgbox.h as a header to view.cpp file. That's it, you are ready to display an icon of your choice in the MessageBox from the resources. The function name used in the project is same as the one which is used to display messagebox in Visual Basic (MsgBox) which takes 3 or 4 parameters depending on the user's choice whether to display a customized icon or the standard ones.

//Customized class for MessageBox
//Author -	Vikram Kashyap
//Created on - 10th January 2002

//Allows the user to display an icon of his own 
//in the messagebox.

#include "stdafx.h"
#include "MsgBox.h"

int MsgBox( CString lpszTitle,
            CString lpszText, 
            int nResourceID,
            int nButtons)
{
  MSGBOXPARAMS msgBox;
  msgBox.cbSize = sizeof(MSGBOXPARAMS);
  msgBox.dwStyle = MB_USERICON | nButtons;
  msgBox.hInstance = AfxGetApp()->m_hInstance;
  msgBox.hwndOwner = NULL;
  msgBox.lpszCaption = lpszTitle;
  msgBox.lpszIcon = MAKEINTRESOURCE(nResourceID);
  msgBox.lpszText = lpszText;
	
  MessageBoxIndirect(&msgBox);

  return TRUE;
}

int MsgBox( CString lpszTitle, 
            CString lpszText, 
            int nButtons)
{
  MSGBOXPARAMS msgBox;
  msgBox.cbSize = sizeof(MSGBOXPARAMS);
  msgBox.dwStyle = nButtons;
  msgBox.hInstance = NULL;
  msgBox.hwndOwner = NULL;
  msgBox.lpszCaption = lpszTitle;
  msgBox.lpszText = lpszText;
	
  MessageBoxIndirect(&msgBox);
  return TRUE;
}

Downloads

Download source - 1 Kb


Comments

  • newbie

    Posted by Legacy on 07/30/2002 12:00am

    Originally posted by: Mike

    How can I get the symbol? Simply writting IDB_BITMAPxy doesn't work :(

    Reply
  • Good tip,thanks

    Posted by Legacy on 01/20/2002 12:00am

    Originally posted by: Artem

    .

    Reply
  • Good work

    Posted by Legacy on 01/18/2002 12:00am

    Originally posted by: sanjeev.k

    Good work

    Reply
  • One small change ...

    Posted by Legacy on 01/18/2002 12:00am

    Originally posted by: Thomas S�ldenwagner

    Following code :
    
    

    .
    .
    .
    MessageBoxIndirect(&msgBox);
    return TRUE;
    }


    ... shall be:

    .
    .
    .
    return MessageBoxIndirect(&msgBox);
    }

    Reply
  • Which class?

    Posted by Legacy on 01/17/2002 12:00am

    Originally posted by: Thomas Freudenberg

    Those are simple functions, but not a class.

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

Top White Papers and Webcasts

  • As mobile devices have pushed their way into the enterprise, they have brought cloud apps along with them. This app explosion means account passwords are multiplying, which exposes corporate data and leads to help desk calls from frustrated users. This paper will discover how IT can improve user productivity, gain visibility and control over SaaS and mobile apps, and stop password sprawl. Download this white paper to learn: How you can leverage your existing AD to manage app access. Key capabilities to …

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds