Sign in to follow this  
Followers 0
Cybernetic

Dual monitor resolution question

5 posts in this topic

Hello all,

I did a quick search on this and didnt find what i was looking for, so here i am asking for help.

I have a GUI which gets scaled based on the resolution of the current computer.

IE: $GUI = GUICreate("Test", @DesktopWidth / 1.5, @DesktopHeight / 1.5, @DesktopWidth / 6, @DesktopHeight / 6)

Now this works just fine when you only have 1 monitor. However, if you have 2 or more monitors, it will spread the GUI across all the monitors and it looks stretched and dumb.

Is there a way to make it only use 1 monitor even if you have multiple monitors?

Thank you for any help.

Share this post


Link to post
Share on other sites



Search again :)

There are a few (I know, I've responded to them)

Here is the main functions

#Region thanks to xrxca for these functions
Func _GetMonitorFromPoint($XorPoint = 0, $y = 0)
    Local $MousePos, $myX, $myY
    If @NumParams = 0 Then
        $MousePos = MouseGetPos()
        $myX = $MousePos[0]
        $myY = $MousePos[1]
    ElseIf (@NumParams = 1) And IsArray($XorPoint) Then
        $myX = $XorPoint[0]
        $myY = $XorPoint[1]
    Else
        $myX = $XorPoint
        $myY = $y
    EndIf
    If $__MonitorList[0][0] == 0 Then
        _GetMonitors()
    EndIf
    Local $i = 0
    Local $Monitor = 0
    For $i = 1 To $__MonitorList[0][0]
        If ($myX >= $__MonitorList[$i][1]) _
                And ($myX < $__MonitorList[$i][3]) _
                And ($myY >= $__MonitorList[$i][2]) _
                And ($myY < $__MonitorList[$i][4]) Then $Monitor = $i
    Next
    Return $Monitor
EndFunc   ;==>_GetMonitorFromPoint

Func _GetMonitors()
    $__MonitorList[0][0] = 0 ;  Added so that the global array is reset if this is called multiple times
    Local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnd;hwnd;ptr;lparam")
    DllCall("user32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0)
    DllCallbackFree($handle)
    Local $i = 0
    For $i = 1 To $__MonitorList[0][0]
        If $__MonitorList[$i][1] < $__MonitorList[0][1] Then $__MonitorList[0][1] = $__MonitorList[$i][1]
        If $__MonitorList[$i][2] < $__MonitorList[0][2] Then $__MonitorList[0][2] = $__MonitorList[$i][2]
        If $__MonitorList[$i][3] > $__MonitorList[0][3] Then $__MonitorList[0][3] = $__MonitorList[$i][3]
        If $__MonitorList[$i][4] > $__MonitorList[0][4] Then $__MonitorList[0][4] = $__MonitorList[$i][4]
    Next
    Return $__MonitorList
EndFunc   ;==>_GetMonitors

Func _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam)
    Local $Rect = DllStructCreate("int left;int top;int right;int bottom", $lRect)
    $__MonitorList[0][0] += 1
    ReDim $__MonitorList[$__MonitorList[0][0] + 1][5]
    If $hDC = $hDC Then
    EndIf
    If $lParam = $lParam Then
    EndIf
    $__MonitorList[$__MonitorList[0][0]][0] = $hMonitor
    $__MonitorList[$__MonitorList[0][0]][1] = DllStructGetData($Rect, "left")
    $__MonitorList[$__MonitorList[0][0]][2] = DllStructGetData($Rect, "top")
    $__MonitorList[$__MonitorList[0][0]][3] = DllStructGetData($Rect, "right")
    $__MonitorList[$__MonitorList[0][0]][4] = DllStructGetData($Rect, "bottom")
    Return 1 ; Return 1 to continue enumeration
EndFunc   ;==>_MonitorEnumProc
#EndRegion thanks to xrxca for these functions

You'll need to add these globals

Global $__MonitorList[1][5]
$__MonitorList[0][0] = 0

I can't remember off hand which of these 2 functions has it

 _GetMonitors()

or

 _GetMonitorFromPoint()

I believe you use _GetMonitorFromPoint() using your gui's location to get the monitor it's on, Then use that result for your  _GetMonitors(). The resulting array has the width and height in it.

example:

$mainmon = _GetMonitorFromPoint()
If $mainmon = 0 Then $mainmon = 1
$res1 = _GetMonitors()
$curresx = $res1[$mainmon][3]
$curresy = $res1[$mainmon][4]

I use these functions to figure out which screen my program is on and bumps it to the edge of the screen if someone tries to move it off screen so I know they will do what you need. Just need to play a little.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

Hi,

 Thanks for the response, however, the comp im trying to get this working on has 3 monitors and it is setup so all 3 monitors are acting as 1 monitor. I didnt realise this before.

Now that i know this, im not going to worry about it.

Thank you for your help anyway.

Share this post


Link to post
Share on other sites

I do hope you come back to this thread because I think I may have an idea that could help you get on the right track.

Are all your monitors the same size? you can divide the total width by 3 to get each resolution then scale from there.

Then it's just a matter of maths to get it positioned where you want (0,0 for the first monitor's corner, 1281,0 for the second, etc)


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
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
Sign in to follow this  
Followers 0