Jump to content

Desktop Workarea, multiple monitors


Recommended Posts

I can get the 'workarea' of the primary monitor using:

Func _GetDesktopArea()
  Local Const $SPI_GETWORKAREA = 48
  Local $tWorkArea = DllStructCreate($tagRECT)
  _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))
  Local $aReturn[4] = [DllStructGetData($tWorkArea, "Left"), DllStructGetData($tWorkArea, "Top"), _
          DllStructGetData($tWorkArea, "Right") - DllStructGetData($tWorkArea, "Left"), DllStructGetData($tWorkArea, "Bottom") - DllStructGetData($tWorkArea, "Top")]
  Return $aReturn
EndFunc   ;==>_GetDesktopArea

MSDN says to use GetMonitorInfo() to get workarea of monitors other than the Primary.

However, when I do this the rect I receive from this function for Primary or Secondary is not a workarea, but a fullscreen rect.

#include <WinApi.au3>
#include <Array.au3>
#include <StructureConstants.au3>


;get monitor handles
Local $edm=_WinAPI_EnumDisplayMonitors();$hDC = 0, $tRECT = 0
If @Error Then MsgBox(0,'Error','_WinAPI_EnumDisplayMonitors')

Local $mh1=$edm[2][0]; 1 for first handle, 2 for second
Local $mr1=$edm[1][1]; supposedly a rect

; use my handle to get monitor infos
Local $vh=_WinAPI_GetMonitorInfo($mh1)
If @Error Then MsgBox(0,'Error','_WinAPI_GetMonitorInfo')
; $vh now filled with
; [0] - $tagRECT structure that specifies the display monitor rectangle, in virtual-screen coordinates.
; [1] - $tagRECT structure that specifies the work area rectangle of the display monitor that can be used by applications, in virtual-screen coordinates.
; [2] - 1 (True) for the primary display monitor, or 0 (False) otherwise.
; [3] - The device name of the monitor being used, e.g. "\\.\DISPLAY1".

Local $aReturn[4] = [DllStructGetData($vh[1], 'Left') _
                    ,DllStructGetData($vh[1], 'Top') _
                    ,DllStructGetData($vh[1], 'Right') - DllStructGetData($vh[1], 'Left') _
                    ,DllStructGetData($vh[1], 'Bottom') - DllStructGetData($vh[1], 'Top') _
                    ]

_ArrayDisplay($aReturn)
Exit

So to reiterate- the MonitorInfo workarea rect does not jive with the one gotten with SPI for the Primary monitor, therefore it doesn't work for the Secondary monitor either - it just gets the true (virtual) dimensions.

I smell a Microsoft thing. I have looked on StackOverflow with no success. Can anyone get a workarea!=desktop with this code?

Edited by MarkRobbins
Link to comment
Share on other sites

MarkRobbins got that function from here.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Seems like it returns the correct information.  The reason that it wouldn't return the whole display coords on the first mon is because of the taskbar.  The opposite for the second monitor.  This is my theory.  I'm not a Windows guru.

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

×
×
  • Create New...