Post Reply

Forums -> UltraMon™ SDK -> Toggling application between windows issue
sebekz   2011-11-09 20:48
I currently have a two-monitor setup, with third monitor being added soon.

Secondary monitor keeps my gmail app opened all the time, and when I want to work on it, I bring it to my primary screen with a hotkey. Pressing a hotkey once again dismisses gmail back to secondary screen.

I have created a script for that and bound it to a key on my keyboard. So far, so good... but it acts weird:

- sometimes all works as intended - app toggles between screens maximized
- sometimes app is minimized on screen and not moved to a second screen (I was able to debug with a simple MsgBox, that during that time the w.Monitor shows 0)
- sometimes app is brought to a second screen, but stays minimized

I have tried to play with WScript.Sleep and it seems to make it more reliable, but still only 50% of the time.

Is there anything I am doing wrong? The script is below.

Thanks

Set wnd = CreateObject("UltraMon.Window")

'get all visible windows
For Each w In wnd.GetAllWindows(False)
If InStr(w.Title, "Gmail") > 0 And InStr(w.Title, "@gmail.com") > 0 Then
w.Activate
WScript.Sleep 500

If w.Monitor = 1 Then
w.Monitor = 2
Else
w.Monitor = 1
End If
flags = WNDCHANGE_CLIP_TO_WORKSPACE
flags = flags + WNDCHANGE_RESIZE_TO_FIT
w.ApplyChanges flags
End IF
Next
Christian Studer   2011-11-10 09:19
I'm seeing that as well on Windows 7 with Internet Explorer, what's weird is that it works fine when using a Move Window hotkey.

The problem only occurs if the browser is maximized, as a workaround you could first restore the browser to normal size, then move and maximize it again:Const SHOWSTATE_NORMAL = 2 Const SHOWSTATE_MAXIMIZED = 3 Set wnd = CreateObject("UltraMon.Window") If wnd.Find("Gmail *@gmail.com*", "IEFrame", 3, 0, 0) = True Then If wnd.Monitor = 1 Then newMon = 2 Else newMon = 1 End If If wnd.ShowState = SHOWSTATE_MAXIMIZED Then wnd.ShowState = SHOWSTATE_NORMAL wnd.ApplyChanges 0 wnd.ShowState = SHOWSTATE_MAXIMIZED End If wnd.Monitor = newMon wnd.ApplyChanges 1 + 2 'WNDCHANGE_RESIZE_TO_FIT + WNDCHANGE_CLIP_TO_WORKSPACE wnd.Activate End IfI'm using the Find method to get the Gmail window, with the window class name for Internet Explorer, IEFrame. If you're using a different browser you would need to change this, you can get the class name with the WndInfo script.

Christian Studer - www.realtimesoft.com
sebekz   2011-11-11 08:49
Works like a charm, thanks!

For anyone willing to reuse - the optimal code for gmail would be:

Const SHOWSTATE_NORMAL = 2 Const SHOWSTATE_MAXIMIZED = 3 Set wnd = CreateObject("UltraMon.Window") If wnd.Find("*@gmail.com*", "Chrome_WidgetWin_0", 3, 0, 0) = True Then If wnd.Monitor = 1 Then newMon = 2 Else newMon = 1 End If wnd.ShowState = SHOWSTATE_NORMAL wnd.ApplyChanges 0 wnd.ShowState = SHOWSTATE_MAXIMIZED wnd.Monitor = newMon wnd.ApplyChanges 1 + 2 'WNDCHANGE_RESIZE_TO_FIT + WNDCHANGE_CLIP_TO_WORKSPACE wnd.Activate End If

It also maximizes window on screen, even if it has been not maximized before. This works for me, though I am aware, that it might not work for everyone.
aspace   2013-02-05 17:07
Sorry to pull this post back up, but I think my problem is somewhat related to the previous issue. I've searched and could not find anything closely related to my issue other than this.

I am using a 3rd monitor and running the OpenDocOnMonX2 script to open Chrome and always have it open on this specific monitor. However, as posted above, this script will not work if Chrome is already full screened (or maybe active?) on another monitor. My 3rd monitor is my TV and I am using a wireless kb/m so getting to my first/second monitor to minimize or close the already opened chrome window is a hassle.

I've made a poor attempt at integrating the above fix into the OpenDocOnMonX2 script, but my knowledge of this is very, very small and did not lead me to any solution. Has there been any sort of work around to this? Is there an easy way to minimize any open Chrome windows on monitors 1/2 before trying to open the one on 3?

Thanks for the help
Christian Studer   2013-02-06 08:12
aspace, I would recommend using the PositionApp script instead, that should do what you want. Let me know if you have any questions about configuring the script.

Christian Studer - www.realtimesoft.com
Forums -> UltraMon™ SDK -> Toggling application between windows issue

Post Reply