One-day Windows API training (4) MessageBox Function

Source: Internet
Author: User
To display the prompt information to users, Windows provides a very convenient API function MessageBox for users to use. Using this API function, you can display simple text information, remind or remind the user to perform the next step.
The function declaration is as follows:
Winuserapi
Int
Winapi
Messageboxa (
_ In_opt hwnd,
_ In_opt lpcstr lptext,
_ In_opt maid,
_ In uint utype );
Winuserapi
Int
Winapi
Messageboxw (
_ In_opt hwnd,
_ In_opt lpcwstr lptext,
_ In_opt maid,
_ In uint utype );
# Ifdef Unicode
# Define MessageBox messageboxw
# Else
# Define MessageBox messageboxa
# Endif //! Unicode
From the above we can see that Windows APIs are two types of declarations, one is to use ANSI encoding, and the other is to use unicode encoded API functions. Use macro definition to unify the two API names to the MessageBox statement. This is a technology that uses different APIs. In future programming, most of them need to use Unicode encoding, because it can adapt to the display of languages in different countries and can be programmed internationally, unicode programming is especially required for Chinese support.
The following describes the parameter definitions:
HwndIs the handle pointing to the parent window. If there is no parent window, you can set this parameter to null.
LptextIs the text to be displayed. The start address of the string.
LpcaptionIs displayed in the title of the window.
UtypeIs the type of window combination buttons and display icons. It will be detailed later.
Return ValueIt is an integer. If the cancel button exists and the ESC key is pressed, idcancel is returned. If there are other buttons and you press them, the corresponding value is returned. The main values are as follows:
Idabort discard button
Idcancel cancel button
Idcontinue continue button
Idignore ignore button
IDNO no button
Idok OK button
Idretry Retry button
Idtryagain Retry button
Idyes is the button
 
An example is as follows:

Download(71.85 KB)

The code shown above is:
#001 // mb_defbutton4
#002 int cmsgbox: show_mb_defbutton4 (void)
#003 {
#004 // display mb_defbutton4.
#005 return: MessageBox (null, _ T ("mb_yesnocancel | mb_defbutton4 | mb_help "),
#006 _ T ("first application"), mb_yesnocancel | mb_defbutton4 | mb_help | mb_iconquestion );
#007}
 
UtypeThe common options are as follows:
Button type:
Mb_abortretryignore
Mb_canceltrycontinue
Mb_help
Mb_ OK
Mb_okcancel
Mb_retrycancel
Mb_yesno
Mb_yesnocancel
 
Icon type:
Mb_iconexclamation
Mb_iconwarning
Mb_iconinformation
Mb_iconasterisk
Mb_iconquestion
Mb_iconstop
Mb_iconerror
Mb_iconhand
 
Set the default button value:
Mb_defbutton1
Mb_defbutton2
Mb_defbutton3
Mb_defbutton4
 
Modify the properties of the display information window:
Mb_applmodal
Mb_systemmodal
Mb_taskmodal
Mb_right
Mb_rtlreading
Mb_setforeground
Mb_topmost
Mb_service_notification

Related Article

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.