One-day Windows API training (17) dialogbox and dialogboxparam Functions

Source: Internet
Author: User
A dialog box is a common window. For example, you can use a dialog box when you want users to enter some parameters. You can also use the dialog box to prompt some warning information. For example, when you copy an object, a dialog box indicating the progress of copying the object is displayed in windows. The dialog box is widely used, and the running result is displayed during design, which facilitates the design. There are two types of dialog boxes. After a dialog box is run, you must close the dialog box before returning it to the parent window; in a dialog box, you can directly return to the parent window without closing the window. Therefore, software developers should consider whether the result of this dialog box will affect subsequent operations. If the result of this dialog box does not have a causal relationship with subsequent operations, you can set it to the second dialog box. A dialog box similar to a copy object is a second type of dialog box, called a non-modal dialog box. If it is set to the first type, you have to wait for the file to be copied to operate on other things, so windows is not easy to use, which will waste a lot of time. It is a poor software. Therefore, when designing software, software developers must stand on the user's standpoint and think about the problem. When keeping the software correct, do not wait, any software that has been waiting for more than 20 seconds can upset users. If you have to wait, you also need to add a prompt in the progress bar dialog box, which can effectively ease the user's fidgety mood. This is the same as when you go to the bank to queue up, you can sit there and watch TV. It doesn't feel like a long time.

The dialogbox and dialogboxparam functions are declared as follows:
# Define dialogboxa (hinstance, lptemplate, hwndparent, lpdialogfunc )/
Dialogboxparama (hinstance, lptemplate, hwndparent, lpdialogfunc, 0l)

# Define dialogboxw (hinstance, lptemplate, hwndparent, lpdialogfunc )/
Dialogboxparamw (hinstance, lptemplate, hwndparent, lpdialogfunc, 0l)

# Ifdef Unicode
# Define dialogbox dialogboxw
# Else
# Define dialogbox dialogboxa
# Endif //! Unicode

Winuserapi
Int_ptr
Winapi
Dialogboxparama (
_ In_opt hinstance,
_ In lpcstr lptemplatename,
_ In_opt hwnd hwndparent,
_ In_opt dlgproc lpdialogfunc,
_ In lparam dwinitparam );

Winuserapi
Int_ptr
Winapi
Dialogboxparamw (
_ In_opt hinstance,
_ In lpcwstr lptemplatename,
_ In_opt hwnd hwndparent,
_ In_opt dlgproc lpdialogfunc,
_ In lparam dwinitparam );

# Ifdef Unicode
# Define dialogboxparam dialogboxparamw
# Else
# Define dialogboxparam dialogboxparama
# Endif //! Unicode
HinstanceIs the instance handle of the current application.
LptemplatenameIs the resource template of the dialog box.
HwndparentIs the handle of the parent window.
LpdialogfuncIs the message processing function of the dialog box.
DwinitparamIs the initialization parameter. The default value is 0.

An example of calling this function is as follows:
#001 //
#002 // purpose: to process messages in the main window.
#003 //
#004 // Cai junsheng 2007/07/12 QQ: 9073204
#005 //
#006 lresult callback wndproc (hwnd, uint message, wparam, lparam)
#007 {
#008 int wmid, wmevent;
#009 paintstruct pS;
#010 HDC;
#011
#012 switch (Message)
#013 {
#014 case wm_command:
#015 wmid = loword (wparam );
#016 wmevent = hiword (wparam );
#017 // menu option command response:
#018 switch (wmid)
#019 {
#020 case idm_about:
#021Dialogbox (hinst, makeintresource (idd_aboutbox), hwnd, about );
#022 break;
#023 case idm_exit:
#024 destroywindow (hwnd );
#025 break;
#026 default:
#027 return defwindowproc (hwnd, message, wparam, lparam );
#028}
#029 break;
#030 case wm_paint:
#031 HDC = beginpaint (hwnd, & PS );
#032 //
#033 endpaint (hwnd, & PS );
#034 break;
#035 case wm_destroy:
#036 postquitmessage (0 );
#037 break;
#038 default:
#039 return defwindowproc (hwnd, message, wparam, lparam );
#040}
#041 return 0;
#042}
Row 3 calls the dialogbox function to display the dialog box window.

The dialog box template is as follows:
//////////////////////////////////////// /////////////////////////////////////
//
// Dialog
//

Idd_aboutbox dialogex 22, 17,230, 75
Style ds_setfont | ds_modalframe | ws_caption | ws_sysmenu
Caption "about"
Font 9, "" ", 400, 0, 0x86
Begin
Icon idi_testwin, idc_myicon
Ltext "testwin version 1.0", idc_static, 49,10, 119,8, ss_noprefix
Ltext "Copyright (c) 2007", idc_static, 8
Defpushbutton "OK", idok, 185, 51, 38,16, ws_group
End

Idd_aboutbox is the name of the dialog box template.
Dialogex is the keyword defined in the dialog box.
22, 17,230, and 75 are the coordinates and sizes of the dialog box.
Style is the display type of the Set dialog box.
Caption is the title name. Here is "about ".
Font is the font that defines the dialog.
Icon is to define an icon display.
Ltext is the definition of displaying static text.
Defpushbutton defines a button.

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.