Create and use the fourth dialog box

Source: Internet
Author: User

The dialog box is divided into modal dialog box and non-modal dialog box. The modal dialog box means that the parent window can be deleted only after it is destroyed.

The operation dialog box. This is not required for non-modal mode. This blog post will introduce the resource definition and usage of the modal dialog box.

.

 

I. Basic Knowledge

The dialog box is mainly used to interact with users. Its existence can make the main window more concise. The dialog box is also based on

Window. However, Windows encapsulation makes creating a dialog box much easier than creating a window.

Let's take a look at the similarities and differences between the create window, modal dialog box, and non-modal dialog box:

You can find the following points:

1. The create dialog box does not require registration classes, and you do not need to call the functions for creating, displaying, and refreshing windows.

2. Custom message loops are required for normal windows and non-modal dialogs, while modal dialogs are not required.

3. the dialog box calls the dialog box process more indirectly.

4. The dialogboxparam function is used to create a modal dialog box, And the createdialogparam function is used to create a non-modal dialog box.

 

2. Define resources and use dialog box

It can be seen that the create dialog box only calls dialogboxparam. In addition, for messages that require special processing

It must be processed in the Custom dialog box.

Is it like what we mentioned above? Yes, but not enough for programming!

Next, let's see:

First, the dialog box exists as a resource. Therefore, you must define the dialog box in the resource file. This is equivalent to defining

The template of the dialog box, and the resource definitions of the modal and non-modal dialog boxes are no different. The difference is that different functions are called during creation.

Secondly, we can see the create mode dialog box. In Windows, we have built a built-in message loop and a built-in window.

Process. When dialogboxparam is called, this function will not be returned until the dialog box is destroyed. In addition

The dialog template in the resource file is also specified. In Windows, the dialog box is created based on the template. We do not need to care about it here.

; Create a modal dialog box until the destruction function is returned; dlg_main is the dialog box invokedialogboxparam, hinstance, dlg_main, \ null, offset _ procdlgmain, null

 

(1) dialog box resource Definition

1,

Dialog Box ID dialog [discardable] x coordinate, Y coordinate, width, height

[Optional attributes]

Begin

Subwindow Control

End

The optional attributes include the title text, window style, and font. Child Window controls include icons and buttons.

 

2. Instance

# Include <resource. h> # defineico_main0x1000 # definedlg_main1 // define the icon ico_mainicondiscardable "Main. ICO "// definition dialog box ‑, 50,113, 63 // dialog box attribute definition stylews_visible | ws_caption | ds_modalframe | ws_sysmenucaption" dialog "font9," "// subwindow control definition beginiconico_main, -, 21 ctext "dialog example \ nby lulipeng",-, 19 defpushbutton "exit (& X)", idok, 58,46, 50,14 control "", -1, "static", ss_etchedhorz | ws_child | ws_visible, 6, 39, 103, 1end

 

(2) Use

1. Specify the resource in the parameter of the dialogboxparam function.

2. Instance

386. modelflat, stdcalloptioncasemap: noneincludewindows. incincludeuser32.incincludelibuser32. libincludekernel32.incincludelibkernel32. libico_mainequ1000hdlg_mainequ1.data? Hinstancedd ?. Code_procdlgmainprocuses ebx edi esi hwnd, umsg, wparam, lparammoveax, umsg. ifeax = wm_close; in the dialog box, use enddialog to destroy invokeenddialog, hwnd, and null. elseifeax = wm_initdialog; set the icons invokeloadicon, hinstance, ico_maininvokesendmessage, hwnd, wm_seticon, icon_small, and eax. elseifeax = wm_commandmoveax, wparam. ifax = idokinvokeenddialog, hwnd, null. endif. else; the custom dialog box does not process messages. To send messages to the; dialog box manager, return false; otherwise, return truemoveax, falseret. endifmoveax, role: invokegetmodulehandle, nullmovhinstance, eax; create a modal dialog box and return the result until the destroy function is displayed. dlg_main is the dialog box in the resource file, such as begin, hinstance, dlg_main, \ null and offset, nullinvokeexitprocess, nullendstart

 

3. Download the "Main. ICO" icon in the code
Main. ICO

 

Iv. Code running result

 

 

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.