csteifel
csteifel

Reputation: 2934

wxWidgets widget IDs

I'm a little bit confused about how the IDs work in wxWidgets, do I have to ensure that all ids across all windows that I create are unique to each of their own functions? Like if I have two wxID_OK's for two different dialog boxes are they going to start firing off events in other windows just because they share the same id?

Currently I've been maintaining a huge enum to grab my IDs from, this seems a bit silly though, and was wondering if I just had a misunderstanding of what is actually going on.

Upvotes: 0

Views: 1873

Answers (2)

Jonatan
Jonatan

Reputation: 3992

I nerver use id's nowadays. I use wxID_ANY for all widgets and use the widget pointer for identification. This works just as well and so there is no reason for two id's for the same widget. There might be some corner cases where real id's are required but i have not found any.

Upvotes: 2

VZ.
VZ.

Reputation: 22678

It's a good idea to use unique IDs inside each top level window (i.e. a wxFrame or a wxDialog) because the controls include their ID in the wxCommandEvents they generate and as command events are propagated upwards the window hierarchy until they reach the first top level window, it could be confusing to have 2 controls with the same ID as any handler defined in their common parent window would need to be careful to distinguish between them.

There are no restrictions on the reuse of IDs in different dialog boxes however.

And an even better idea is to not use any non standard IDs at all but just let wxWidgets generate them for you by specifying wxID_ANY when creating controls and using Bind() to connect your event handlers instead of the IDs in the event tables.

Upvotes: 1

Related Questions