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

  • On-demand Event Event Date: September 10, 2014 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 how the best mobile …

  • 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 …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds