OK, I have a button class. We’ll call it GUIButton. It has an “OnClick()” member that gets called when the button is clicked. Currently this just prints “Clicked!” on the screen.
Imagine I want to put five buttons on the screen to do various things. Where do I put the OnClick() code for each button?
I was thinking of making an instance of GUIButton for each real button I want (QuitButton, LoadButton … etc) and overriding the OnClick() in each one. What I can’t work out now is how to link that to the GUI XML I’ve just created.
Take this line:
| Code: |
| <BUTTON x=0, y=0, name=”btnQuit” type=”1″ /> |
How, in my code, do I make that button link to the “QuitButton” class without having messy code that does this:
| Code: |
| switch (buttontype) { case 1: widget = new QuitButton(x,y,z,blah); break; case 2: widget = new OKButton(x,y,z); break; } |
Since by doing this I’m hardcoding the class types into code that will later be rolled up into a library. Also it doesn’t work very well if I have two OK buttons that do different things.
It feels like I need some sort of table that I register each class with so I can ask for a class by name.
This is the bit I never got to see when writing MFC code. All I did was click on a button, press Ctrl-W and choose “WM_CLICKED” and hit “Edit code”. *something* happened and I got a function to put code in.