Message Box with printf capability

This is a small utility funtion will simply put up a userdefined message box with a string formatted like printf().

Example:


int MsgBox(UINT nType, PSTR sz,...)
{ 
    char ach[512];
    va_list args; 
    va_start(args, sz); 
    wvsprintf (ach, sz, args); /* Format the string */
    int retval = AfxMessageBox (ach, nType == 0 ? MB_OK|MB_ICONEXCLAMATION : nType);
    
    return retval;
}


void main(int argc, char *argv[])
{
  MsgBox(MB_OK|MB_ICONINFORMATION, "There are %ld commandline parameters - parameter one is %s", argc, argv[1]);
}

 

Last updated: 15 May 1998


Comments

  • You forgot to call va_end()

    Posted by Passmaster on 03/25/2004 04:15pm

    Once you are done, you have to call va_end()
    Just add 
    va_end( args );
    after the call to wvsprintf()

    Reply
  • use _vsnprintf

    Posted by Legacy on 07/22/1999 12:00am

    Originally posted by: Olan Patrick Barnes

    If you aren't worried about portability, Microsoft VC has _vsnprintf which allows you to detrmine the max # of characters to put into the string. vsprintf and sprintf and the like do no error checking to see if they have spilled over the buffer size, which if it does will crash your program.

    Reply
  • replace wvsprintf with vsprintf

    Posted by Legacy on 04/11/1999 12:00am

    Originally posted by: XuYifeng

    wvsprintf does not support float and double,
    can you replace wvsprintf with vsprintf ?

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

Top White Papers and Webcasts

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds