简体   繁体   中英

What are the differences among Top Level Window, Child window, Dialog(modal) window and non-dialog (modeless) windows?

Can any body please tell me how to distinguish among them?

I have difficulty in understanding what are the distinguishing factors for top level child windows vs dialog/non-dialog window? Can the top level window be dialog/non-dialog window? Can the child window be dialog/non-dialog window?

Top-level forms are owned by the desktop, whereas child forms belong to another form; this means that closing or minimising the owning form will also affect the child form.

Modal forms/dialogs block the calling thread until the form is closed, whereas modeless forms allow you to interact with other forms in the application while shown. Any form can be modal/modeless, regardless of whether it is a top-level or child form - however the default behaviour for modal dialogs is to be owned by the form that caused them to be shown.

From MSDN :

Modal

A modal form or dialog box must be closed or hidden before you can continue working with the rest of the application.

Modeless

Modeless forms let you shift the focus between the form and another form without having to close the initial form.

A top-level window can be either modal (dialog) or modeless.

A top-level window is owned by the desktop, thus it cannot be a child of a parent form.

A child window, owned by a parent form, is not a top-level form, because it has a parent. But it can be on top in the Z order , and can be modal or modeless depending on how it is displayed, with either ShowDiaglog() or Show() respectively.

Top Level Window: The windows which are not owned by any other windows and hence they govern their own lifetime. Example Notepad window

Child window: The windows which are owned by some other window. This other window itself could be Top-level or Child. Example Edit box or status bar of Notepad, so if you close Notepad window edit box, status bar etc windows are gone.

Modal window: The window which blocks current threads execution until it is alive. If it is a child window then any interaction with its parent window will be blocked. Example Font dialog box of Notepad, if you open Font window, you can not type anything on Notepad window.

Modeless windows: The window which doesnt block current thread's execution when it is alive so if it is a child window it allows you to interact with its parent. example Find dialog box of Notepad, if you press Ctrl+F and open Find window, then you can put it aside and continue typing on main Notepad window.

Important point, a window can either be Child or Top level but cannot be both.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM