The RcDialog class gets its dialog definition from a resource script file. Resource script files are plain text files usually produced by a resource editor. The files generally have a file extension of ".rc", but an extension of ".dlg" is used by some resource editors.
This class subclasses the UserDialog class and has available all the methods of that class. RcDialog is a convenience class that uses the Load method of the UserDialog to load the dialog definition from the resource script file. The programmer then does not need to worry about the details of how and when to load the resource script. There is a slight difference in instantiating the class, and the programmer does not need to use the DefineDialog method because the dialog is defined in the resource script. Other than that, the RcDialog class is used in the same manner as the UserDialog class.
Note: Although the programmer does not need to use the Define method, there is nothing preventing its use. The Define method could be used at runtime to add additional dialog elements to those defined in the resource script.
RcDialog.cls is the source file for this class.
::requires "oodialog.cls"
The RcDialog class is a subclass of UserDialog.
>>-aRcDialog~Init(--script--,--dlgID--+-------------+--+----------+---------> +-,--dlgData.-+ +-,--hFile-+ >--+------------------------------------------------------+--)------------->< +-,--+------------------------------+--+-------------+-+ | .--------------------. | +-,--expected-+ | V | | +-"----+-CENTER---------+-+--"-+ +-CONNECTBUTTONS-+ +-CONNECTRADIOS--+ +-CONNECTCHECKS--+
The Init method of the parent class, UserDialog, has been overridden.
The arguments when creating a new dialog instance of this class are:
The name of the resource script file where the dialog is defined.
The resource ID of the dialog. This is the unique number, or sybmbolic ID, you assigned to the (dialog) resource when creating it.
A stem variable (don't forget the trailing period) that contains initialization data.
The file name of a header file containing the symbolic ID defines for the resources used by the program.
One or more of the keywords listed in the syntax diagram, separated by blanks:
The dialog is to be positioned in the center of the screen.
For each push button a connection to an object method in the RcDialog object is established automatically. See ConnectButton for a description of connecting buttons to a method. The name for the object method is created by ooDialog and the programmer needs to define the object method. The method name will be the button text with all spaces, ampersands, and colons removed.
Similar to CONNECTBUTTONS, but this option will connect the radio buttons to an object method. For radio buttons, the created method name will be the button text with all spaces, ampersands, and colons removed, prefaced with "ID".
Exactly the same as CONNECTRADIOS, for check box controls. The object method name is generated in the same way as it is for radio buttons.
This is the maximum number of dialog elements the dialog object can handle. See the Create method for details. The default value for this argument is 200.
This example creates a new dialog object using the SimpleLB class, which subclasses the RcDialog. It uses the dialog defintion with symbolic ID IDD_DIALOG1 in the listBox.rc resource script file. The dialog is initialized so that the "Doctor" item is selected in the list box with symbolic ID of IDC_LB by using the dlgData. stem variable. The symbolic IDs for this program are contained in the "resource.h" file. When the user closes the dialog, the dlgData.IDC_LB variable will contain the text of the selected item in the list box.
/* Simple ListBox using a .rc file for the dialog definition */ dlgData.IDC_LB = "Doctor" dlg = .SimpleLB~new("listBox.rc", IDD_DIALOG1, dlgData., "resource.h") if dlg~initCode = 0 then do dlg~Execute("SHOWTOP") dlg~Deinstall end else do say "Problem creating the dialog. Init code:" dlg~initCode return 99 end say "The user's choosen profession is" dlgData.IDC_LB return 0 -- End of entry point. ::requires "OODWIN32.CLS" ::class SimpleLB subclass RcDialog inherit AdvancedControls ::method initDialog lb = self~getListBox(IDC_LB) lb~add("Business Manager" ) lb~add("Software Developer") lb~add("Accountant") lb~add("Lawyer") lb~add("Doctor")
To try the example, cut and paste the above code into a file named listBox.rex and paste the following code into files listBox.rc and resource.h.
/* listBox.rc */ #include <windows.h> #include <commctrl.h> #include "resource.h" IDD_DIALOG1 DIALOGEX 30,30,179,182 STYLE DS_MODALFRAME | DS_FIXEDSYS | WS_VISIBLE | WS_CAPTION | WS_POPUP | WS_SYSMENU CAPTION "List Box Example" FONT 8,"MS Shell Dlg 2",400,0,1 BEGIN DEFPUSHBUTTON "Close",IDOK,122,161,50,14 LISTBOX IDC_LB,8,28,163,122,WS_TABSTOP | LBS_NOINTEGRALHEIGHT | LBS_SORT CTEXT "Pick Your Choosen Profession",IDC_STATIC,26,13,122,9 END /* resource.h */ #ifndef IDC_STATIC #define IDC_STATIC (-1) #endif #define IDD_DIALOG1 100 #define IDC_LB 1001