kjpolker Posted July 2, 2023 Share Posted July 2, 2023 (edited) I am looking for a way to get the screen resolution from mouse point which I am having a hard time figuring out. I also would like to identify where the monitor sits. This is so I can "snap" my gui to the correct monitor in the correct location. For example position 1 will snap the gui to the lower left corner of the screen that the mouse is on. I have been playing with Windows API functions but I can't seem to get what I need. Here is an example best I can come up with but doesn't work obviously. #include <WinAPI.au3> #include <WindowsConstants.au3> Local $aMousePos = MouseGetPos() ; Get the current mouse position Local $hMonitor = _WinAPI_MonitorFromPoint($aMousePos[0], $aMousePos[1]) ; Get the handle of the monitor containing the mouse position Local $tMonitorInfo = _WinAPI_GetMonitorInfo($hMonitor) ; Get the monitor information ; Retrieve the monitor resolution Local $iMonitorWidth = DllStructGetData($tMonitorInfo, "Monitor.Right") - DllStructGetData($tMonitorInfo, "Monitor.Left") Local $iMonitorHeight = DllStructGetData($tMonitorInfo, "Monitor.Bottom") - DllStructGetData($tMonitorInfo, "Monitor.Top") ConsoleWrite("Monitor Resolution: " & $iMonitorWidth & "x" & $iMonitorHeight & @CRLF) I have 4 monitors for reference. 3 are 1920x1080 and the middle one is 2560x1440 in the following layout: Edited July 2, 2023 by kjpolker Link to comment Share on other sites More sharing options...
Solution argumentum Posted July 2, 2023 Solution Share Posted July 2, 2023 https://www.autoitscript.com/forum/topic/139260-autoit-snippets/page/22/#comment-1479329 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
kjpolker Posted July 2, 2023 Author Share Posted July 2, 2023 (edited) 23 minutes ago, argumentum said: https://www.autoitscript.com/forum/topic/139260-autoit-snippets/page/22/#comment-1479329 Thank you! I am dissecting it now and understand most of it. Can you assist me in how I would change it to be lower left corner? WinMove($hForm, _ $sText, _ Int($aData[0].Left + $aWinPos[2]), _ Int($aData[0].Bottom) - $aWinPos[3] - WinGetClientSize("[CLASS:Shell_TrayWnd]")) ;Attempt to account for tasbar height I tried the above and apparently I am not understanding it like I thought. Edited July 2, 2023 by kjpolker Link to comment Share on other sites More sharing options...
kjpolker Posted July 2, 2023 Author Share Posted July 2, 2023 Disregard, I believe I understand it. Working with Work Area. Although I will say it seems to be a few pixels off a touch. Not a big deal. WinMove($hForm, _ $sText, _ Int($aData[1].Left), _ Int($aData[1].Bottom) - $aWinPos[3]) argumentum 1 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