PillarSoft

http://www.pillarsoft.net/os-2-software/rexx/open-and-center-window-in-visprorexx.shtml

Open and center window in VisPro/Rexx

Contributed by: Wayne Swanson

An explanation of some of the lines followed by the snippet.Normally the screensize and windowsize commands are two line commands in the templates that come with VisPro/Rexx. Rather than using the usual two line template for them, I like to combine them into one line each by using "parse value .... with". Here are the stock lines from the VisPro templates:

xy=VpWindow(window,'GETSCREENSIZE')
PARSE VAR xy x y
xy=VpWindow(window,'GETSIZE')
PARSE VAR xy xsize ysize

And here is how I prefer them in my templates.

parse value VpWindow(window,"GETSCREENSIZE") with x y
parse value VpWindow(window,"GETSIZE") with xsize ysize

It works the same either way, it's more a matter of what you prefer to use.

x=(x-xsize)/2
y=(y-ysize)/2

Here we subtract the window width (xsize) from screen width (x) to find out how much unused space will be left after the window is drawn on the screen. Then we divide that unused space in half and put it on either side of the window to make it appear centered. We do the same with the height (y & ysize) of the window. For example if:

Screensize = 1024 768
Windowsize =  600 400
x = (1024-600)/2        thus: 1024 - 600 = 424,  424 / 2 = 212
y =  (768-400)/2        thus:  768 - 400 = 368,  368 / 2 = 184

So now x = 212, y = 184, xsize = 600, ysize = 400. Let's go ahead and position the window.

CALL VpWindow window,"SETPOS", x, y, xsize, ysize

So here is the snippet. It is a generic call that you can place in your templates and use repeatedly from your "When opened" event without having to change it at all for any program.


 

parse value VpWindow(window,"GETSCREENSIZE") with x y
parse value VpWindow(window,"GETSIZE") with xsize ysize
x=(x-xsize)/2
y=(y-ysize)/2
CALL VpWindow window,"SETPOS", x, y, xsize, ysize