Associating ESC key with dialog button

30 views
Skip to first unread message

Kenneth Porter

unread,
Oct 18, 2022, 3:57:06 PM10/18/22
to wx-u...@googlegroups.com
I'm messing with the font size on a full-screen dialog over Remote
Desktop and the on-site user reports that the buttons to dismiss the
dialog at the bottom are off the bottom of the screen. Oops.

The dialog displays the running status of a worker thread and has two
"Stop" buttons at the bottom, one for a "graceful" stop and the other
for halting immediately (and possibly losing part of the latest
operation's data).

I'd like to allow use of the escape key as an "emergency stop" to invoke
the Stop Immediately button's function. What's the code magic to do that?

I'm using Bind in my dialog constructor:

   m_buttonStopImmediately->Bind(wxEVT_BUTTON,
&CycleStatusDialog::OnStopImmediately, this);

Igor Korot

unread,
Oct 18, 2022, 4:04:34 PM10/18/22
to wx-u...@googlegroups.com
Hi, Kenneth,
I think SetEscapeId() is what you are looking for...

Thank you.

>
> --
> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
> ---
> You received this message because you are subscribed to the Google Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/7afc2de4-2e0a-d53c-703e-01af28ce5733%40sewingwitch.com.

Kenneth Porter

unread,
Oct 18, 2022, 5:59:14 PM10/18/22
to wx-u...@googlegroups.com
On 10/18/2022 1:04 PM, Igor Korot wrote:
> I think SetEscapeId() is what you are looking for...

I think I need to re-think this. That would invoke the Close handler
which hides the dialog and ends the modal loop.

When the user hits my dialog's Stop Immediately button, the handler sets
a flag in the worker thread to tell it to exit at the next opportunity
rather than wait for a major operation to complete. (Each API call to
the hardware driver checks this flag.) The thread posts a "thread done"
event to the dialog, which then closes the window, hiding it and ending
the modal loop.

So I think I really want to intercept the Escape key as an ordinary key
and vector it away from the default Close handler.


David Connet

unread,
Oct 18, 2022, 6:04:03 PM10/18/22
to wx-u...@googlegroups.com
All you should need to do is bind to wxID_CANCEL and do what you need to
there. Binding to that will handle 'ESC', clicking the 'X'(close)
button, or the 'Cancel' button (if you have one). I think that will work
even if you haven't specifically created a Cancel button...

Dave

Reply all
Reply to author
Forward
0 new messages