Allow2010 Posted April 21, 2015 Share Posted April 21, 2015 Hello, i sometimes have to deal with multimonitor setups. I searched the forums and found quite a lot of threads about this. Most fo them seem to complicated for what i have in mind. When i start a program and drag it to a different monitor, and the close the program, i save the x/y coordinates of the window to start it were it was closed. this works fine as long as i start it on the same PC setup. But when suddenly i use a pc with only one monitor i will end up with a window placed outside the visible area. Is there an easy way to detect that? If yes, i would simply move the window to the center of the screen if it is not visible. I tried windowgetstate, but it seems it can only detect if the state is set to hide and not if the window is off screen... Ideas are welcome:-) Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 21, 2015 Moderators Share Posted April 21, 2015 Allow2010,This thread should allow you to determine the setup with which you are working - then use WinGetPos to get the position of the GUI and then check to see if it is within the available bounds.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Allow2010 Posted April 21, 2015 Author Share Posted April 21, 2015 thanks...i will try that! Link to comment Share on other sites More sharing options...
Allow2010 Posted April 21, 2015 Author Share Posted April 21, 2015 (edited) Edit: i misunderstood the script :-) Edited April 21, 2015 by Allow2010 Link to comment Share on other sites More sharing options...
jguinch Posted April 21, 2015 Share Posted April 21, 2015 (edited) The script allows you to retrieve the desktop size. Can you try with this function : just give the window title in the first parameter : expandcollapse popup; Returns 0 = Not visible ; Returns 1 = Fully viewable ; Returns 2 = Partially viewable ; @error = Window does not exist Func _WinIsOnScreen($vTitle, $sText = "") Local $iDesktopLeft, $iDesktopTop, $iDesktopRight, $iDesktopBottom Local $aDesktopPos[4], $i = 0 Local $hWnd = WinGetHandle($vTitle, $sText) If @error Then Return SetError(@error, 0, 0) If BitAND( WinGetState($hWnd), 32) Then Return 1 ; Window is maximized Local $aPos = WinGetPos($hWnd) If @error Then Return SetError(@error, 0, 0) Local $iWinLeft = $aPos[0] Local $iWinTop = $aPos[1] Local $iWinRight = $iWinLeft + $aPos[2] Local $iWinBottom = $iWinTop + $aPos[3] Local $iNbMonitors = _WinAPI_GetSystemMetrics(80) If $iNbMonitors = 1 Then $iDesktopLeft = 0 $iDesktopTop = 0 $iDesktopRight = _WinAPI_GetSystemMetrics(0) $iDesktopBottom = _WinAPI_GetSystemMetrics(1) Else $iDesktopLeft = _WinAPI_GetSystemMetrics (76) $iDesktopTop = _WinAPI_GetSystemMetrics (77) $iDesktopRight = $iDesktopLeft + _WinAPI_GetSystemMetrics (78) $iDesktopBottom = $iDesktopTop + _WinAPI_GetSystemMetrics (79) EndIf If $iWinLeft < $iDesktopLeft Or $iWinTop < $iDesktopTop Or $iWinRight > $iDesktopRight Or $iWinBottom > $iDesktopBottom Then If $iWinRight < $iDesktopLeft Or $iWinBottom < $iDesktopTop Or $iWinLeft > $iDesktopRight Or $iWinTop > $iDesktopBottom Then Return 0 Return 2 EndIf Return 1 EndFunc ;==> _WinIsOnScreen Edited April 21, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Allow2010 Posted April 21, 2015 Author Share Posted April 21, 2015 (edited) can you explain this line? If BitAND(WinGetState($hWnd), @SW_MAXIMIZE) Then Return 1 is it normal that a minimized window is visible reported as visible? Its no problem, i just have to know:-) Edit: the function does not work.When i move the window outside the screen WinMove("mywindow", "", 2000, 2000, Default, Default, 1) it is still reported as visible Edited April 21, 2015 by Allow2010 Link to comment Share on other sites More sharing options...
jguinch Posted April 21, 2015 Share Posted April 21, 2015 Sorry, I didn't try with a single monitor. I edited my previous post. Can you try again ? The line BitAND(WinGetState($hWnd), @SW_MAXIMIZE) was wrong, it's replaced by a correct line witch test of the window is maximized (returns 1 if it is) A minimized window is not visible, so the function just return 0. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Allow2010 Posted April 22, 2015 Author Share Posted April 22, 2015 Hey, thanks!! This seems to work just fine... It should be mentioned that this may not be 100% accurate when using multiple monitors with different resolutions...or did i miss understand? Link to comment Share on other sites More sharing options...
jguinch Posted April 22, 2015 Share Posted April 22, 2015 All right, you understood. My code is just a draft, but should be adapted to take into account the possibility to have different resolutions. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Allow2010 Posted April 22, 2015 Author Share Posted April 22, 2015 for a draft it is quite good.-) Thanks again... Link to comment Share on other sites More sharing options...
jguinch Posted April 22, 2015 Share Posted April 22, 2015 You can also use _WinAPI_EnumDisplayMonitors to retrieve the monitor resolution and position. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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