Jump to content

Multiple monitor positions and dimensions


Recommended Posts

I know a little about DLLs and Structs, but not quite enough to figure out how this works. Basically, I want to be able to create a window that is exactly the right size and position to completely fill up any given monitor except for the primary one attached to a system. To do this I need to find out how many monitors are attached (so the program will fail if there's only one monitor, and offer a choice if there's more than two), and what the dimensions and absolute positions of each monitor are.

MSDN has this information about monitors, but I couldn't make heads nor tails of it:

http://msdn.microsoft.com/library/default....onitor_8woj.asp

And while searching around, I found this, which looks very helpful but it's in VB:

http://www.vbaccelerator.com/home/vb/Tips/...ors/article.asp

Can any experienced developers give me a hand with the DLL calls, or maybe find another (hopefully easier) way to get this done?

Edited by Sokko
Link to comment
Share on other sites

Hi,

to get the list of monitors maybe scriptomatic will help you out.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Thanks for the pointer. Unfortunately, I was unable to find a class that would provide the needed information, though admittedly I don't really know anything at all about classes or WMI. Have you found a class that provides the multiple-monitor info?

Link to comment
Share on other sites

just on the fly before I'm going to LV...

Global Const $MONITOR_DEFAULTTONULL     = 0x00000000
Global Const $MONITOR_DEFAULTTOPRIMARY  = 0x00000001
Global Const $MONITOR_DEFAULTTONEAREST  = 0x00000002

Global Const $CCHDEVICENAME             = 32
Global Const $MONITORINFOF_PRIMARY      = 0x00000001


$hMonitor = GetMonitorFromPoint(0, 0)
;$hMonitor = GetMonitorFromPoint(-2, 0)
;$hMonitor = GetMonitorFromPoint(@DesktopWidth, 0)

If $hMonitor <> 0 Then
    Dim $arMonitorInfos[4]
    If GetMonitorInfos($hMonitor, $arMonitorInfos) Then _
        Msgbox(0, "Monitor-Infos", "Rect-Monitor" & @Tab & ": " & $arMonitorInfos[0] & @LF & _
                            "Rect-Workarea" & @Tab & ": " & $arMonitorInfos[1] & @LF & _
                            "PrimaryMonitor?" & @Tab & ": " & $arMonitorInfos[2] & @LF & _
                            "Devicename" & @Tab & ": " & $arMonitorInfos[3])
EndIf

Exit

Func GetMonitorFromPoint($x, $y)
    $hMonitor = DllCall("user32.dll", "hwnd", "MonitorFromPoint", _
                                            "int", $x, _
                                            "int", $y, _
                                            "int", $MONITOR_DEFAULTTONULL)
    Return $hMonitor[0]
EndFunc


Func GetMonitorInfos($hMonitor, ByRef $arMonitorInfos)
    Local $stMONITORINFOEX = DllStructCreate("dword;int[4];int[4];dword;char[" & $CCHDEVICENAME & "]")
    DllStructSetData($stMONITORINFOEX, 1, DllStructGetSize($stMONITORINFOEX))

    $nResult = DllCall("user32.dll", "int", "GetMonitorInfo", _
                                            "hwnd", $hMonitor, _
                                            "ptr", DllStructGetPtr($stMONITORINFOEX))
    If $nResult[0] = 1 Then
        $arMonitorInfos[0] = DllStructGetData($stMONITORINFOEX, 2, 1) & ";" & _
            DllStructGetData($stMONITORINFOEX, 2, 2) & ";" & _
            DllStructGetData($stMONITORINFOEX, 2, 3) & ";" & _
            DllStructGetData($stMONITORINFOEX, 2, 4)
        $arMonitorInfos[1] = DllStructGetData($stMONITORINFOEX, 3, 1) & ";" & _
            DllStructGetData($stMONITORINFOEX, 3, 2) & ";" & _
            DllStructGetData($stMONITORINFOEX, 3, 3) & ";" & _
            DllStructGetData($stMONITORINFOEX, 3, 4)
        $arMonitorInfos[2] = DllStructGetData($stMONITORINFOEX, 4)
        $arMonitorInfos[3] = DllStructGetData($stMONITORINFOEX, 5)
    EndIf
    
    Return $nResult[0]
EndFunc

Maybe you find it helpfull...

Holger

Link to comment
Share on other sites

Wow, thanks! I'll be sure to save that code for later. In this case, though, I just recently found an easier way around it: Have the user drag a "stub" window onto the desired monitor and click a button, then delete the stub, create the actual GUI at the same location (using WinGetPos) with the $WS_MAXIMIZE style, and retrieve its width and height to get the monitor's dimensions (again with WinGetPos).

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...