Posts: 102
Threads: 30
Joined: Mar 2018
I cannot find this in the Windows, Controls toolbar or in the QM program documentation. Is there a way to launch applications, Notepad for example, in the following four screen locations?
Top left
Top right
Bottom left
Botom right
Posts: 1,337
Threads: 61
Joined: Jul 2006
run then mov
int hwnd
run "$system$\notepad.exe" "" "" "" 0x800 win("" "Notepad") hwnd
int x y
RECT r
;top left
;-----------
;x=+1
;y=+1
;Bottom left
;-----------
;x=+1
;y=-1
;top right
;---------
;x=-1
;y=+1
;Bottom Right
;------------
;x=-1
;y=-1
r.left=x; r.top=y
AdjustWindowPos hwnd &r 3
or another way
int hwnd
run "$system$\notepad.exe" "" "" "" 0x800 win("" "Notepad") hwnd
;top left
;----------------
;mov 0 0 hwnd
;bottom left
;----------------
;int L T H wH
;GetWorkArea L T 0 H
;GetWinXY hwnd 0 0 0 wH
;mov L T+H-wH hwnd
;bottom right
;------------------------
;int L T H wH w W wW
;GetWorkArea L T W H 1
;GetWinXY hwnd 0 0 wW wH
;mov W-wW H-wH hwnd
;upper right
;-----------------------
;int L T H wH wW W
;GetWorkArea L T W H 1
;GetWinXY hwnd 0 0 wH 0
;mov W-wH 0 hwnd
Posts: 102
Threads: 30
Joined: Mar 2018
Works great with Notepad thank you!
Is it also possible to place the Active window (any window or program that has focus) to top left, bottom left, top right, bottom right while it's running (when it is not maximized of course)?
Posts: 1,337
Threads: 61
Joined: Jul 2006
yep
change
int hwnd
run "$system$\notepad.exe" "" "" "" 0x800 win("" "Notepad") hwnd
to
rest of the code is the same as above
Posts: 102
Threads: 30
Joined: Mar 2018
09-29-2018, 02:35 AM
(This post was last modified: 09-29-2018, 02:38 AM by InterestedNewbie.)
Had to shorten line 2, variable was already declared:
Macro bottom left
The script works perfectly from within QM, but when I export it as executable it doesn't work because the target application loses focus when this executable is started. Is there a way to first reactivate the last active window so that the scripts works on that window?
Posts: 1,337
Threads: 61
Joined: Jul 2006
09-29-2018, 02:37 PM
(This post was last modified: 09-29-2018, 03:26 PM by Kevin.)
windows doesn't keep a list of of activated windows only current
you can try this
int hwnd=RealGetNextWindow(0)
int x y
RECT r
;;top left
;;-----------
x=+1
y=+1
r.left=x; r.top=y
AdjustWindowPos hwnd &r 3
or try
key AT ;; Alt+Tab
0.1
int hwnd=win
int x y
RECT r
;;top left
;;-----------
x=+1
y=+1
r.left=x; r.top=y
AdjustWindowPos hwnd &r 3
Posts: 102
Threads: 30
Joined: Mar 2018
The first one works but the target application loses focus afterwards.
The second one has a tendency to activate other Windows first.
Apparently there's no other reliable way then to first activate the target application (which makes this placement executable application specific). After that it works perfectly.
But this placement script is useful as it is. Thanks again!
Posts: 1,337
Threads: 61
Joined: Jul 2006
09-29-2018, 08:09 PM
(This post was last modified: 09-29-2018, 08:09 PM by Kevin.)
"The first one works but the target application loses focus afterwards."
easy fix
int hwnd=RealGetNextWindow(0)
int x y
RECT r
;;top left
;;-----------
x=+1
y=+1
r.left=x; r.top=y
AdjustWindowPos hwnd &r 3
act hwnd
Posts: 102
Threads: 30
Joined: Mar 2018
Great, thank you this works!
Added:
Macro top left
to place window in center of the screen.
Posts: 1,337
Threads: 61
Joined: Jul 2006
09-30-2018, 04:08 PM
(This post was last modified: 09-30-2018, 04:12 PM by Kevin.)
with AdjustWindowPos x and y can just be 0 and will move to center
Adjusts window or rectangle coordinates like mes and other QM functions do. If negative, adjusts so that the window would be at the right or bottom of the screen. If 0, adjusts so that the window would be at the center of the screen. Ensures that whole window is in the screen. Ensures that the window will be in the specified monitor.
a few more positions
center
x=0
y=0
top center
x=0
y=1
bottom center
x=0
y=-1
right center
x=-1
y=0
left center
x=1
y=0
Posts: 102
Threads: 30
Joined: Mar 2018
Nice! I will experiment with those.
Posts: 1,337
Threads: 61
Joined: Jul 2006
10-01-2018, 01:55 AM
(This post was last modified: 10-01-2018, 02:03 AM by Kevin.)
was just messing around made this
puts all 9 different positions in 1 function and lets you choose at run time where to place the window. Uses a list dialog.
Function MoveActiveWindow
int iSel=ListDialog("Top Left[]Top Center[]Top Right[]Left Center[]Center[]Right Center[]Bottom Left[]Bottom Center[]Bottom Right" "Select a screen position to move the active window" "Choose a Position")
sub.MoveWindowToScreenPosition(iSel-1)
#sub MoveWindowToScreenPosition
function position
int x y
sel position
,case 0;;Top Left
,x=1
,y=1
,case 1;;Top Center
,x=0
,y=1
,case 2;;Top Right
,x=-1
,y=1
,case 3;;Left Center
,x=1
,y=0
,case 4;;Center
,x=0
,y=0
,case 5;;Right Center
,x=-1
,y=0
,case 6;;Bottom Left
,x=1
,y=-1
,case 7;;Bottom Center
,x=0
,y=-1
,case 8;;;Bottom Right
,x=-1
,y=-1
,case else
,ret
int hwnd=RealGetNextWindow(0)
RECT r
r.left=x; r.top=y
AdjustWindowPos hwnd &r 3
act hwnd
if you would want to run this specifically from qm i would recommend putting a trigger on it
something like this
Function MoveActiveWindow
Trigger CAF8
int iSel=ListDialog("Top Left[]Top Center[]Top Right[]Left Center[]Center[]Right Center[]Bottom Left[]Bottom Center[]Bottom Right" "Select a screen position to move the active window" "Choose a Position")
sub.MoveWindowToScreenPosition(iSel-1)
#sub MoveWindowToScreenPosition
function position
int x y
sel position
,case 0;;Top Left
,x=1
,y=1
,case 1;;Top Center
,x=0
,y=1
,case 2;;Top Right
,x=-1
,y=1
,case 3;;Left Center
,x=1
,y=0
,case 4;;Center
,x=0
,y=0
,case 5;;Right Center
,x=-1
,y=0
,case 6;;Bottom Left
,x=1
,y=-1
,case 7;;Bottom Center
,x=0
,y=-1
,case 8;;;Bottom Right
,x=-1
,y=-1
,case else
,ret
int hwnd=RealGetNextWindow(0)
RECT r
r.left=x; r.top=y
AdjustWindowPos hwnd &r 3
act hwnd
|