Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Window placement
#1
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
#2
run then mov

Code:
Copy      Help
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




Code:
Copy      Help
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
#3
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)?
#4
yep 
 change 

Code:
Copy      Help
int hwnd
run "$system$\notepad.exe" "" "" "" 0x800 win("" "Notepad") hwnd
 
to

Code:
Copy      Help
int hwnd=win()

rest of the code is the same as above
#5
Had to shorten line 2, variable was already declared:
Macro bottom left
Code:
Copy      Help
hwnd=win()
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?
#6
windows doesn't keep a list of of activated windows only current 


you can try this

Code:
Copy      Help
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
Code:
Copy      Help
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
#7
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!
#8
"The first one works but the target application loses focus afterwards."
easy fix

Code:
Copy      Help
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
#9
Great, thank you this works!
Added:

Macro top left
Code:
Copy      Help
x=0.5
y=0.5

to place window in center of the screen.
#10
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
#11
Nice! I will experiment with those.
#12
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
Code:
Copy      Help
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     Help - how to add the trigger to the macro
Code:
Copy      Help
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


Forum Jump:


Users browsing this thread: 1 Guest(s)