How i can show a dialog when i press wxCLOSE_BOX  [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.
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

Postby F » Sun May 16, 2010 12:47 am

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:

Postby Auria » Sun May 16, 2010 12:58 am

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

Postby F » Sun May 16, 2010 2:15 am

Only i want show a dialog when i press the x (top-right frame X button named wxCLOSE_BOX)

catalin
Moderator
Moderator
Posts: 1455
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

  [SOLVED]

Postby catalin » Sun May 16, 2010 3:49 am

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

Postby Yugandhan » Thu Mar 05, 2015 11:27 am

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


Return to “Component Writing”

Who is online

Users browsing this forum: No registered users and 2 guests