Methods to Query Operating System Values

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.

GetSelf

>>-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, the GetSelf method was not documented. The Get method was documented as if it were the GetSelf method. 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.

Example:

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

Output:

The above might write to the console something like the following:

  Top dialog:       787096
  Self (dlgHandle): 4522228
  Self (getSelf):   4522228
  Static dialog:    787096

Get

>>-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.

Example:

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

Output:

The above might write to the console something like the following:

  Top dialog:    787096
  Self:          4522228
  Static dialog: 787096

GetItem

>>-aBaseDialog~GetItem(--id--+---------+--)-------------------><
                             +-,--hDlg-+


The GetItem method returns the handle of a particular dialog item.

Arguments:

The arguments are:

id

The ID of the dialog element.

hDlg

The handle of the dialog. If it is omitted, the main dialog handle is used.

Example:

The following example returns the handle of a push button:

hndPushButton = MyDialog~GetItem(101)

GetControlID

>>-aBaseDialog~GetControlID(--hWnd--)-------------------------><


Given a valid window handle to a dialog control, the GetControlID method returns the resource ID of the control.

Arguments:

The only argument is:

hWnd

The window handle of the dialog control.

Return value:

Negative values indicate an error.

-1

The hWnd argument is not a valid window handle.

less than -1

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.

other

The resource ID of the dialog control.

Example:

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")

getPos

>>--getPos-----------------------------------------------------><

The getPos method returns the coordinates of the upper left corner a window, either a dialog or a dialog control, in dialog units.

Return value:

The horizontal and vertical position, separated by a blank.

Example dialog control:

The following example repositions the tree view control FILES to the upper left corner of the window and displays the new position:

obj = MyDialog~GetTreeControl("FILES")
if obj = .Nil then return
obj~Move(1,1)
parse value obj~getPos with x y
say "New horizontal position of window is" x "and new vertical position is" y

Example dialog:

The following example moves the window towards the top left of the screen.

parse value self~getPos with px py
self~Move(px - 10, py - 10)

GetButtonRect

>>-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.

Arguments:

The only argument is:

id

The ID of the button

GetWindowRect

>>-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.

Arguments:

The only argument is:

hwnd

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.

getSystemMetrics (deprecated)

Note: This method is deprecated. It is replaced by the functionally equivalent getSystemMetrics() method of the .DlgUtil class. Do not use this method in new code. Try to migrate existing code to to the .DlgUtil~getSystemMetrics() method. This method may not exist in future versions of ooDialog.