How to Hide a wxFrame using "X" (Close Window) button Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
ColleenKobe
Experienced Solver
Experienced Solver
Posts: 96
Joined: Mon Aug 31, 2015 3:47 pm

How to Hide a wxFrame using "X" (Close Window) button

Post by ColleenKobe » Wed May 05, 2021 4:59 pm

Hi. I have a wxFrame window I would like to close using the "X" in the upper right corner. However, I don't want to delete the window. I just want to turn it off, as in the code snippet below.

Code: Select all

void    Processing_Monitor_Class::pm_Update_Show    (bool   Off_or_On)
{
    Local_PM_ptr->Show                              (Off_or_On);
    Local_MF_ptr->mf_Set_m_menu_View_X_Page_Check   (gdb_Processing_Monitor_Page, Off_or_On);
}   //  pm_Update_Show
The window is displayed when a checkable menu item is selected, and the checkmark preceding the menu item text is updated appropriately: If the menu item is unchecked, then the window is shown. If the menu item is checked, then the window is hidden. Example: View, Processing Page.

Checking and unchecking the menu item shows and hides the page correctly. Clicking the "cancel" or "close" buttons that are also on the page also works correctly.

But when I close using the "X", and then try to show the page by clicking the menu item, the program hangs. Hangs as in I have to close the program in CodeLite.

I think the problem is that the "X" generates a wxEVT_CLOSE_WINDOW, not a wxEVT_COMMAND_BUTTON_CLICKED (like the menu item and the cancel button event do). If I close the displayed window using the "X", the next time I click the menu item, the program hangs. I don't know why. The pointer to the class is not null.

Or maybe the problem is that wxDialogs and wxFrames behave differently when the X is clicked.

Here is my code.

Code: Select all

void    Processing_Monitor_Class::OnClose_Window(wxCloseEvent& event)
{
    event.Skip ();
    Local_PM_ptr->pm_Update_Show    (false);
}   //  OnClose_Window
I even tried to remove OnClose_Window and not have ANY event procedure run when the user clicks "X". I rebuilt the whole workspace. Program still hung.

Suggestions?

For what it's worth: I use similar code in a wxDialog that operates the same way. The operation works correctly: clicking the X hides the window, and clicking the menu item restores the window.

Interestingly, there IS no wxCloseEvent in the wxDialog.

I dread recreating this page as a wxDialog, because I have two other windows with the same problem that are wxFrames and I'd have to recreate them, too. But I will if I have to.

Colleen

Operating System: Windows 10
Target operating system: Windows 10
CodeLite version 14.0.0
wxCrafter version 2.9
wxWidgets, don't know how to find out what version
MinGw, don't know how to find out what version

User avatar
doublemax
Moderator
Moderator
Posts: 16026
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to Hide a wxFrame using "X" (Close Window) button

Post by doublemax » Wed May 05, 2021 5:23 pm

Code: Select all

event.Skip ();
Remove this. If you call event.Skip(), it means that the default event handler gets executed, too. And the default close event handler for a wxFrame destroys it.

The name of the Skip() method is not very clear, imagine it to be ContinueProcessing().
Use the source, Luke!

User avatar
ColleenKobe
Experienced Solver
Experienced Solver
Posts: 96
Joined: Mon Aug 31, 2015 3:47 pm

Re: How to Hide a wxFrame using "X" (Close Window) button

Post by ColleenKobe » Wed May 05, 2021 5:39 pm

Hallelujah! Thank you, doublemax!!! What a refreshingly easy fix! Works perfectly now.

Thank you so much!!!

Colleen

jpo234
Knows some wx things
Knows some wx things
Posts: 45
Joined: Tue Feb 25, 2020 11:34 am

Re: How to Hide a wxFrame using "X" (Close Window) button

Post by jpo234 » Wed May 05, 2021 6:11 pm

doublemax wrote:
Wed May 05, 2021 5:23 pm

Code: Select all

event.Skip ();
Remove this. If you call event.Skip(), it means that the default event handler gets executed, too. And the default close event handler for a wxFrame destroys it.

The name of the Skip() method is not very clear, imagine it to be ContinueProcessing().
Maybe Skip() should be deprecated in favor of ContinueProcessing()...

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5156
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to Hide a wxFrame using "X" (Close Window) button

Post by ONEEYEMAN » Wed May 05, 2021 8:20 pm

Hi,
Most likely this will never going to happen for historic purposes...

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 16026
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to Hide a wxFrame using "X" (Close Window) button

Post by doublemax » Wed May 05, 2021 10:17 pm

ONEEYEMAN wrote:
Wed May 05, 2021 8:20 pm
Most likely this will never going to happen for historic purposes...
Vadim has more powerful solutions in mind: https://groups.google.com/g/wx-users/c/ ... 7rCZGkBgAJ
Use the source, Luke!

Post Reply