fspafford Posted October 4, 2012 Share Posted October 4, 2012 How can I determine if a window is on my second monitor? I have two monitors. I know about WinGetPos, but how do I get information about the two monitors? Frank Link to comment Share on other sites More sharing options...
BrewManNH Posted October 4, 2012 Share Posted October 4, 2012 If the X position is greater than the X dimensions of the first monitor, it's more than probable it's on the second one. Example, you have 2 monitors, 1440x900 resolution, WinGetPos tells you that the X position of the window is at 2000, then from that you can determine that it's on the second monitor. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
kaotkbliss Posted October 4, 2012 Share Posted October 4, 2012 Sometimes the 2nd monitor uses negative coordinates (-800,-600 for example) 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Mechaflash Posted October 4, 2012 Share Posted October 4, 2012 (edited) $aPos = WinGetPos("Window Title") If $aPos[0] < 0 Or $aPos[0] > @DesktopWidth Then msgbox(0,"","It's on your second monitor") Else msgbox(0,"","It's on your main monitor") EndIf Edited October 4, 2012 by Mechaflash Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
UEZ Posted October 5, 2012 Share Posted October 5, 2012 (edited) $aPos = WinGetPos("Window Title") If $aPos[0] < 0 Or $aPos[0] > @DesktopWidth Then msgbox(0,"","It's on your second monitor") Else msgbox(0,"","It's on your main monitor") EndIf That will only work if your second monitor is on the left or right side of your main monitor. It will not work e.g. if your second monitor is up above. Br, UEZ Edited October 5, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
BrewManNH Posted October 5, 2012 Share Posted October 5, 2012 I suppose in cases where the monitors are above and below, you could use [1] and @DesktopHeight instead of [0] and @DesktopWidth, should work equally as well. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Mechaflash Posted October 5, 2012 Share Posted October 5, 2012 (edited) $aPos = WinGetPos("Window Title") If $aPos[0] < 0 Or $aPos[0] > @DesktopWidth Or $aPos[1] < 0 Or $aPos[1] > @DesktopHeight Then msgbox(0,"","It's on your second monitor") Else msgbox(0,"","It's on your main monitor") EndIf =/ EDIT: or $aPos = WinGetPos("Window Title") If ($aPos[0] < @DesktopDir And $aPos[0] > 0) Or ($aPos[1] < @DesktopWidth And $aPos[1] > 0) Then msgbox(0,"","It's on your main monitor") Else msgbox(0,"","It's on your second monitor") EndIf Edited October 5, 2012 by Mechaflash Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
BrewManNH Posted October 5, 2012 Share Posted October 5, 2012 Mechaflash, I'm not sure that would work because if you have 2 monitors and drag a window around to get its position, you'll see that often times, on a left-right monitor set up, the $apos[1] is going to be negative. This is especially true if the two monitors have different resolutions. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
kaotkbliss Posted October 5, 2012 Share Posted October 5, 2012 There are some functions by xrxca (search the forums) that grab useful info for multi-monitor setups and I've modified his functions to figure out which monitor my Gui was on. Unfortunately it would take a bit of time to untangle the functions from my code and create a generic working example for you. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Mechaflash Posted October 5, 2012 Share Posted October 5, 2012 I created a personal UDF a while ago that will enumerate all Real monitors. It's made only for monitors stacked side-by-side. It returns an array. 0 index is the total monitor count. 1-n goes left to right based on the X position value.#include-once #include <Display_Library_Functions.au3> #include <Array.au3> Func _MonitorMapping() Local $aDisplay, $aMonitors $aDisplay = _DisplayKeySettings(0) For $i = 1 To $aDisplay[0][0] If StringInStr($aDisplay[$i][1], "DISPLAYV") And $aDisplay[$i][7] = 0 Then _ArrayDelete($aDisplay, $i) $aDisplay[0][0]-=1 If $i <= $aDisplay[0][0] Then ExitLoop EndIf Next Dim $aMonitors[UBound($aDisplay)] $aMonitors[0] = $aDisplay[0][0] For $i = 1 To $aDisplay[0][0] $aMonitors[$i] = $aDisplay[$i][2] Next _ArraySort($aMonitors, 0, 1, 0, 0) Return $aMonitors EndFunc Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now