Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 984507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:01:39+00:00 2026-05-16T05:01:39+00:00

I am developing a GUI that has a canvas and a bunch of controls

  • 0

I am developing a GUI that has a canvas and a bunch of controls and crap surrounding it. I want to allow the canvas’s event handler a chance to handle events like key presses and such when it doesn’t have focus. I want the rest to continue working as normal.

Basically what I want to set up is to tell the frame, “Any event you get that you don’t yourself process, forward it on to which ever canvas is currently active.” I want the quickest, most painless method of doing so…preferably just a couple lines of code.

The problem comes in things that process key presses to change their state. For example, if you hold ctrl down we stop snapping to grid coordinates but there are conditions in which we are not notified of the press and so can’t update the cursor until the user moves their mouse (at which point we check in the event for the key). We only get the press if focus is in the control. We’ve run into this problem before and just worked around it but now there’s these couple of conditions that just can’t be worked around without this forwarding mechanism.

Thanks.

=======================================================

Answer is that there really is no simple way to do this. You can’t just simply send anything that isn’t processed to a child widget because if it doesn’t process it then you’ll get it again….and then send it down again….etc…stack overflow. I actually got excited when I finally managed to cause this…

You also can’t just override ProcessEvent within the application frame. You have to override it in the App derived object that encapsulates the program. The reason for this is that you’ll spend a lot of extra time trying to capture events that never reach this point…such as key down (the one I specifically wanted at this time). The wxApp::ProcessEvent function seems to always get called when an event is not processed though.

You can’t simply call ProcessEvent on your target (even temporarily forgetting the first paragraph) because it doesn’t call the handlers that you’ve pushed onto it. If the processor for the event was added to the target with PushEventHandler it won’t be reached through target->ProcessEvent(event) but instead you need to activate the handlers themselves with target->GetHandler()->ProcessEvent(event).

However, again, you can’t even do that because you’ll receive anything that wasn’t directly processed and send it back…get it back…send it back…

The answer is to write a copy of ProcessEvent in the target’s handler(s) that doesn’t TryParent in addition to overriding wxApp::ProcessEvent. I ended up just keeping a pointer to the handler that deals with the events I want to forward and then, eventually (behind a bunch of abstraction), calling this->GetEventHashTable().HandleEvent(event,this) with “this” being the handler that needs to be activated. This is the key line within wxEvtHandler::ProcessEvent that actually grabs the function from your table and activates it; it skips the validator, some other crap, and doesn’t TryParent.

And that is how I defeated WX and did the impossible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:01:39+00:00Added an answer on May 16, 2026 at 5:01 am

    You can use the ProcessEvent method.

    On the event handlers you want to forward, add

    /* Let the canvas process this event too */ 
    canvas->ProcessEvent(aEvent);
    

    where “canvas” is a static global pointer to your canvas, and “aEvent” is the event object received by your handler.

    This way you can even simulate events! That’s what I use for my GUI regression testing system…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been developing a GUI library for Windows (as a personal side project, no
I am developing a c# GUI and was wondering if there were any (preferably
Developing websites are time-consuming. To improve productivity, I would code a prototype to show
Developing a .NET WinForms application: how can I check if the window is in
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
Developing a website and just trying to get back into the swing of (clever)
Developing server side code i finally got my eyes X-crossed trying to write -
When developing a desktop application in .NET, is it possible to not require the
When developing whether its Web or Desktop at which point should a developer switch
When developing a new web based application which version of html should you aim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.