<< Click to Display Table of Contents >> Navigation: 3. Script Language > Window Operations > Window Operations |
MiniRobotLanguage (MRL)
SWP. Command
Set Window Position and Size
Intention
The SWP.-Command can be used to set the position or to change the size of the actual
selected Top- or Child-Window. You need to select/locate a child or Top-Window using the STW. or the LAP. command before you can use SWP.
The window position is been calculated from the top-left corner of the window or child-window.
The SWP. command has a lot of additional features. If you want to place the window just in the middle of the screen, without changing the size, you can just write:
' Place the actual localized window in the middle of the screen
SWP.mid
You can still resize the window if you do this:
' Place the actual localized window in the middle of the screen
' and resize it to 600x400 Pixel
SWP.mid|600,400
Using some more tricks, you can for example make the window to quarter of its current size while not changing the position of the window at all.
SWP.|hw,hw
Here are some more complete examples:
' locate / select the Window that shall be resized using STW.
STW.c|ieframe
' The window is moved to position 0,0|640,400
' and resized to 640x400
SWP.0,0|640,400
' The window is resized to 500x500 pixel
SWP.|500,500
' The window is resized to 100x200 and vertically moved to y=300
SWP.,300|100,200
' The window is only moved, not resized.
SWP.100,200
Syntax
SWP.[P1][,P2][|P3][,P4][|T]
Parameter Explanation
P1 - Left-Position
P2 - Top - Position
P3 - X - Size
P4 - Y - Size
You can specify three special Options as [|T]:
T - use Top-Window and whole Desktop Area of primary Monitor
M - use Top-Window and whole Desktop Area of all Monitors
F - use Desktop without Traybar and Top-Window
C - use actual localized window and whole Desktop Area. If you do not specify any of these additional Options, the actual window is used, and the whole-Desktop Area.
If you want to place the window just in the middle of the screen, without changing the size, you can just write:
' Place the actual localized window in the middle of the screen
SWP.mid
For the position parameters P1 (Left-Position) you can specify these words:
- "mid"
- "lb" (left bound) equals to zero
- "rb" (right bound) moves the window to the right border of the primary desktop
or just the first letter of these. They will take the actual size and calculate the new size as expected.
For the position parameters P2 (Top-Position) you can specify these words:
- "mid"
- "tb" (top bound)
- "bb" (bottom bound)
or just the first letter of these. They will take the actual size and calculate the new size as expected.
For the size parameters P3 and P4),you can specify the following words, which are based on the desktop size. Note that these calculations are influenced by adding the special options "|T" or "|F".
- "half" - half desktop size
- "full" - full desktop size
- "quarter" - quarter desktop size
or use these, which calculate the new size based on the current window size. Note that these options are influenced by adding special options "|T" or "|C" to the command.
- "halfwin","hw"
- "doublewin","dw"
- "quarterwin","qw"
They will take the actual size of the desktop and calculate the new size of the window as a part of the desktop size. It will use the size of the primary desktop, no matter if you have dual- or multi-screen.
You can omit any of the Parameters or just write "x".. In these cases, the parameters will be internally substituted with the current values. If you write for example:
' The window is horizontally moved to position 100, the vertical position is not changed
SWP.100,x
' The window is moced into the center of the desktop
SWP.mid,mid
' The window is only resized to half of its size in both directions
SWP. half,half
' The window is only moved, not resized. It's move to the left desktop border.
SWP.lb,x
Example
'---------------------------------------------
' SWP.-Example 1
'---------------------------------------------
' Close all such windows if there are some open
CAW.PBWindowClass:0|BCS - Testform
EXE.?exepfad\Sample Apps\BSC-Testform.exe
' Locate the window
STW.p|#pid#
' Position it "around"
SWP.lb,tb
PAU..1
SWP.mid,mid
PAU..1
SWP.rb,bb
PAU..1
SWP.|(#iw#/2)
ENR.
'---------------------------------------------
' SWP.-Example 2
'---------------------------------------------
' Close all such windows if there are some open
CAW.PBWindowClass:0|BCS - Testform
' Open 5 Terstforms and position them nicely
FOR.$$CNT|1|5
EXE.?exepfad\Sample Apps\BSC-Testform.exe
STW.p|#pid#
SWP.(100+55*$$CNT),(200+55*$$CNT)
NEX.
FOR.$$CNT|1|50
'Move Testform "On top" to back
STW.ctb|PBWindowClass:0|BCS - Testform
' Make small rest so we can see it
PAU..1
NEX.
' Close all Testforms
CAW.PBWindowClass:0|BCS - Testform
ENR.
Remarks
Additional to the features that SWP. delivers, you can always use these 3.1 Systemvariables for size or position calculations.
They are based on the last located object (window or whatever).
As always, use mathematical brackets () to enclose calculations.
#ssx#,#ssy# - Screen size X,Y
#cwh# - Debug Console Window-Handle
#wsx#,#wsy# - Work-area-Size X,Y
#sbp# - Screen-bits per pixel (Colordepth)
#fex# - FEX - Elements left on the FEX-Stack
#fxd# - FEX - Nesting-Depth
#il# - actual Element, left side X
#it# - actual Element, upper side Y
#ir# - actual Element, right side X
#ib# - actual Element, bottom side y
#iw# - actual Element, width X
#ih# - actual Element, height Y
#icx# - actual Element, Centerpoint X
#icx# - actual Element, Centerpoint Y
Example for this:
' Will make the x-size of the window half of current x-size
SWP.|(#iw#/2)
' Will move the window to its own centerpoint
SWP.(#icx#)
Limitations:
Not all Windows can be resized to exactly any size. This depends on the Internals of the target software as well as possibly on the used OS.
Using Windows 7, for example:
PRT.Output-Window. $crlf$ Close the Utility with this window!
' Console Fenster rechts anlehnen
STW.ctwAXo|consolewindowclass|system mess|2|Lab_nocon
SWP.0,0|600,400
PAU.15
:Lab_nocon
This window will be sizes to the nearest possible size, which is 605,395 in my testcase.
See also: