How i can show a dialog when i press wxCLOSE_BOX Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
F
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon May 10, 2010 12:34 am

How i can show a dialog when i press wxCLOSE_BOX

Post by F »

Hello, I want to show a dialog message asking if to close or not the form (Y/N) when i press the button wxCLOSE_BOX(in the top-right of the form).
I use this:

Code: Select all

Connect(wxCLOSE_BOX,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Frame::OnQuit);

void Frame::OnQuit(wxCommandEvent& event)
{
if(wxMessageBox(wxString(_("Continue closing?"),wxString(_("Please confirm")),wxICON_QUESTION | wxYES_NO) == wxYES){
    Close();
    }
}
...The problem is:


"The dialog "not appears" when i press the x (top-right of the form) but the FORM close even."


can anyone help me please?
what i am doing bad?

...Thanks beforehand
Last edited by F on Sun May 16, 2010 1:50 am, edited 4 times in total.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Please define "doesn't work" :
1) closes the dialog even if you press no?
2) doesn't close the dialog even if you press yes?

EDIT: furthermore, the docs for "close" say :
This function simply generates a wxCloseEvent [...]. It doesn't close the window itself, however.
You probably want either Hide() or Destroy() instead (depending on whether you plan to re-use the same frame later)
"Keyboard not detected. Press F1 to continue"
-- Windows
F
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon May 10, 2010 12:34 am

Post by F »

Only i want show a dialog when i press the x (top-right frame X button named wxCLOSE_BOX)
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin »

Create & connect a handler for wxEVT_CLOSE (name it OnClose for example).
Put there the question, and if the answer is affirmative do event.Skip().
In your OnQuit just call Close().

p.s. Giving your menu wxCLOSE_BOX as its id will only confuse things. That is a flag used in a totally different way (not an id of close box or similar)... IMO you should just create a separate id for each menu (see any sample).
Yugandhan
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Mar 04, 2015 2:32 pm

Re: How i can show a dialog when i press wxCLOSE_BOX

Post by Yugandhan »

wxCLOSE_BOX is an just Style, not an id..!
Post Reply