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