Attach a function to the control - an event handler.

Call:

ts_dialogcontrol(int iButtonDescr, "eventreaction", string eventfunctionname);


Here:

eventfunctionname - the name of the function that handles the event.


Example. 

To handle the response to a button click, create a function:


int iDialogDescr, iButtonZoom;
int main()
{
...// create a dialog box
    int x, y, w, h;
    x=1,y=1, w=200; h = 200;
    object("create","ts_dialog",iDialogDescr);
    ts_dialog(iDialogDescr, "init_dialog","palette",x,y,w,h);
    ts_dialog(iDialogDescr, "eventreaction", "Event_PanelCloseRequested");
    ts_dialog(iDialogDescr, "SetTitle","Bill of Quantity Calculation");
    bool bres;
   // create a control
   x=1; y=1; w=50; h=20;
   object("create","ts_dialogcontrol",iButtonZoom,"iButtonZoom");
    ts_dialogcontrol(iButtonZoom, "init_control", "button",iDialogDescr, x, y, w, h);
    ts_dialogcontrol(iButtonZoom, "eventreaction", "Event_ButtonClicked");
    ts_dialogcontrol(iButtonZoom, "settext", "Show");
...
    ts_dialog(iDialogDescr, "invoke",bres);
    cout << bres;
}

int Event_ButtonClicked(int iDescr, string sDescr)
{
   if(sDescr == "ButtonCancel")
   {
      ts_dialog(iDialogDescr,"PostCloseRequest","cancel"); // close dialog with cancel result
   }
   else if(sDescr == "ButtonOK")
   {
      ts_dialog(iDialogDescr,"PostCloseRequest","ok"); // close the dialog with the result "Ok"
   }
   else if(sDescr == "ButtonCalc")
   {
Calc();
   }
   else if(sDescr == "ButtonZoom")
   {
ZoomElementInProject();
   }
}


Now, on pressing the button, this function will be executed.

At the time of its execution, iDescr is the numeric value of the button handle that triggered the event, and sDescr is its object name (not to be confused with the button text). You can distinguish which button is pressed by design


if(iDescr == iDescrZoom)
{
   //
}
Or
if(sDescr == "iButtonZoom")
{
   //
}



It happens conveniently both by number and by name. For example, you can give a group of buttons the same name, perform common actions, and then distinguish them by a numeric descriptor.

Below is a table of function names - event handlers for each type of dialog controls.


Function name - event handler

Items that can be applied to

Note

Event_TreeViewContextMenuRequested

MultiselTreeView, SingleSelTreeView

Request to call the context menu

Event_TreeViewItemCollapsed

Tree rolling

Event_TreeViewItemDoubleClicked

Double cick

Event_TreeViewItemExpanded

Element expansion

Event_TreeViewLabelEditFinished

Finish editing the text of an element

Event_TreeViewLabelEditStarted

Start editing element text

Event_TreeViewSelectionChanged

Changing the selected tree element

Event_TreeViewStateIconClicked

Clicking the status icon




Event_ListViewContextMenuRequested

MultiselListView, SingleselListView

Context menu request

Event_ListViewDoubleClicked

double click

Event_ListViewItemUpdate

Position update

Event_ListViewSelectionChanged

Changing the current position




Event_RealEditChanged

RealEdit

Changing the number in the edit box




Event_TextEditChanged

TextEdit

Change the text in the edit field




Event_ItemFocusGained

All focusable elements

Element received focus

Event_ItemFocusLost

All focusable elements

Element lost focus




Event_ImageClicked

IconItem

Click on the picture




Event_ListBoxClicked

MultiselListBox, SingleselListBox

Mouse click

Event_ListBoxDoubleClicked

Double click

Event_ListBoxSelectionChanged

Changing the current selection




Event_PopUpChanged

PopUp

Changing the value in the PopUp element




Event_StaticTextClicked

LeftText, CenterText, RightText

Clicking on text

Event_StaticTextDoubleClicked

Double click




Event_CheckItemChanged

CheckBox, IconCheckBox, IconPushCheck, PushCheck

Changing the current selection

Event_CheckItemDoubleClicked

Double click




Event_ButtonClicked

Button, IconButton

Press button




Event_NormalTabChanged

NormalTab

Changing the current element in NormalTab (moving to another panel)

Event_NormalTabClicked

NormalTab

Mouse click on the field of the NormalTab element