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

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • Hurricane Sandy was one of the most destructive natural disasters that the United States has ever experienced. Read this success story to learn how Datto protected its partners and their customers with proactive business continuity planning, heroic employee efforts, and the right mix of technology and support. With storm surges over 12 feet, winds that exceeded 90 mph, and a diameter spanning more than 900 miles, Sandy resulted in power outages to approximately 7.5 million people, and caused an estimated $50 …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds