The methods in this section return information known to, or used by, the operating system when it works with dialogs or dialog controls. This includes things like window handles, window sizes, and window positions. It also includes things like the width of a scroll bar or the number of monitors attached to the system.
>>-aBaseDialog~GetSelf----------------------------------------><
The GetSelf method returns the handle of the Windows Dialog associated with the ooDialog dialog instance. A handle is a unique reference to a particular Windows object. Handles are used within some of the methods to work on a specific Windows object.
Note: Prior to ooRexx 3.2.0, and all the way back through the original IBM documentation, the GetSelf method was not documented. And, the Get method was documented as through it was the GetSelf method. This most likely has caused confusion. The Get method returns the handle to the most recently created dialog. In an application with more than one dialog this may not be the same as the Windows dialog associated with the instance object the programmer is working with.
Below is an example demonstrating these Windows handles and how they are related. Assume showHandles is a method of a subclass of BaseDialog and that staticDlg is a saved reference to another ooDialog object and that the static dialog was just created. The showHandles method is connected to a push button and then displays the handles when the user clicks that button.
::method showHandles expose staticDlg hwndTop = self~get hwndMyDialogHandle = self~dlgHandle hwndMySelf = self~getSelf hwndStatic = staticDlg~dlgHandle say "Top dialog: " hwndTop say "Self (dlgHandle):" hwndMyDialogHandle say "Self (getSelf): " hwndMySelf say "Static dialog: " hwndStatic
The above might write to the console something like the following:
Top dialog: 787096 Self (dlgHandle): 4522228 Self (getSelf): 4522228 Static dialog: 787096
>>-aBaseDialog~Get--------------------------------------------><
The Get method returns the handle of the Windows Dialog associated with the top ooDialog dialog. A handle is a unique reference to a particular Windows object. Handles are used within some of the methods to work on a specific Windows object.
Note: If more than one ooDialog exists, the top dialog and the dialog whose method is executing may not be the same. When more than one dialog exists, the top dialog is the one that was created last.
Below is an example demonstrating that the top dialog and the executing dialog may not be the same. Assume display is a method of a subclass of BaseDialog and that staticDlg is a saved reference to another ooDialog object.
::method display expose staticDlg hwndTop = self~get hwndSelf = self~dlgHandle hwndStatic = staticDlg~dlgHandle say "Top dialog: " hwndTop say "Self: " hwndSelf say "Static dialog:" hwndStatic
The above might write to the console something like the following:
Top dialog: 787096 Self: 4522228 Static dialog: 787096
>>-aBaseDialog~GetItem(--id--+---------+--)------------------->< +-,--hDlg-+
The GetItem method returns the handle of a particular dialog item.
The arguments are:
The ID of the dialog element.
The handle of the dialog. If it is omitted, the main dialog handle is used.
The following example returns the handle of a push button:
hndPushButton = MyDialog~GetItem(101)
>>-aBaseDialog~GetControlID(--hWnd--)-------------------------><
Given a valid window handle to a dialog control, the GetControlID method returns the resource ID of the control.
The only argument is:
The window handle of the dialog control.
Negative values indicate an error.
The hWnd argument is not a valid window handle.
The value is the negated Operating System Error code. The absolute value of the return can be used to look up the error reason in the Windows documentation.
The resource ID of the dialog control.
The following is a complete working example. It allows the user to check a check box with the F2 key and uncheck it with the F3 key. The F2 and F3 key press events are connected to the check and uncheck methods. When the user presses the F2 key, the program determines which control has the focus, uses the returned window handle to get the control ID, and then uses the ID to check the check box. And the same approach if the F3 key is pressed.
Note that in this dialog, there are only four controls that can have the focus. If the OK button has the focus, then nothing is done. In a more complex application, the programmer would probably check that the resource ID matches one of the check boxes instead.
/* Simple Grocery List */ dlg = .SimpleDialog~new dlg~constDir[IDC_GB_LIST] = 101 dlg~constDir[IDC_CB_MILK] = 102 dlg~constDir[IDC_CB_BREAD] = 103 dlg~constDir[IDC_CB_FRUIT] = 104 dlg~constDir[IDC_CB_CEREAL] = 105 if dlg~initCode = 0 then do dlg~create(30, 30, 150, 150, "The Simple Grocery List", "VISIBLE") dlg~Execute("SHOWTOP") dlg~Deinstall end -- End of entry point. ::requires "oodWin32.cls" ::class SimpleDialog subclass UserDialog inherit AdvancedControls MessageExtensions ::method check hWnd = self~getFocus id = self~getControlID(hWnd) if id == self~constDir[IDOK] then return self~getCheckControl(id)~check ::method unCheck id = self~getControlID(self~getFocus) if id == self~constDir[IDOK] then return self~getCheckControl(id)~uncheck ::method defineDialog self~addGroupBox(10, 20, 130, 90, "Check Needed Groceries", "", IDC_GB_LIST); self~addCheckBox(IDC_CB_MILK, , 30, 35, , , "Milk", "GROUP"); self~addCheckBox(IDC_CB_BREAD, , 30, 55, , , "Bread", "NOTAB"); self~addCheckBox(IDC_CB_FRUIT, , 30, 75, , , "Fruit", "NOTAB"); self~addCheckBox(IDC_CB_CEREAL, , 30, 95, , , "Cereal", "NOTAB"); self~addButton(IDOK, 105, 120, 35, 15, "OK", , "GROUP") ::method initDialog -- We know that the key code for F2 is 113 so we don't need to use the -- VirtualKeyCodes class. We use the 'none' filter so that only a F2 or F3 -- key press is captured. (Not Alt-F2, or Shift-F2, etc..) self~connectKeyPress(check, 113, "NONE") self~connectKeyPress(unCheck, 114, "NONE")
>>-aBaseDialog~GetPos-----------------------------------------><
The GetPos method returns the dialog window's position in pixels. The values are returned in a string separated by blanks for parsing.
The following example moves the window towards the top left of the screen.
parse value self~GetPos with px py self~Move( px%self~FactorX - 10, py%self~FactorY - 10)
>>-aBaseDialog~GetButtonRect(--id--)--------------------------><
The GetButtonRect method returns the size and position of the given button. The four values (left, top, right, bottom) are returned in one string separated by blanks.
The only argument is:
The ID of the button
>>-aBaseDialog~GetWindowRect(--hwnd--)------------------------><
The GetWindowRect method returns the size and position of the given window. The four values (left, top, right, bottom) are returned in one string separated by blanks.
The only argument is:
The handle of the window. There are a number of ways to get the window handle of objects used in ooDialog. For instance, use the GetSelf method to retrieve the window handle of the dialog instance. Use the Get method to retrieve the window handle of the most recently created dialog. To get the window handle to a dialog control, the GetItem method can be used.
>>-aBaseDialog~GetSystemMetrics(--index--)--------------------><
Obtains the system metric value for the given index.
The only argument is:
The numeric index of the system metric.
Good documentation on the system metrics is found in the MSDN Library under the GetSystemMetrics function. This documentation contains both the numeric value of the different indexes and information on what is returned for each index. The documentation is easy to found using a Google search of "GetSystemMetrics MSDN Library"
The return value is dependent on the index queried. Consult the MSDN library for information on the returned values.
Note: The OS will return 0 if an invalid index is used. Hoever, the return value for some indexes is also 0. The programmer will need to determine from the context if 0 is an error return or not. In addition, ooDialog will return -1 for some invalid argument values. For instance, if the string "dog" was passed in for the index argument, -1 would be returned.
The following code snippet is from an application where the user can have 5, 6, or more, independent dialogs open at one time. One of the menu options is "Tile Dialogs." When the user selects this option all the open dialogs are "tiled."
All the open dialog objects are stored in a queue. In the onTile method, which is invoked when the user selects the menu item, each dialog is fetched in turn from the queue. Then the dialog is repositioned at an offset from the preceding dialog. It is shifted to the right the width of 2 scroll bars and shifted down the the width of the title bar. (This width is the title bar width plus the thin border around the title bar.) The height of the thin border, the height of the title bar, and the width of a scroll bar are all determined by querying the system metrics.
::method onTile expose offSetX offSetY dialogQueue -- SM_CXVSCROLL = 20 -- SM_CYCAPTION = 4 -- SM_CYBORDER = 6 if \ offSetX~datatype('W') then do scrollBarX = self~getSystemMetrics(20) titleBarY = self~getSystemMetrics(4) windowBorderY = self~getSystemMetrics(6) offSetX = 2 * scrollBarX offSetY = (2 * windowBorderY) + titleBarY end parse value self~getWindowRect(self~dlgHandle) with x y . do dlg over dialogQueue x = x + offSetX y = y + offSetY self~setWindowRect(dlg~dlgHandle, x, y, 0, 0, "NOSIZE") end