Kbase P11674: How to keep all the windows and dialog-boxes centered with o
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/18/2003 |
|
Status: Unverified
GOAL:
How to keep all the windows and dialog-boxes centered with one persistent procedure in the background?
FIX:
The WINDOW and DIALOG-BOX widgets have no CENTERED attribute, so it is not straight forward to keep a window at the center of the screen.
However, it is possible to use the PSTimer OCX to periodically walk though the windows and dialog-boxes tree and center them, as shown in the following code:
At the beginning of the 4GL session, do: RUN CenterThemAll.w PERSISTENT.CenterThemAll.w is a hidden window (with VIEW Property unchecked and HIDDEN property checked) that contains the PSTimer OCX (Interval property set to 1000 for example) and the following 3 sections of code:
PROCEDURE CtrlFrame.PSTimer.Tick . /*trigger procedure OcxTick*/
/*------------------------------------------------------------------------------
Purpose:
Parameters: None required for OCX.
Notes:
------------------------------------------------------------------------------*/
RUN CenterChildren(SESSION:HANDLE).
END PROCEDURE.
PROCEDURE CenterChildren :
DEFINE INPUT PARAMETER hParent AS HANDLE NO-UNDO.
DEFINE VARIABLE h AS HANDLE NO-UNDO.
h = hParent:FIRST-CHILD.
DO WHILE h <> ?:
IF LOOKUP(h:TYPE,"WINDOW,DIALOG-BOX") <> 0 THEN DO:
RUN CenterChildren(h).
RUN centerObject(h).
END.
h = h:NEXT-SIBLING.
END.
END PROCEDURE.
PROCEDURE CenterObject :
DEFINE INPUT PARAMETER h AS HANDLE NO-UNDO.
DEFINE VARIABLE hParent AS HANDLE NO-UNDO.
DEFINE VARIABLE iAvailWidth AS INTEGER NO-UNDO.
DEFINE VARIABLE iAvailHeight AS INTEGER NO-UNDO.
DEFINE VARIABLE ix AS INTEGER NO-UNDO.
DEFINE VARIABLE iy AS INTEGER NO-UNDO.
IF h:TYPE = "WINDOW" THEN ASSIGN
iAvailWidth = SESSION:WORK-AREA-WIDTH-PIXELS
iAvailHeight = SESSION:WORK-AREA-HEIGHT-PIXELS.
ELSE ASSIGN /*Dialog-box*/
hParent = h:PARENT
iAvailWidth = hParent:WIDTH-PIXELS
iAvailHeight = hParent:HEIGHT-PIXELS.
ASSIGN
ix = (iAvailWidth - h:WIDTH-PIXELS) / 2
iy = (iAvailHeight - h:HEIGHT-PIXELS) / 2.
IF h:X <> ix THEN h:X = ix.
IF h:Y <> iy THEN h:Y = iy.
END PROCEDURE.