Simple Connect question

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
Jengu
Earned a small fee
Earned a small fee
Posts: 20
Joined: Fri Jun 24, 2005 9:45 am

Simple Connect question

Post by Jengu »

I have a frame that has 4 wxTextCtrl's in it. If a wxEVT_SET_FOCUS event happens on either of the first two controls, I want function foo to be called. If a wxEVT_SET_FOCUS happens on either of the second two controls, I want function bar to be called (but not foo). How do I set this up using Connect? I've tried a million different combinations but either nothing gets called at all or both foo and bar get called no matter what.
Lucky75
Super wx Problem Solver
Super wx Problem Solver
Posts: 305
Joined: Thu May 03, 2007 3:54 pm

Post by Lucky75 »

It sounds to me like you are using the same ID for both of them.
Jengu
Earned a small fee
Earned a small fee
Posts: 20
Joined: Fri Jun 24, 2005 9:45 am

Post by Jengu »

I've tried using different IDs or same IDs, but I still haven't been able to get the correct behavior. It's not clear to me what ID I'm passing to Connect. I assume it's not the window ID, since Connect is already a method on a window so the ID should be obvious. If it's the event ID, passing a unique ID to one group hasn't worked... although now explaining it I think I've been giving one group wxID_ANY and the other a unique ID. :P I bet that's the problem...
Lucky75
Super wx Problem Solver
Super wx Problem Solver
Posts: 305
Joined: Thu May 03, 2007 3:54 pm

Post by Lucky75 »

The ID of the menu item, and the id of the function bar (?) need to be different. Generally it is a good idea to always keep different ID's, although sometimes I cheat when I have an item on the menubar and an item on the toolbar which do the same thing.

Your passing the ID of the item you want an event activated on through Connect(). For example, if you want an event to occur on menu click, you would pass the menu item ID through Connect().
Post Reply