Hi,
I have a function that gets a wxWindow*. I need to test if the pointee is sill a valid window. Because it can happen that the window is closed by the user between saving the window pointer and calling AddPendingEvent() for this window.
Or in Short: I need a wx equavilent for the WinAPI IsWindow()
Or, as alternative: Is there a way to install some sort of global "Hook" with wich I can automatically add EventHandlers for Creation/Destruction for every created Window, so I can manage a global std::set<> of valid windows to check against.
How to check if a window is valid? Topic is solved
-
- wxWorld Domination!
- Posts: 1059
- Joined: Sun Dec 30, 2007 6:40 pm
- Location: Canada
Hi,
I suspect you have to catch the close event for the window (EVT_CLOSE) and notify the object that recorded the pointer to the window that it's being destroyed. Otherwise, the pointer will most likely point to random data.
See http://docs.wxwidgets.org/2.6/wx_window ... rview.html for the sequence regarding which deletion.
Hope that helps,
Jim
I suspect you have to catch the close event for the window (EVT_CLOSE) and notify the object that recorded the pointer to the window that it's being destroyed. Otherwise, the pointer will most likely point to random data.
See http://docs.wxwidgets.org/2.6/wx_window ... rview.html for the sequence regarding which deletion.
Hope that helps,
Jim
OS: Vista SP1, wxWidgets 2.8.7.
Another option could be to store the window id instead of the pointer and then use wxWindow::FindWindowById()
http://docs.wxwidgets.org/stable/wx_wxw ... windowbyid
http://docs.wxwidgets.org/stable/wx_wxw ... windowbyid
Use the source, Luke!
Unluckily, most of my windows are created with wxID_ANY, so I can't use the ID.
And since half of the pointee's are wxPanels in a notebook (sort of), I can't use the name either.
The other half are TopLevel windows, but sadly there is no wxWindow wich holds HWND_DESKTOP, so I also can't use wxWindow::GetChilds() to check against those.
But wait: If wx can find a window by it's ID, that means it must have a list of all windows somewhere. Maybee I can just patch in a function to check against this list.
And since half of the pointee's are wxPanels in a notebook (sort of), I can't use the name either.
The other half are TopLevel windows, but sadly there is no wxWindow wich holds HWND_DESKTOP, so I also can't use wxWindow::GetChilds() to check against those.
But wait: If wx can find a window by it's ID, that means it must have a list of all windows somewhere. Maybee I can just patch in a function to check against this list.
-
- wxWorld Domination!
- Posts: 1059
- Joined: Sun Dec 30, 2007 6:40 pm
- Location: Canada
wx keeps a list of toplevel windows, from there it searches recursively.But wait: If wx can find a window by it's ID, that means it must have a list of all windows somewhere. Maybee I can just patch in a function to check against this list.
Check wxFindWindowHelper() in /src/common/wincmn.cpp
Use the source, Luke!
-
- Experienced Solver
- Posts: 72
- Joined: Fri Feb 20, 2009 7:13 pm
- Location: $(#wx)\src
I've written my own dialog class, from wich I derive the Non-Modal Dialogs.
This class connects a wxEVT_DESTROY to the to-be-notified window, so it can set the pointer to 0, when it gets destroyed.
Also, I just can make a member PostData (const boost::any&), without any need for the derived class to check if the window still exists or not.
This class connects a wxEVT_DESTROY to the to-be-notified window, so it can set the pointer to 0, when it gets destroyed.
Also, I just can make a member PostData (const boost::any&), without any need for the derived class to check if the window still exists or not.