Author |
Topic |
|
poweruser84
Russia
24 Posts |
Posted - 06/28/2013 : 17:28:45
|
Hello all. Please help me to make the script to increase or decrease the size of active window.
What this script's example supposed to do: - Activate window under cursor (main application window) - Get window x and y coordinates - Increase the size of window to 20%
I am tried this:
acActivateWindow(acGetOwnerWindowByPoint(acGetMouseLocationX(), acGetMouseLocationY()),0,0) wi = acGetWindowByPoint(acGetMouseLocationX(), acGetMouseLocationY()) w = acGetWindowLeft(wi,0,0) h = acGetWindowTop(wi,0,0) cSetWindowSize(wi,0,0,w,h,w*1.2,h*1.2)
This don't work because of unknown error in cSetWindowSize command. |
Edited by - poweruser84 on 06/28/2013 17:29:33 |
|
Noesis
25 Posts |
Posted - 06/28/2013 : 23:29:49
|
There's a few issues with the provided code, firstly you're activating the owner window then potentially applying the resize to a sub-window (may or may not matter depending on app/window being resized), secondly you are only getting the top and left coordinate for the window not the width and height which naturally will cause issues with the resize (this is probably the source of the error) and the resize function itself is misspelled in the post (probably just a typo in the post). I haven't tried the following code but try something like this;
wi = acGetOwnerWindowByPoint(acGetMouseLocationX(), acGetMouseLocationY()) acActivateWindow(wi) x = acGetWindowLeft(wi) y = acGetWindowTop(wi) w = acGetWindowRight(wi) - x h = acGetWindowBottom(wi) - y acSetWindowSize(wi,nil,nil,x,y,w*1.2,h*1.2)
hope this helps. |
|
|
poweruser84
Russia
24 Posts |
Posted - 06/29/2013 : 02:33:43
|
Noesis, thanks. I am tried with a few application windows and three different methods to get window under mouse cursor. But this doesn't work. This only changes the size of window (its width and height) to one fixed size... Probably that needs more complex script to get it work properly.
|
|
|
poweruser84
Russia
24 Posts |
Posted - 06/29/2013 : 03:59:42
|
Finnaly, i have found working code and modified it.
--- increase the size of window (+20%) acActivateWindow(acGetOwnerWindowByPoint(acGetMouseLocationX(), acGetMouseLocationY()),0,0) local wi = acGetParentWindowByPoint(acGetMouseLocationX(), acGetMouseLocationY()),0,0 local wil = acGetWindowLeft(wi) local wir = acGetWindowRight(wi)-acGetWindowLeft(wi) local wit = acGetWindowTop(wi) local wih = acGetWindowBottom(wi)-acGetWindowTop(wi) acSetWindowSize(wi, nil, nil, wir*1.2, wih*1.2) ---
It works. I am using Scroll down/Scroll up gestures with Left Mouse Button (as an modifier) to increase and decrease the size of the active window.
Now i want to improve it: script should remember current window until i release S+ button and no matter when another window would be appeared under mouse cursor (another window should'nt be resized until i release S+ button!). I know that will require Global lua script and After Release script option ON. Please assistance me!
|
Edited by - poweruser84 on 06/29/2013 04:05:15 |
|
|
Rob
USA
2615 Posts |
Posted - 06/29/2013 : 14:56:32
|
Sure, in your Global Lua add the following:function sp_after_release()
selectedWindow = nil
end Make sure the sp_after_release function isn't already defined, if it is, then only add the selectedWindow = nil line to it.
In your action:if selectedWindow == nil then
selectedWindow = acGetParentWindowByPoint(acGetMouseLocationX(), acGetMouseLocationY())
acActivateWindow(acGetOwnerWindowByPoint(acGetMouseLocationX(),acGetMouseLocationY()))
end
acSetWindowSize(selectedWindow, nil, nil,
(acGetWindowRight(selectedWindow)-acGetWindowLeft(selectedWindow))*1.2,
(acGetWindowBottom(selectedWindow)-acGetWindowTop(selectedWindow))*1.2
) That's a pretty handy idea |
|
|
poweruser84
Russia
24 Posts |
Posted - 06/30/2013 : 07:28:10
|
Rob Thanks. Works like a charm.
Now i want to go further - another script should resize child windows (such as tex boxes). It could be useful to bypass size limiations in various windows where text can't be fitted for reading.
I am tried this:
if selectedWindow == nil then selectedWindow = acGetWindowByPoint(acGetMouseLocationX(), acGetMouseLocationY()) acActivateWindow(acGetWindowByPoint(acGetMouseLocationX(),acGetMouseLocationY())) end acSetWindowSize(selectedWindow, nil, nil, (acGetWindowRight(selectedWindow)-acGetWindowLeft(selectedWindow))*1.01, (acGetWindowBottom(selectedWindow)-acGetWindowTop(selectedWindow)) )
This only adjusts child window's width to 0.01% as it supposed to be.
But i can't see it works at all. Child window elemenets just dissappering after performing the gesture... I know this is a quite possible in Windows because i have freeware utility which is able to resize window's elements.
Any ideas? |
Edited by - poweruser84 on 06/30/2013 07:29:28 |
|
|
Rob
USA
2615 Posts |
Posted - 07/02/2013 : 19:43:36
|
Sorry for the late response. I haven't really dug deep into it, but my immediate thought is that it's due to the different between screen and client coordinates. Meaning, the screen itself has coordinates (the ones you're used to working with), but within a window, a control (like a text box) has coordinates in relation to the window itself.
For example, for most systems 0,0 (x,y) is the upper left corner of the entire desktop. Meanwhile, a window (like Notepad) has its own coordinates internally (client). So a text box on a window may have the client coordinates of 0,0 (if it were in the upper left corner of the application window).
By default, SetWindowPos (the API call used by S+ for acSetWindowSize) expects the x and y coordinates in client coordinates. So what is happening (and I've tested to confirm) is that the position of the control is way off due to the coordinates that S+ uses internally for x and y are screen coordinates. After being translated by SetWindowPos, it's sending the control far, far away.
There isn't an immediately obvious solution to this, what needs to happen is a call to ScreenToClient (Windows API call) to convert the screen coordinates to client coordinates. This can technically be achieved via using the Alien interface built into S+ and calling the necessary Windows API calls, but it's rather complicated. My quick attempt was unsuccessful with ScreenToClient not succeeding, likely due to the need to pass in a POINT struct and something going wrong.
I'll need to look further into this. |
|
|
|
Topic |
|
|
|