Wsprintf: String Formatting Function

Source: Internet
Author: User

Wsprintf, a common function in Win32 API, is a string Formatting Function that translates numeric values into strings in the specified format. It is similar to the printf function in C language. Its prototype is as follows:

Int wsprintf (

Lptstr lpout, // output buffer address

Lpctstr lpfmt, // format the string address

... // Variable list

The number of variable lists is specified by the formatting string. wsprintf processes the formatting string and directly copies the string to the output if a common character is encountered. If % character is encountered, there is a variable, different letters after % indicate different output formats. For example, % d indicates that the output is an integer, % x indicates that the output is hexadecimal, and % s indicates the output string.

The % symbol can be used between letters such as D, X, and s to specify the length of the bit occupied by the output. If the length of the output bit is not long enough, the function will fill in space. In addition, you can add 0 before the number indicating the bit length to indicate that "0" rather than a space is used for filling, for example, % 08x indicates the hexadecimal number filled with 0 in front of the 8-digit output.

Wsprintf is Win32
The API only has a function with an indefinite number of parameters. When using the wsprintf function, the number of parameters depends on the number specified by the "%" sign in the formatting string, the number of variable lists, and the number of formatting strings.
The % format must be one-to-one. If the letters D, x s, and so on are uppercase, the output string is uppercase.
Invoke wsprintf, ADDR szbuffer, ADDR szreceive, lparam, lparam

This statement converts the value of lparam and the string of lparam according to the format defined by szreceive formatting string, and stores the result in szbuffer. Then, the program displays the content of szbuffer in a message box:

Invoke MessageBox, hwnd, offset szbuffer, ADDR szcaptionmain, mb_ OK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.