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

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds