Centering a GUI window on the available desktop space

Chris Kelleher

Administrator
Staff member
<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>procedure WinCascade:
def var twh as handle no-undo.
def var svga as logical no-undo.

svga = session:width-pixels >= 800.

twh = {&WINDOW-NAME}:next-sibling.
if twh = ? then
twh = session:first-child.
if twh <> ? then do:
{&WINDOW-NAME}:x = twh:x + (if svga then 19 else 8)
+ (if twh:resize then 3 else 0).
if svga then
{&WINDOW-NAME}:y = twh:y + 19 + (if twh:resize then 3 else 0).
else
{&WINDOW-NAME}:y = twh:y.
end.
else do:
{&WINDOW-NAME}:row = (session:height-chars -
{&WINDOW-NAME}:height-chars) / 2. {&WINDOW-NAME}:column =
(session:width-chars - {&WINDOW-NAME}:width-chars) / 2.
end.
end.

procedure WinCenter:
def var twh as handle no-undo.
def var svga as logical no-undo.

svga = session:width-pixels >= 800.

twh = {&WINDOW-NAME}:next-sibling.
if twh = ? then
twh = session:first-child.
if twh <> ? then do:
{&WINDOW-NAME}:x = twh:x + (twh:width-pixels -
{&WINDOW-NAME}:width-pixels) / 2. {&WINDOW-NAME}:y = twh:y +
(twh:height-pixels - {&WINDOW-NAME}:height-pixels) / 2. /* Make
sure the upper left corner stays inside the parent program: */ if
{&WINDOW-NAME}:x < 0 then do:
{&WINDOW-NAME}:x = twh:x + (if svga then 19 else 8)
+ (if twh:resize then 3 else 0).
end.
if {&WINDOW-NAME}:y < 0 then do:
if svga then
{&WINDOW-NAME}:y = twh:y + 19 + (if twh:resize then 3 else 0).
else
{&WINDOW-NAME}:y = twh:y.
end.
end.
else do:
{&WINDOW-NAME}:row = (session:height-chars -
{&WINDOW-NAME}:height-chars) / 2. {&WINDOW-NAME}:column =
(session:width-chars - {&WINDOW-NAME}:width-chars) / 2.
end.
end.

procedure WinPlaceAt:
def input parameter xrow as decimal.
def input parameter xcolumn as decimal.

def var twh as handle no-undo.
def var svga as logical no-undo.

svga = session:width-pixels >= 800.

twh = {&WINDOW-NAME}:next-sibling.
if twh = ? then
twh = session:first-child.
if twh <> ? then do:
{&WINDOW-NAME}:row = twh:row + xrow.
{&WINDOW-NAME}:column = twh:column + xcolumn.
end.
else do:
{&WINDOW-NAME}:row = (session:height-chars -
{&WINDOW-NAME}:height-chars) / 2. {&WINDOW-NAME}:column =
(session:width-chars - {&WINDOW-NAME}:width-chars) / 2.
end.
end.
[/code]
 
Top