Code to Automatically Resize a Progress Window

Chris Kelleher

Administrator
Staff member
Hi All,

Unfortunately Tim is right, In Version 8.x you cannot resize a Browse
after it has been realized. I had never tried this in any version besides
9+ so I never even thought of it. Anyway the following code demonstrates
how to create a Window-Maximized event which will dynamically re-size and
re-place all of the objects on a window, depending on the size of the
window.

This procedure also has Triggers for Window-Restored, Window-Resized and
Window-Minimized. These Triggers are essentially there to support the
Window-Maximized Trigger. If you wanted to, you could take the formula's I
used here and apply them to the Window-Resize event in order to do this when
the user resizes the window with the Mouse.

In the past, I have also applied a constant to this formula and placed
it in initializeObject or the Main-Block, in order to proportionally resize
the window to the current Windows Resolution. To get the current
Resolution, you can query the SESSION:HEIGHT-PIXELS and SESSION:WIDTH-PIXELS
values. This is a pretty good start and there is a whole lot you can
accomplish with this base.

Happy Coding,
Ken McIntosh
TSEII
Progress Software Corp.
 

Chris Kelleher

Administrator
Staff member
<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>/** Definitions Section **/

DEFINE VARIABLE hCol AS HANDLE NO-UNDO.
DEFINE VARIABLE winState AS INTEGER NO-UNDO.

DEFINE TEMP-TABLE tt_Size NO-UNDO
FIELD wg_Name AS CHARACTER
FIELD wg_Width AS DECIMAL
FIELD wg_Height AS DECIMAL
FIELD wg_Xpos AS DECIMAL
FIELD wg_Ypos AS DECIMAL
INDEX wg_Name IS PRIMARY wg_Name.
DEFINE BUFFER bf_Size FOR tt_Size.

/** MAIN-BLOCK **/

ASSIGN CURRENT-WINDOW:MAX-WIDTH = SESSION:WIDTH-CHARS
CURRENT-WINDOW:MAX-HEIGHT = SESSION:HEIGHT-CHARS.

ASSIGN hCol = CURRENT-WINDOW NO-ERROR.
CREATE tt_Size.
ASSIGN tt_Size.wg_Name = STRING(hCol)
tt_Size.wg_Width = hCol:WIDTH-PIXELS
tt_Size.wg_Height = hCol:HEIGHT-PIXELS
tt_Size.wg_Xpos = hCol:X
tt_Size.wg_Ypos = hCol:Y NO-ERROR.

/** WINDOW-MAXIMIZED Trigger **/

ASSIGN winState = 1 NO-ERROR.
ASSIGN hCol = FRAME {&FRAME-NAME}:HANDLE NO-ERROR.
FIND FIRST bf_Size WHERE bf_Size.wg_Name = STRING(CURRENT-WINDOW)
NO-ERROR.
IF AVAILABLE bf_Size THEN DO:
ASSIGN hCol:HEIGHT-PIXELS = (hCol:HEIGHT-PIXELS *
CURRENT-WINDOW:HEIGHT-PIXELS) / bf_Size.wg_Height
hCol:WIDTH-PIXELS = (hCol:WIDTH-PIXELS *
CURRENT-WINDOW:WIDTH-PIXELS) / bf_Size.wg_Width NO-ERROR.
FIND FIRST tt_Size WHERE tt_Size.wg_Name = STRING(hCol) NO-ERROR.
IF NOT AVAILABLE tt_Size THEN DO:
CREATE tt_Size.
ASSIGN tt_Size.wg_Name = STRING(hCol)
tt_Size.wg_Width = hCol:WIDTH-PIXELS
tt_Size.wg_Height = hCol:HEIGHT-PIXELS
tt_Size.wg_xPos = hCol:X
tt_Size.wg_yPos = hCol:Y NO-ERROR.
END.
ASSIGN hCol = hCol:FIRST-CHILD NO-ERROR.
ASSIGN hCol = hCol:FIRST-CHILD NO-ERROR.
DO WHILE VALID-HANDLE(hCol):
FIND FIRST tt_Size WHERE tt_Size.wg_Name = STRING(hCol) NO-ERROR.
IF NOT AVAILABLE tt_Size THEN DO:
CREATE tt_Size.
ASSIGN tt_Size.wg_Name = STRING(hCol)
tt_Size.wg_Width = hCol:WIDTH-PIXELS
tt_Size.wg_Height = hCol:HEIGHT-PIXELS
tt_Size.wg_xPos = hCol:X
tt_Size.wg_yPos = hCol:Y NO-ERROR.
END.
ASSIGN hCol:HEIGHT-PIXELS = (hCol:HEIGHT-PIXELS *
CURRENT-WINDOW:HEIGHT-PIXELS) / bf_Size.wg_Height
hCol:WIDTH-PIXELS = (hCol:WIDTH-PIXELS *
CURRENT-WINDOW:WIDTH-PIXELS) / bf_Size.wg_Width
hCol:X = (hCol:X * CURRENT-WINDOW:WIDTH-PIXELS) /
bf_Size.wg_Width
hCol:Y = (hCol:Y * CURRENT-WINDOW:HEIGHT-PIXELS) /
bf_Size.wg_Height NO-ERROR.
ASSIGN hCol = hCol:NEXT-SIBLING NO-ERROR.
END.
END.


/** WINDOW-RESTORED Trigger **/

IF winState = 3 THEN
ASSIGN winState = 0 NO-ERROR.
ELSE DO:
IF winState = 1 THEN DO:
ASSIGN winState = 0 NO-ERROR.
END.
ASSIGN hCol = FRAME {&FRAME-NAME}:HANDLE NO-ERROR.
FIND FIRST tt_Size WHERE wg_Name = STRING(hCol) NO-ERROR.
IF AVAILABLE tt_Size THEN DO:
ASSIGN hCol:HEIGHT-PIXELS = tt_Size.wg_Height
hCol:WIDTH-PIXELS = tt_Size.wg_Width
hCol:X = tt_Size.wg_xPos
hCol:Y = tt_Size.wg_yPos NO-ERROR.
END.
ASSIGN hCol = hCol:FIRST-CHILD NO-ERROR.
ASSIGN hCol = hCol:FIRST-CHILD NO-ERROR.
DO WHILE VALID-HANDLE(hCol):
FIND FIRST tt_Size WHERE wg_Name = STRING(hCol) NO-ERROR.
IF AVAILABLE tt_Size THEN DO:
ASSIGN hCol:HEIGHT-PIXELS = tt_Size.wg_Height
hCol:WIDTH-PIXELS = tt_Size.wg_Width
hCol:X = tt_Size.wg_xPos
hCol:Y = tt_Size.wg_yPos NO-ERROR.
END.
ASSIGN hCol = hCol:NEXT-SIBLING NO-ERROR.
END.
END.


/** WINDOW-MINIMIZED Trigger **/

ASSIGN winState = 3.

/** WINDOW-RESIZED Trigger **/

IF winState <> 1 THEN DO:
FIND FIRST tt_Size WHERE tt_Size.wg_Name = STRING(CURRENT-WINDOW)
NO-ERROR.
IF AVAILABLE tt_Size THEN
ASSIGN CURRENT-WINDOW:HEIGHT-PIXELS = tt_Size.wg_Height
CURRENT-WINDOW:WIDTH-PIXELS = tt_Size.wg_Width NO-ERROR.
END.

[/code]
 

Chris Kelleher

Administrator
Staff member
Hi Again,

The following is the program that I used to dynamically re-size and
re-place the window and everything in it, based on the current windows
resolution. This is based on a design resolution of 800 by 600, but these
numbers can be changed depending on the resolution used at design time. To
run it, I created an internal procedure called 'winResize', and ran it from
the main block, prior to creating the temp-table record for the Window
Specifications.

I tested this briefly in 8.2C and had a problem with the frame resizing
when the screen resolution was less than 800 x 600, and obviously this
doesn't take into account any Font issues, so the Labels can get kind of
hairy, but it works pretty good and I've used this frequently to keep my app
from either being too big or too small(depending on the resolution).

This also doesn't get the current resolution if it has been changed
after you start the session. To do that in the 4GL, you would have to apply
window-maximized and get the window height and width, then apply
window-restored, then do your processing. This can get pretty ugly so I
don;t ussually bother.

Happy Coding,
Ken McIntosh
TSEII
Progress Software Corp.
 

Chris Kelleher

Administrator
Staff member
<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>/** Procedure winResize **/

DEFINE VARIABLE winHeight AS DECIMAL NO-UNDO.
DEFINE VARIABLE winWidth AS DECIMAL NO-UNDO.
DEFINE VARIABLE winXpos AS DECIMAL NO-UNDO.
DEFINE VARIABLE winYpos AS DECIMAL NO-UNDO.

IF SESSION:WIDTH-PIXELS <> 800 THEN DO:

ASSIGN winHeight = 600 / SESSION:HEIGHT-PIXELS
winWidth = 800 / SESSION:WIDTH-PIXELS
winXpos = CURRENT-WINDOW:X
winYpos = CURRENT-WINDOW:Y NO-ERROR.

ASSIGN CURRENT-WINDOW:HEIGHT-PIXELS = CURRENT-WINDOW:HEIGHT-PIXELS /
winHeight
CURRENT-WINDOW:WIDTH-PIXELS = CURRENT-WINDOW:WIDTH-PIXELS /
winWidth
CURRENT-WINDOW:X = winXpos / winWidth
CURRENT-WINDOW:Y = winYpos / winHeight NO-ERROR.

ASSIGN hCol = FRAME {&FRAME-NAME}:HANDLE NO-ERROR.
IF SESSION:WIDTH-PIXELS < 800 THEN
ASSIGN hCol:HEIGHT-PIXELS = hCol:HEIGHT-PIXELS * winHeight
hCol:WIDTH-PIXELS = hCol:WIDTH-PIXELS * winWidth NO-ERROR.
ELSE IF SESSION:WIDTH-PIXELS > 800 THEN
ASSIGN hCol:HEIGHT-PIXELS = hCol:HEIGHT-PIXELS / winHeight
hCol:WIDTH-PIXELS = hCol:WIDTH-PIXELS / winWidth NO-ERROR.

ASSIGN hCol = hCol:FIRST-CHILD NO-ERROR.
ASSIGN hCol = hCol:FIRST-CHILD NO-ERROR.

DO WHILE VALID-HANDLE(hCol):
ASSIGN hCol:HEIGHT-PIXELS = hCol:HEIGHT-PIXELS / winHeight
hCol:WIDTH-PIXELS = hCol:WIDTH-PIXELS / winWidth
hCol:X = hCol:X / winWidth
hCol:Y = hCol:Y / winHeight NO-ERROR.
ASSIGN hCol = hCol:NEXT-SIBLING NO-ERROR.
END.

END.


[/code]
 
Top