cbruce Posted August 15, 2008 Share Posted August 15, 2008 (edited) The function below does what it says in the comments.But is there a simple WinAPI call, that I can use instead, that will give me just the "available Desktop client region" (ie. Desktop minus any visible Taskbar)? I would swear that there is, but I can't remember it - and I haven't been able to find it by searching.Thanks,cbruce(edited 2008.08.15 - had calculation errors - all fixed - cbruce)expandcollapse popup; #cs Script: Desktop client size and Taskbar position (code snippet) Author: Bruce Huber (cbruce) AutoIt: v3.2.12.1 Date: 2008.08.13 - Original release Purpose: Determine whether the Taskbar is visible or hidden and where it is docked on the Desktop. Also calculate the available Desktop client region, accounting for any Taskbar space. #ce ; Desktop and Taskbar position information - GetDesktopAndTaskbarPos(). Global Enum $DTP_X, $DTP_Y, $DTP_W, $DTP_H Global $aDesktop_Pos, $aTaskbar_Pos Global Enum $TBDL_UNKNOWN, $TBDL_LEFT, $TBDL_RIGHT, $TBDL_TOP, $TBDL_BOTTOM Global $Taskbar_Dock_Location = $TBDL_UNKNOWN Global $Taskbar_Visible Func GetDesktopAndTaskbarPos() $aDesktop_Pos = WinGetPos( "Program Manager") ; Desktop size includes the Taskbar space, if the Taskbar is visible. ; Sample coordinates: ; DESKTOP (x,y,width,height): 0 0 1491 1098 If $DEBUG_001 = True Then DebugPrint( "Desktop window stats (x,y,width,height): " & $aDesktop_Pos[$DTP_X] & " " & $aDesktop_Pos[$DTP_Y] & " " & $aDesktop_Pos[$DTP_W] & " " & $aDesktop_Pos[$DTP_H]) $aTaskbar_Pos = WinGetPos( "[Class:Shell_TrayWnd]") If $DEBUG_001 = True Then DebugPrint( "Taskbar window stats (x,y,width,height): " & $aTaskbar_Pos[$DTP_X] & " " & $aTaskbar_Pos[$DTP_Y] & " " & $aTaskbar_Pos[$DTP_W] & " " & $aTaskbar_Pos[$DTP_H]) ; Determine if Taskbar is taking up space on the Desktop. ; If ( TX > -3) And ( TY > -3) And (TX < ( DW - 5)) And ( TY < ( DH - 5)) Then YES. 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 ; Taskbar is Visible. $Taskbar_Visible = True If $DEBUG_001 = True Then DebugPrint( "Taskbar is Visible.") ; Calculate the parameters of the AVAILABLE Desktop client region. If ( $aTaskbar_Pos[$DTP_X] < 1) and ( $aTaskbar_Pos[$DTP_Y] > 0) and ( $aTaskbar_Pos[$DTP_W] > $aTaskbar_Pos[$DTP_H]) Then ; Taskbar is on the BOTTOM. $Taskbar_Dock_Location = $TBDL_BOTTOM ; Sample coordinates: ; BOTTOM (visible) (x,y,width,height): -2 1070 1495 30 If $DEBUG_001 = True Then DebugPrint( "Taskbar is on the BOTTOM.") ; We need to adjust the Desktop Height. ; DH = TY $aDesktop_Pos[$DTP_H] = $aTaskbar_Pos[$DTP_Y] If $DEBUG_001 = True Then DebugPrint( "[B] Desktop window stats (x,y,width,height): " & $aDesktop_Pos[$DTP_X] & " " & $aDesktop_Pos[$DTP_Y] & " " & $aDesktop_Pos[$DTP_W] & " " & $aDesktop_Pos[$DTP_H]) ElseIf ( $aTaskbar_Pos[$DTP_X] < 1) and ( $aTaskbar_Pos[$DTP_Y] < 1) and ( $aTaskbar_Pos[$DTP_W] < $aTaskbar_Pos[$DTP_H]) Then ; Taskbar is on the LEFT. $Taskbar_Dock_Location = $TBDL_LEFT ; Sample coordinates: ; LEFT (visible) (x,y,width,height): -2 -2 107 1102 If $DEBUG_001 = True Then DebugPrint( "Taskbar is on the LEFT.") ; We need to adjust the Desktop X and Width. ; DX += TW + TX $aDesktop_Pos[$DTP_X] += $aTaskbar_Pos[$DTP_W] + $aTaskbar_Pos[$DTP_X] ; DW -= TW + TX $aDesktop_Pos[$DTP_W] -= $aTaskbar_Pos[$DTP_W] + $aTaskbar_Pos[$DTP_X] If $DEBUG_001 = True Then DebugPrint( "[L] Desktop window stats (x,y,width,height): " & $aDesktop_Pos[$DTP_X] & " " & $aDesktop_Pos[$DTP_Y] & " " & $aDesktop_Pos[$DTP_W] & " " & $aDesktop_Pos[$DTP_H]) ElseIf ( $aTaskbar_Pos[$DTP_X] > 0) and ( $aTaskbar_Pos[$DTP_Y] < 1) and ( $aTaskbar_Pos[$DTP_W] < $aTaskbar_Pos[$DTP_H]) Then ; Taskbar is on the RIGHT. $Taskbar_Dock_Location = $TBDL_RIGHT ; Sample coordinates: ; RIGHT (visible) (x,y,width,height): 1386 -2 107 1102 If $DEBUG_001 = True Then DebugPrint( "Taskbar is on the RIGHT.") ; We need to adjust the Desktop Width. ; DW = TX $aDesktop_Pos[$DTP_W] = $aTaskbar_Pos[$DTP_X] If $DEBUG_001 = True Then DebugPrint( "[R] Desktop window stats (x,y,width,height): " & $aDesktop_Pos[$DTP_X] & " " & $aDesktop_Pos[$DTP_Y] & " " & $aDesktop_Pos[$DTP_W] & " " & $aDesktop_Pos[$DTP_H]) ElseIf ( $aTaskbar_Pos[$DTP_X] < 1) and ( $aTaskbar_Pos[$DTP_Y] < 1) and ( $aTaskbar_Pos[$DTP_W] > $aTaskbar_Pos[$DTP_H]) Then ; Taskbar is on the TOP. $Taskbar_Dock_Location = $TBDL_TOP ; Sample coordinates: ; TOP (visible) (x,y,width,height): -2 -2 1495 30 If $DEBUG_001 = True Then DebugPrint( "Taskbar is on the TOP.") ; We need to adjust the Desktop Y and Height. ; DY += TH + TY $aDesktop_Pos[$DTP_Y] += $aTaskbar_Pos[$DTP_H] + $aTaskbar_Pos[$DTP_Y] ; DH -= TH + TY $aDesktop_Pos[$DTP_H] -= $aTaskbar_Pos[$DTP_H] + $aTaskbar_Pos[$DTP_Y] If $DEBUG_001 = True Then DebugPrint( "[T] Desktop window stats (x,y,width,height): " & $aDesktop_Pos[$DTP_X] & " " & $aDesktop_Pos[$DTP_Y] & " " & $aDesktop_Pos[$DTP_W] & " " & $aDesktop_Pos[$DTP_H]) Else ; Where the heck has the Taskbar gone? $Taskbar_Dock_Location = $TBDL_UNKNOWN If $DEBUG_001 = True Then DebugPrint( "Where the heck has the Taskbar gone?") EndIf Else ; Taskbar is Hidden. $Taskbar_Visible = False ; Sample coordinates: ; BOTTOM (hidden) (x,y,width,height): -2 1096 1495 30 ; LEFT (hidden) (x,y,width,height): -62 -2 64 1102 ; RIGHT (hidden) (x,y,width,height): 1489 -2 64 1102 ; TOP (hidden) (x,y,width,height): -2 -28 1495 30 If $DEBUG_001 = True Then DebugPrint( "Taskbar is Hidden.") EndIf #cs $aDesktop_Pos now contains parameters that only define the AVAILABLE Desktop client region. This will be the entire Desktop if the Taskbar is hidden. Otherwise, the region will be the Desktop area minus the Taskbar area. $Taskbar_Dock_Location now specifies WHERE, on the Desktop, that the Taskbar is docked. #ce EndFunc ; GetDesktopAndTaskbarPos() ; Edited August 16, 2008 by cbruce Link to comment Share on other sites More sharing options...
Malkey Posted August 15, 2008 Share Posted August 15, 2008 (edited) The function below does what it says in the comments. But is there a simple WinAPI call, that I can use instead, that will give me just the "available Desktop client region" (ie. Desktop minus any visible Taskbar)? I would swear that there is, but I can't remember it - and I haven't been able to find it by searching. Thanks, cbruce expandcollapse popup; #cs Script: Desktop client size and Taskbar position (code snippet) Author: Bruce Huber (cbruce) AutoIt: v3.2.12.1 Date: 2008.08.13 - Original release Purpose: Determine whether the Taskbar is visible or hidden and where it is docked on the Desktop. Also calculate the available Desktop client region, accounting for any Taskbar space. #ce ; Desktop and Taskbar position information - GetDesktopAndTaskbarPos(). Global Enum $DTP_X, $DTP_Y, $DTP_W, $DTP_H Global $aDesktop_Pos, $aTaskbar_Pos Global Enum $TBDL_UNKNOWN, $TBDL_LEFT, $TBDL_RIGHT, $TBDL_TOP, $TBDL_BOTTOM Global $Taskbar_Dock_Location = $TBDL_UNKNOWN Global $Taskbar_Visible Func GetDesktopAndTaskbarPos() ; Get the Desktop size - which includes the Taskbar space, if the Taskbar is visible. $aDesktop_Pos = WinGetPos( "Program Manager") ; Get the Taskbar size. $aTaskbar_Pos = WinGetPos( "[Class:Shell_TrayWnd]") ; Determine if Taskbar is taking up space on the Desktop. 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 ; Taskbar is Visible. $Taskbar_Visible = True ; Calculate the parameters of the AVAILABLE Desktop client region. If ( $aTaskbar_Pos[$DTP_X] < 1) and ( $aTaskbar_Pos[$DTP_Y] > 0) and ( $aTaskbar_Pos[$DTP_W] > $aTaskbar_Pos[$DTP_H]) Then ; Taskbar is on the BOTTOM. $Taskbar_Dock_Location = $TBDL_BOTTOM ; We need to adjust the Desktop Height. $aDesktop_Pos[$DTP_H] = $aTaskbar_Pos[$DTP_Y] - 1 ElseIf ( $aTaskbar_Pos[$DTP_X] < 1) and ( $aTaskbar_Pos[$DTP_Y] < 1) and ( $aTaskbar_Pos[$DTP_W] < $aTaskbar_Pos[$DTP_H]) Then ; Taskbar is on the LEFT. $Taskbar_Dock_Location = $TBDL_LEFT ; We need to adjust the Desktop X and Width. $aDesktop_Pos[$DTP_X] = $aTaskbar_Pos[$DTP_X] + $aTaskbar_Pos[$DTP_W] + 1 $aDesktop_Pos[$DTP_W] = $aTaskbar_Pos[$DTP_X] - 1 ElseIf ( $aTaskbar_Pos[$DTP_X] > 0) and ( $aTaskbar_Pos[$DTP_Y] < 1) and ( $aTaskbar_Pos[$DTP_W] < $aTaskbar_Pos[$DTP_H]) Then ; Taskbar is on the RIGHT. $Taskbar_Dock_Location = $TBDL_RIGHT ; We need to adjust the Desktop Width. $aDesktop_Pos[$DTP_W] = $aTaskbar_Pos[$DTP_X] - 1 ElseIf ( $aTaskbar_Pos[$DTP_X] < 1) and ( $aTaskbar_Pos[$DTP_Y] < 1) and ( $aTaskbar_Pos[$DTP_W] > $aTaskbar_Pos[$DTP_H]) Then ; Taskbar is on the TOP. $Taskbar_Dock_Location = $TBDL_TOP ; We need to adjust the Desktop Y and Height. $aDesktop_Pos[$DTP_Y] = $aTaskbar_Pos[$DTP_Y] + $aTaskbar_Pos[$DTP_H] + 1 $aDesktop_Pos[$DTP_H] = $aTaskbar_Pos[$DTP_Y] - 1 Else ; Where the heck has the Taskbar gone? $Taskbar_Dock_Location = $TBDL_UNKNOWN EndIf Else ; Taskbar is Hidden. $Taskbar_Visible = False EndIf #cs $aDesktop_Pos now contains parameters that only define the AVAILABLE Desktop client region. This will be the entire Desktop if the Taskbar is hidden. Otherwise, the region will be the Desktop area minus the Taskbar area. $Taskbar_Dock_Location now specifies WHERE, on the Desktop, that the Taskbar is docked. #ce EndFunc ; GetDesktopAndTaskbarPos() ; Check out the macros:- @DesktopHeight - Height of the desktop screen in pixels. (vertical resolution) @DesktopWidth - Width of the desktop screen in pixels. (horizontal resolution) in help file. If you are concerned about taskbar space on the desktop, the above two marcos should reduce the size of your script. Then again your script works on my xp. Do you want to fix something that's not broken? Personally, I never think about the taskbar and I just use the above macros for the current desktop width and height. Edited August 15, 2008 by Malkey Link to comment Share on other sites More sharing options...
cbruce Posted August 15, 2008 Author Share Posted August 15, 2008 Thanks Malkey, but for my purposes I need to know the position and size of JUST the Desktop Client region (does not include the Taskbar if it's visible). The macros do not take the Taskbar into account. cbruce Link to comment Share on other sites More sharing options...
Skruge Posted August 15, 2008 Share Posted August 15, 2008 Take a look at the GetMonitorInfo function. Holger posted a sample that will give you the information you need.http://www.autoitscript.com/forum/index.ph...st&p=211754Rect-Monitor is the Screen Resolution.Rect-Workarea is the Desktop size (minus the Taskbar)Note that if the Taskbar is set to "AutoHide", the Workarea result always matches the resolution, whether the bar is temporarily visible or not. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
cbruce Posted August 15, 2008 Author Share Posted August 15, 2008 Duh! GetMonitorInfo()... That's what I was trying to remember. Thanks Skruge! cbruce Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now