Duilib the child window is destroyed when the child window is created in the

Source: Internet
Author: User

When learning Duilib, learn the right-click menu in the Listdemo, and then when the menu is clicked alive loses focus, how the menu window destroys the problem.

1. Here, the concept of child window is used when creating the menu, when it is created, the Ws_ex_toolwindow type is used, which means that it is a toolbar window.

2, this menu window has its own message processing function handlemessage. The first attempt was to call the close function in Cwindowwnd, see the source of the function, and find out that it was using postmessage to send itself a WM_CLOSE message and then intercept the WM_CLOSE message in Handlemessage. PostQuitMessage (0) was called in the message handler, in which case the menu window was exited, but the parent window was also exited. Because getmessage in Cpaintmanager messageloop returns 0 when a message is received Wm_quit, the while loop in Messageloop is broken. The entire message loop exits, so the entire program exits

3, the second attempt is to call PostQuitMessage (0) Directly when the menu item is selected and the menu window loses focus, because the first attempt is the same as the action, and therefore has failed.

4, because of the previous two failures, and then on-line various queries have not found the relevant solution. Later, when viewing MSDN, I looked at the remark of the message wm_close, which said, "The application handles WM_CLOSE messages, can do some hints to the user before the window is destroyed, and if the user confirms the prompt, by calling Destorywindow to Ecstasy window." Therefore, the code is modified based on this foundation and the 12th attempt. First, call the close function of Cwindowwnd when the menu item is selected and the menu window loses focus, and then intercept the WM_CLOSE message in the window's message handler, WM_ The close message handler uses Destorywindow to achieve the purpose of destroying the menu window, and then calls delete this to delete the form itself after the Destorywindow is called. This has achieved the effect.

Of course, in the completion of the 4th step, also encountered some other small trouble, a little debugging is completed. It also has some new experience on the window application programming.

Duilib the child window is destroyed when the child window is created in the

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.