Multi Monitor - MoveWindow

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
SteenJakobsen
Pro Scripter
Posts: 110
Joined: Thu Apr 08, 2010 6:11 am
Location: Hørsholm, Denmark
Contact:

Multi Monitor - MoveWindow

Post by SteenJakobsen » Fri Apr 30, 2010 1:26 pm

Hi,

In a multi monitor setup - is it possibe to move a window to monitor 2 or 3
and maximize it ?

And how do I detect how many monitors are present ?
Best Regards
Steen Jakobsen
DM Software A/S

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Apr 30, 2010 1:57 pm

http://www.mjtnet.com/forum/viewtopic.php?t=4960

The above will get you number and size. I have no good idea how to move your window to a specific monitor. Perhaps moving it to a guestimated location then maximizing will work???

SteenJakobsen
Pro Scripter
Posts: 110
Joined: Thu Apr 08, 2010 6:11 am
Location: Hørsholm, Denmark
Contact:

Post by SteenJakobsen » Fri Apr 30, 2010 3:55 pm

Hi JRL,

Thanks a lot :-)

this is the code for detecting how many monitors - and it works fine.

Code: Select all

// Number of monitors
Let>SM_CMONITORS=80
// Virtual Width
Let>SM_CXVIRTUALSCREEN=78
// Virtual Height
Let>SM_CYVIRTUALSCREEN=79
LibFunc>user32,GetSystemMetrics,mcnt,SM_CMONITORS

LibFunc>user32,GetSystemMetrics,vsw,SM_CXVIRTUALSCREEN
LibFunc>user32,GetSystemMetrics,vsh,SM_CYVIRTUALSCREEN

MessageModal>You have %mcnt% monitors%CRLF%Virtual Screen Size: %vsw%x%vsh% px

Now I just need to find a way to move a window from monitor 1 to monitor 2 and maximize it ..
Any body have a clue ?
Best Regards
Steen Jakobsen
DM Software A/S

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Apr 30, 2010 4:09 pm

You didn't say whether or not you tried estimating the screen positions. I don't have multiple monitors to try this on so this is just a guess.

Seems like after running the GetSystemMetrics API you should be able to divide the screen width by the number of monitors and then move the window to an approximate position based on that math. Then use WindowAction> to maximize the window. I would expect the window to maximize onto whichever screen the upper left corner of the window is sitting in.

WindowAction>1,window_title will maximize a window.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Apr 30, 2010 8:30 pm

JRL: That relies on knowing where each monitor is in relation to the other. Are they all in a row, one on top of another and a third to the right, and which one is the primary?

What you need is a function to retrieve the virtual desktop coordinates and size of a given monitor. I expect an API function to do that exists, but I don't know off the top of my head what it is, or whether it would be something that Macro Scheduler could use natively.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Apr 30, 2010 8:46 pm

JRL: That relies on knowing where each monitor is in relation to the other.
EXACTLY!!!

And no computer program can possibly know the physical layout of the monitors. So make a best guess.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Apr 30, 2010 8:52 pm

Of course It can. Windows does. The size, layout and position of each monitor is defined in Display Properties. There must therefore be an API to retrieve that info. I'm on a blackberry right now so can't easily find out at this time.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

SteenJakobsen
Pro Scripter
Posts: 110
Joined: Thu Apr 08, 2010 6:11 am
Location: Hørsholm, Denmark
Contact:

Post by SteenJakobsen » Sat May 01, 2010 5:40 am

Hi,

Great that you are investigating it :-)
many of my clients have multible monitors and the purpose is to
make macros for "Arrangeing different apps om different monitors"
Best Regards
Steen Jakobsen
DM Software A/S

SteenJakobsen
Pro Scripter
Posts: 110
Joined: Thu Apr 08, 2010 6:11 am
Location: Hørsholm, Denmark
Contact:

Post by SteenJakobsen » Mon May 03, 2010 9:38 am

Hi,

I have it working just file :-)

Here is my simple code
SRT>MoveToSecondMonitor
// Number of monitors
Let>SM_CMONITORS=80
// Virtual Width
Let>SM_CXVIRTUALSCREEN=78
// Virtual Height
Let>SM_CYVIRTUALSCREEN=79
LibFunc>user32,GetSystemMetrics,mcnt,SM_CMONITORS

LibFunc>user32,GetSystemMetrics,vsw,SM_CXVIRTUALSCREEN
LibFunc>user32,GetSystemMetrics,vsh,SM_CYVIRTUALSCREEN

If>%mcnt%>1 Then
let>%NewX%={(%vsw%/2) + 1}
WindowAction>0,DM.scp*
MoveWindow>DM.scp*,%newX%,1
WindowAction>1,DM.scp*
EndIf

//MessageModal>You have %mcnt% monitors%CRLF%Virtual Screen Size: %vsw%x%vsh% px
END>MoveToSecondMonitor
Best Regards
Steen Jakobsen
DM Software A/S

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts