Jump to content

Get Client Size from Point (including negatives)


Go to solution Solved by argumentum,

Recommended Posts

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:

image.png.f777987e0f82a238aa8d03b7d03d4421.png

Edited by kjpolker
Link to comment
Share on other sites

23 minutes ago, argumentum said:

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 by kjpolker
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...