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

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds