Page 1 of 1

Toolbar Custom ID

Posted: Mon Nov 04, 2013 2:07 am
by musictreeAstro
Right now in wxCrafter we can choose an ID from a dropdown list for a toolbar item, for example. However, if we type in a custom ID, of course we need to declare it as a wxNewId(). However, if I add

Code: Select all

const long MainFrame::ID_MYID = wxNewId();
in wxcrafter.cpp and

Code: Select all

static const long ID_MYID;
in wxcrafter.h, these will be erased automatically by wxCrafter whenever I "Generate Code".

I understand that it is not recommended to edit wxcrafter.cpp and wxcrafter.h in the first place, so how can I use custom IDs? I am asking this because I have several similar toolbar buttons which need unique IDs.

Re: Toolbar Custom ID

Posted: Mon Nov 04, 2013 7:53 am
by eranif
There are 4 ways to set Window IDS:

1) Select the ID from the dropdown list
2) Use XRCID so instead of typing MY_ID, type: XRCID("MY_ID")
3) Use custom header file with all your IDs, and include this header by selecting the top level item in the wxCrafter view and add it to the 'Additional include headers' - so wxCrafter will include it while generating the code
4) (and this is what you are looking for) Click on the top level item in the tree view of wxCrafter and in its properties, select 'Generate Window ID' to True and just type your ID: MY_ID the generated codelite will include a enum with all your IDs

See this screenshot:
1.png
Here is an example of the generated code:

Code: Select all

class MainDialogBaseClass : public wxDialog
{
protected:
    enum {
        ID_BUTTON1 = 1003,
        ID_BUTTON2 = 1004,
        ID_BUTTON3 = 1005,
    };
protected:
    wxBoxSizer* mainSizer;
    wxPanel* m_panel69;
    wxBoxSizer* boxSizer71;
    wxRibbonBar* m_ribbonBar;
...
Eran

Re: Toolbar Custom ID

Posted: Fri Nov 08, 2013 12:30 pm
by musictreeAstro
Thanks! That was exactly what I was looking for.

Forrest