How to check if a frame is alive?

830 views
Skip to first unread message

Nicholas Andrews

unread,
Jul 9, 2004, 11:37:18 AM7/9/04
to wx-u...@lists.wxwidgets.org
I have an application with several frames, one "main" one and two
optional ones. I want the main one to be able to open the optional
windows and close them. For this, I need to know if these windows are
alive so I don't open the same one twice or try to close something that
doesn't exist. I first tried just testing for a NULL pointer, but that
didn't work. Is there a function to call to see if a window exists, or
some other way? Also, does anyone know what event is called when a
window is closed by clicking the "X"?

Thanks,
Nick

li...@safish.com

unread,
Jul 9, 2004, 12:11:38 PM7/9/04
to wx-u...@lists.wxwidgets.org
Are you using the Close() or Destroy() when you're closing the window?
>From the documentation, Close() does not guarantee that the window will be
destroyed - use Destroy() instead if you want to be certain the object is
cleaned up.

Depending on how much memory your child screens use though, you might want
to consider not destroying them once they have been created, and if they
have to be shown again just setting them to visible. They'll load quicker
and retain the user settings from when the user last saw the screen.

EVT_CLOSE is called when you close a window.

Cheers
Matt

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
> For additional commands, e-mail: wx-use...@lists.wxwidgets.org
>
>


Jon Bennett

unread,
Jul 9, 2004, 3:06:02 PM7/9/04
to wx-u...@lists.wxwidgets.org
Two options:
1) If you are going to keep the pointer, then put a member
variable in the frames that can go away that points to
your frame that keeps them. Then, whenever they are
closed, they can tell the main frame that they are closing.
That way you can null out the pointer that you are
keeping and know that the frame is gone.

2) Instead of keeping a pointer to the frame when
you know that it can go bad when the frame closes,
keep member variables containing a unique string
for each frame. Perhaps a numeric string created
from the frames address. When you create a frame,
create the name and call "SetName" for the new
frame. Once each frame has a name you can use the
wxWindow funciton
wxWindow::FindWindowByName

and it will return a wxWindow *, or
NULL if the frame does
not exist.

---
Jon

Otto Wyss

unread,
Jul 9, 2004, 5:11:42 PM7/9/04
to wxWidgets-User
There doesn't seems to be an event which signals when a frame is closed
(I haven't found any). Therefore I do it this way
"http://wxguide.sourceforge.net/guidelines/basics.html#multiple" or look
into the Demo sample "http://wxguide.sourceforge.net/indexdemo.html".

O. Wyss

--
See wyoEditor at "http://freshmeat.net/projects/wyoeditor/"

Robin Dunn

unread,
Jul 14, 2004, 7:03:12 PM7/14/04
to wx-u...@lists.wxwidgets.org
Otto Wyss wrote:
>>I have an application with several frames, one "main" one and two
>>optional ones. I want the main one to be able to open the optional
>>windows and close them. For this, I need to know if these windows are
>>alive so I don't open the same one twice or try to close something that
>>doesn't exist. I first tried just testing for a NULL pointer, but that
>>didn't work. Is there a function to call to see if a window exists, or
>>some other way? Also, does anyone know what event is called when a
>>window is closed by clicking the "X"?
>>
>
> There doesn't seems to be an event which signals when a frame is closed
> (I haven't found any).

Is EVT_CLOSE what you ar elooking for? See wxCloseEvent docs.


--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Reply all
Reply to author
Forward
0 new messages