18.104.22.168.1 Accessing Dialog Builder Resources with Origin C
To access a resource (or control) on a Dialog Builder dialog first launch the dialog containing the control. Then, declare an Origin C object of the appropriate type and attach it to the desired resource (control). Once an Origin C object is successfully attached to the resource, the resource can be accessed (initialized, controlled, evaluated, enabled, and shown or hidden) by manipulating the methods and properties of the attached Origin C object.
To access a control on a dialog use the following syntax:
MyControl = GetItem(ControlID);
where ControlName is an Origin C class name and ControlID is the resource ID string of the control defined in your Symbol header file. The Dialog class member function GetItem returns the control for the given resource ID.
Note: To access a resource outside a Dialog class member function you must also include the name of the dialog. For example, you would use MyControl = DialogName.GetItem(ControlID); where DialogName is the Origin C name of the dialog containing the control.
The following example demonstrates how to declare an Origin C object of the appropriate type and attach it to a resource.
- 1 For the control on the dialog that you want to access declare an Origin C object of the appropriate type (one that matches the control type of the resource you want to access). For example, to access a list box control you would declare an Origin C ListBox object.
ListBox m_lbxAvailableData; // Declare ListBox object
- 2 Attach the declared Origin C object to the resource or control you want to access using the GetItem method of the Origin C Dialog class. For example, the statement below attaches an Origin C ListBox object to a list box control identified by the resource ID string IDC_LDS_LIST1.
m_lbxAvailableData = GetItem(IDC_LDS_LIST1); // Attach ListBox object to list box
- 3 Access the list box control in the Dialog Builder resource by manipulating the methods and properties of the Origin C ListBox object attached to the list box control. For example the code below populates the list box with the names of all data sets in the currently open Origin project file.
// Loop through all data set names in project
foreach(strDataName in Project.DatasetNames)
m_lbxAvailableData.AddString(strDataName); // Add name to list box
Note: The call to the GetItem method of the Dialog class above (step 2) does not require a prepended object identifier (e.g. dlgListDataSets.) because the call is contained within the scope of the dlgListDataSets class object. See the section Accessing a List Box Control with Origin C for a link to all source code used in the example above.