Proper way to get a wxWidgets pop-up window to dismis when the parent gets clicked?
Preface: wxWidgets 2.8.10 project on Windows.
I have a main application window (controls in a frame). If the user presses a hotkey, a pop-up window (implemented as a wxDialog) shows centered within the parent.
The behavior I want is if the user clicks outside of the pop-up window, on to the parent window, then the pop-up will dismiss, ala EndModal(wxID_CANCEL开发者_Go百科).
But if the user clicks outside the pop-up into another app, the pop-up should stay there.
Any thoughts?
What about handling EVT_KILL_FOCUS in your popup window? A click outside your window will make the window which was clicked on receive the focus.
If you want the dialog to close when the mouse is pressed outside of its screen area you need to catch the mouse clicks. Unfortunately the parent form won't receive them, as it is disabled while a modal dialog is shown. This happens on the system level, so there won't be any mouse messages sent to disabled windows in your app (actually my first idea was to use wxApp::FilterEvents()
, but it's useless for this purpose due to this).
One idea would be to use the CaptureMouse()
method, which can be used to direct all mouse events to the window having the capture, even when the mouse cursor is outside its screen area but over other windows of the application.
精彩评论