StrokesPlus Forum
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 Action Scripts Using Alien
 How to detect if a window is maximized, minimized
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  


1 Posts

Posted - 02/28/2019 :  12:14:28  Show Profile  Reply with Quote

First of all, sorry for my poor english.

I'm using this two functions to detect if a given window is maximized, minimized or "restored" or "windowed".

I think that this need to be a funcion integrated in the LUA commands of Strokesplus.

The code is from Rob's scripts.

The function aIsZoomed detects if a window is maximized (zoomed) and the function aIsIconic detects if a window is minimized (iconized). If a window is not maximized and is not minimized, its state is "restored" or "windowed".

Put this in Global Lua:

user32 = alien.core.load("user32.dll")

-- ************ IsZoomed ************
gIsZoomed = user32.IsZoomed
gIsZoomed:types{ ret = 'long', abi = 'stdcall', 'long'}
-- aIsZoomed (iWnd = window handle)
function aIsZoomed(iWnd)
return gIsZoomed(iWnd)

-- ************ IsIconic ************
gIsIconic = user32.IsIconic
gIsIconic:types{ ret = 'long', abi = 'stdcall', 'long'}
-- aIsIconic (iWnd = window handle)
function aIsIconic(iWnd)
return gIsIconic(iWnd)

If a window is maximized (zoomed) aIsZoomed will return something different to 0, else will return 0.

If a window is minimized (iconized) aIsIconic will return something different to 0, else will return 0.

Now you can use these functions directly. In my case I have differents monitors with different resolutions, so moving a window from one monitor to other is a problem, because the window is greater than the monitor.
I'm detecting if a window is maximized before and save the result in a variable.
Then I force the window to be "restored" ( even if is restored), move the window to the new monitor and then, if the window was maximized, I force to maximize.

This is the function on you Global Lua: ( the name of the function is in catalan, my language)

function dp_canvia_finestra_de_pantalla(h_Window,n_MonitorNum)
-- dp_change_a_window_to_monitor (handle of window, number of monitor)
local b_Max=aIsZoomed( h_Window)
acSendWindowToMonitorByName(h_Window,nil,nil, "\\\\.\\DISPLAY"..n_MonitorNum)
if b_Max~=0 then -- Means not equal
acCenterWindowToScreen(h_Window, nil, nil, 1)

In your action script you can use this:

local s_MonitorNom=acGetMonitorName(acGetMonitorFromPoint(gsx, gsy))
local n_MonitorNum=string.sub(s_MonitorNom,string.len(s_MonitorNom))
if n_MonitorNum=="1" then n_MonitorNum="2"
elseif n_MonitorNum=="2" then n_MonitorNum="4"
elseif n_MonitorNum=="3" then n_MonitorNum="1"
elseif n_MonitorNum=="4" then n_MonitorNum="3"
dp_canvia_finestra_de_pantalla(acGetOwnerWindowByPoint(gsx, gsy),n_MonitorNum)

I have 4 monitors, but Windows think that the order is 2,1,3,4 ( from left to right) This is the script to move a windows to the monitor on the left.

I can use a similar funtion to assign a window to a monitor by a hotkey:


This sends the foreground window to my first monitor ( in my case monitor 2)

Hope you can enjoy this...


2566 Posts

Posted - 02/28/2019 :  12:29:40  Show Profile  Visit Rob's Homepage  Reply with Quote
Thanks for posting a useful script!

I think that this need to be a funcion integrated in the LUA commands of Strokesplus

Unfortunately, any of my free time is dedicated to working on, which does happen to support those and many other window properties by default.

But it uses a new script engine and scripting language, so unfortunately all scripts would have to be converted if you switched :/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000