Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

What's wrong with my understanding of this code?

$
0
0

I found this thread started by chuber while searching for a way to get the useable desktop area (size of primary monitor desktop minus taskbar).

 

My first bit of bafflement was why the code written by chuber does not match the quote of his code in the reply that follows his post.

 

Since I didn't want to tackle figuring out Sysinternal's debug viewer I went with the version of his code that omits all the lines starting with "If $DEBUG_001...". (more is omitted than that but I think it's missing only comments)  I'll paste this version below. It compiles fine.

 

What chuber posted is a function. So my first goal is to write a simple MsgBox that will show me the results of his function.

 

When I insert a simple MsgBox to see the results of his function...

MsgBox(0,"test",$aDesktop_Pos[0])

...I get an error saying "Subscript used with non-Array variable.", yet he used $aDesktop_Pos as an array variable throughout his function and it's a global variable. What part of this do I not understand and how can I extract the info I'm seeking?

 

Here's the code from the original thread.

AutoIt         
  1. ;
  2. #cs
  3.     Script:        Desktop client size and Taskbar position (code snippet)
  4.     Author:        Bruce Huber (cbruce)
  5.     AutoIt:        v3.2.12.1
  6.     Date:        2008.08.13 - Original release
  7.  
  8.     Purpose:
  9.         Determine whether the Taskbar is visible or hidden and where it is docked on the Desktop.
  10.         Also calculate the available Desktop client region, accounting for any Taskbar space.
  11. #ce
  12.  
  13. ;    Desktop and Taskbar position information - GetDesktopAndTaskbarPos().
  14. Global Enum $DTP_X, $DTP_Y, $DTP_W, $DTP_H
  15. Global $aDesktop_Pos, $aTaskbar_Pos
  16. Global Enum $TBDL_UNKNOWN, $TBDL_LEFT, $TBDL_RIGHT, $TBDL_TOP, $TBDL_BOTTOM
  17. Global $Taskbar_Dock_Location = $TBDL_UNKNOWN
  18. Global $Taskbar_Visible
  19.  
  20.  
  21. Func GetDesktopAndTaskbarPos()
  22.     ;    Get the Desktop size - which includes the Taskbar space, if the Taskbar is visible.
  23.     $aDesktop_Pos = WinGetPos( "Program Manager")
  24.     ;    Get the Taskbar size.
  25.     $aTaskbar_Pos = WinGetPos( "[Class:Shell_TrayWnd]")
  26.     ;    Determine if Taskbar is taking up space on the Desktop.
  27.     If ( $aTaskbar_Pos[$DTP_X] > -3) And ( $aTaskbar_Pos[$DTP_Y] > -3) And ( $aTaskbar_Pos[$DTP_X] < ( $aDesktop_Pos[$DTP_W] - 5)) And ( $aTaskbar_Pos[$DTP_Y] < ( $aDesktop_Pos[$DTP_H] - 5)) Then
  28.         ;    Taskbar is Visible.
  29.         $Taskbar_Visible = True
  30.         ;    Calculate the parameters of the AVAILABLE Desktop client region.
  31.         If ( $aTaskbar_Pos[$DTP_X] < 1) and ( $aTaskbar_Pos[$DTP_Y] > 0) and ( $aTaskbar_Pos[$DTP_W] > $aTaskbar_Pos[$DTP_H]) Then
  32.             ;    Taskbar is on the BOTTOM.
  33.             $Taskbar_Dock_Location = $TBDL_BOTTOM
  34.             ;    We need to adjust the Desktop Height.
  35.             $aDesktop_Pos[$DTP_H] = $aTaskbar_Pos[$DTP_Y] - 1
  36.         ElseIf ( $aTaskbar_Pos[$DTP_X] < 1) and ( $aTaskbar_Pos[$DTP_Y] < 1) and ( $aTaskbar_Pos[$DTP_W] < $aTaskbar_Pos[$DTP_H]) Then
  37.             ;    Taskbar is on the LEFT.
  38.             $Taskbar_Dock_Location = $TBDL_LEFT
  39.             ;    We need to adjust the Desktop X and Width.
  40.             $aDesktop_Pos[$DTP_X] = $aTaskbar_Pos[$DTP_X] + $aTaskbar_Pos[$DTP_W] + 1
  41.             $aDesktop_Pos[$DTP_W] = $aTaskbar_Pos[$DTP_X] - 1
  42.         ElseIf ( $aTaskbar_Pos[$DTP_X] > 0) and ( $aTaskbar_Pos[$DTP_Y] < 1) and ( $aTaskbar_Pos[$DTP_W] < $aTaskbar_Pos[$DTP_H]) Then
  43.             ;    Taskbar is on the RIGHT.
  44.             $Taskbar_Dock_Location = $TBDL_RIGHT
  45.             ;    We need to adjust the Desktop Width.
  46.             $aDesktop_Pos[$DTP_W] = $aTaskbar_Pos[$DTP_X] - 1
  47.         ElseIf ( $aTaskbar_Pos[$DTP_X] < 1) and ( $aTaskbar_Pos[$DTP_Y] < 1) and ( $aTaskbar_Pos[$DTP_W] > $aTaskbar_Pos[$DTP_H]) Then
  48.             ;    Taskbar is on the TOP.
  49.             $Taskbar_Dock_Location = $TBDL_TOP
  50.             ;    We need to adjust the Desktop Y and Height.
  51.             $aDesktop_Pos[$DTP_Y] = $aTaskbar_Pos[$DTP_Y] + $aTaskbar_Pos[$DTP_H] + 1
  52.             $aDesktop_Pos[$DTP_H] = $aTaskbar_Pos[$DTP_Y] - 1
  53.         Else
  54.             ;    Where the heck has the Taskbar gone?
  55.             $Taskbar_Dock_Location = $TBDL_UNKNOWN
  56.         EndIf
  57.     Else
  58.         ;    Taskbar is Hidden.
  59.         $Taskbar_Visible = False
  60.     EndIf
  61.     #cs
  62.             $aDesktop_Pos now contains parameters that only define the AVAILABLE Desktop client region.  This will
  63.         be the entire Desktop if the Taskbar is hidden.  Otherwise, the region will be the Desktop area minus the
  64.         Taskbar area.
  65.  
  66.             $Taskbar_Dock_Location now specifies WHERE, on the Desktop, that the Taskbar is docked.
  67.     #ce
  68. EndFunc   ; GetDesktopAndTaskbarPos()
  69. ;

I realize there's a post in another thread that uses a different approach to finding the data I seek but all I need are "x,y,h,w" and I can't figure out how to extact that info from the script provided in that code (copy pasted below).  This is humbling.

AutoIt         
  1. Global Const $MONITOR_DEFAULTTONULL     = 0x00000000
  2. Global Const $MONITOR_DEFAULTTOPRIMARY  = 0x00000001
  3. Global Const $MONITOR_DEFAULTTONEAREST  = 0x00000002
  4.  
  5. Global Const $CCHDEVICENAME             = 32
  6. Global Const $MONITORINFOF_PRIMARY      = 0x00000001
  7.  
  8.  
  9. $hMonitor = GetMonitorFromPoint(0, 0)
  10. ;$hMonitor = GetMonitorFromPoint(-2, 0)
  11. ;$hMonitor = GetMonitorFromPoint(@DesktopWidth, 0)
  12.  
  13. If $hMonitor <> 0 Then
  14.     Dim $arMonitorInfos[4]
  15.     If GetMonitorInfos($hMonitor, $arMonitorInfos) Then _
  16.         Msgbox(0, "Monitor-Infos", "Rect-Monitor" & @Tab & ": " & $arMonitorInfos[0] & @LF & _
  17.                             "Rect-Workarea" & @Tab & ": " & $arMonitorInfos[1] & @LF & _
  18.                             "PrimaryMonitor?" & @Tab & ": " & $arMonitorInfos[2] & @LF & _
  19.                             "Devicename" & @Tab & ": " & $arMonitorInfos[3])
  20.  
  21.  
  22. Func GetMonitorFromPoint($x, $y)
  23.     $hMonitor = DllCall("user32.dll", "hwnd", "MonitorFromPoint", _
  24.                                             "int", $x, _
  25.                                             "int", $y, _
  26.                                             "int", $MONITOR_DEFAULTTONULL)
  27.     Return $hMonitor[0]
  28.  
  29.  
  30. Func GetMonitorInfos($hMonitor, ByRef $arMonitorInfos)
  31.     Local $stMONITORINFOEX = DllStructCreate("dword;int[4];int[4];dword;char[" & $CCHDEVICENAME & "]")
  32.     DllStructSetData($stMONITORINFOEX, 1, DllStructGetSize($stMONITORINFOEX))
  33.  
  34.     $nResult = DllCall("user32.dll", "int", "GetMonitorInfo", _
  35.                                             "hwnd", $hMonitor, _
  36.                                             "ptr", DllStructGetPtr($stMONITORINFOEX))
  37.     If $nResult[0] = 1 Then
  38.         $arMonitorInfos[0] = DllStructGetData($stMONITORINFOEX, 2, 1) & ";" & _
  39.             DllStructGetData($stMONITORINFOEX, 2, 2) & ";" & _
  40.             DllStructGetData($stMONITORINFOEX, 2, 3) & ";" & _
  41.             DllStructGetData($stMONITORINFOEX, 2, 4)
  42.         $arMonitorInfos[1] = DllStructGetData($stMONITORINFOEX, 3, 1) & ";" & _
  43.             DllStructGetData($stMONITORINFOEX, 3, 2) & ";" & _
  44.             DllStructGetData($stMONITORINFOEX, 3, 3) & ";" & _
  45.             DllStructGetData($stMONITORINFOEX, 3, 4)
  46.         $arMonitorInfos[2] = DllStructGetData($stMONITORINFOEX, 4)
  47.         $arMonitorInfos[3] = DllStructGetData($stMONITORINFOEX, 5)
  48.     EndIf
  49.  
  50.     Return $nResult[0]

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>