After succesfully setting up IUP lib reference in codeblocks its time to test some IUP coding style. Download source code below.
In main.c file, we create some buttons and attach event handler to it. I modify it from IUP hello world sample to show how we access other controls from a event handler that only has reference to the control sending the event.
The first event handler is for the quit button. Its a simple one only returning some value that cause the IUP program to exit. I think we need this on all IUP program 🙂 yeah …
int btn_exit_cb( Ihandle *self )
/* Exits the main loop */
The next event handler we want to change the title of a label. To access the label we need to get a reference to the dialog/form containing the button and also the label by using IupGetDialog then we get the label using IupGetDialogChild.
void btn_change_label_cb( Ihandle *self )
Ihandle* dlg = IupGetDialog(self);
Ihandle* label = IupGetDialogChild(dlg, “LABEL1”);
IupSetAttribute(label, “TITLE”, “Hello world from Code::Blocks.”);
Each control need to be named by setting the name attribute. Our label named as LABEL1 according to code before. To set an attribute we use IupSetAttribute. Below is code for the label declaration and settings.
label = IupLabel(“Hello world from IUP.”);
IupSetAttribute(label, “NAME”, “LABEL1”);
IupSetAttribute(label, “SIZE”, “150x”);
I will leave it to reader to find out more from supplied source code.
Happy coding !