A non-modal dialog box is more difficult to use than a modal dialog box. This is because the message loop of its parent window is blocked during the modal dialog box running, so that it can be self-contained, so it can be pleasant. However, the non-modal dialog box is only equivalent to an hwnd of the same level created by the parent form. It is like a grown-up child who can work with his or her parents. It must be managed by her parents and cannot be managed too much, its resource management and communication are more complex than those in modal mode.
In many cases, modal dialogs are used. Although Mr. copper pointed to his nose and taught us with painstaking efforts, sometimes the slack face is also thick, it doesn't matter. However, the world is always cruel. In many cases (for example, You need to respond to the form event when processing the dialog box event), we have to face the non-modal dialog box. In fact, I learned about the resource management mode, just like opening a non-Modal Dialog Box half-covering, And I can face it very calmly.
The modal dialog box contains two types of resources: memory resources and non-memory resources. The management of non-memory resources is the same as that of memory resources. In C ++, the management of memory resources requires pairing new and delete. Similarly, the management of non-memory resources requires both create and destroy inbound pairs. In this articleArticleIs a basic mode of non-modal dialog box resource management, that is, memory resource management and non-memory resource synchronization.
In this way, the usage of non-memory resources can be determined by determining whether the memory resources are occupied (that is, whether the pointer is null. If the pointer is null, the dialog box has not been created (non-memory resources are not applied). if the pointer is not empty, the dialog box has been created and is in the visible or invisible state. In this way, the two parts of resource management are merged. You only need to judge whether the pointer is null to understand the resource status of the dialog box. Some memory management methods, such as class management ideas (put Delete and destroy into class destructor), can realize automatic resource management.
To implement this management mode, pay attention to the following points:
1. allocate the memory resources of the Non-modal dialog box on the stack. The general description is not to use this method: cxxdialog t; but to use this method: cxxdialog * t = new cxxdialog (); to allocate memory.
2. synchronous construction and destructor, that is, there must be a new with a create, delete must be hooked up with a destroy.
3. The memory pointer to be deleted must be null, that is, the following two sentences will follow: delete xx; and xx = NULL ;. In fact, this is also a good habit for common memory management.
After learning about this, the non-modal dialog box will only be gentle and has no limit.