Jump to content

GuiCtrlTreeViewGetItemRect()


eltorro
 Share

GuiCtrlTreeViewGetItemRect()  

7 members have voted

  1. 1. Include this in standard UDFs?

    • Yeah, Sure.
      7
    • Yeah, Maybe.
      0
    • Are you nuts.
      0


Recommended Posts

This function gets the bounding rectangle of a Treeview Item.

;===============================================================================
;
; Description:        _GUICtrlTreeViewGetItemRect
; Parameter(s):        $i_treeview        - controlID
;                    $h_item            - item ID/handle to get the bounding rect of
;                    $b_flag            - If set to True, rect returned is just the text area
;                                      else the rect extends out.
;                    $i_mode            - Mode 0 rect relative to Control x,y,r,b
;                                    - Mode 1 Absoulte points relatvie to window.x,y,r,b
;                                    - Mode 2 (Default) Rect relative to Window x,y,w,h
; Requirement:        None
; Return Value(s):    Returns the item rect on success or 0 otherwise
; User CallTip:
; Author(s):        eltorro <steve@ocotillo.sytes.net>
; Note(s):            Gets the bounding rectangle of a treeview item.
;
;===============================================================================
Func _GuiCtrlTreeViewGetItemRect($i_treeview, $h_item, $b_flag = True, $i_mode = 1)
    Local $st_Rect = DllStructCreate("int;int;int;int")
    If @error Then Return 0
    Local $retval[4], $TVM_GETITEMRECT = (0x1100 + 4) ;$TV_FIRST + 4
    DllStructSetData($st_Rect, 1, GUICtrlGetHandle($h_item))
    If GUICtrlSendMsg($i_treeview, $TVM_GETITEMRECT, $b_flag, DllStructGetPtr($st_Rect)) = 0 Then Return 0
 
    For $x = 0 To 3
        $retval[$x] = DllStructGetData($st_Rect, $x + 1)
    Next
    If $i_mode = 0 Then Return $retval
   
    Local $tv_pos = ControlGetPos("", "", $i_treeview)
    if @error Then Return 0 ; if errors with ControlGetPos
    Switch $i_mode
        Case 1
            $retval[0] += $tv_pos[0]
            $retval[1] += $tv_pos[1]
            $retval[2] += $tv_pos[0]
            $retval[3] += $tv_pos[1]
        Case 2
            $retval[2] -= $retval[0]
            $retval[3] -= $retval[1]
            $retval[0] += $tv_pos[0]
            $retval[1] += $tv_pos[1]
    EndSwitch
   
    Return $retval
EndFunc   ;==>_GuiCtrlTreeViewGetItemRect

This would be a useful inclusion to the standard Treeview UDFs

Steve

Edit1: Clean code, add error check.

Edit2: typo

Edited by eltorro
Link to comment
Share on other sites

Here is your code after little cleaning :D

Func _GuiCtrlTreeViewGetItemRect($i_treeview, $h_item, $b_flag = True, $i_mode = 2)
    Local $st_Rect = DllStructCreate("int;int;int;int")
    If @error Then Return 0
    Local $retval[4], $TVM_GETITEMRECT = (0x1100 + 4) ;$TV_FIRST + 4
    DllStructSetData($st_Rect, 1, GUICtrlGetHandle($h_item))
    If GUICtrlSendMsg($i_treeview, $TVM_GETITEMRECT, $b_flag, DllStructGetPtr($st_Rect)) = 0 Then Return 0
    
    For $x = 0 To 3
        $retval[$x] = DllStructGetData($st_Rect, $x + 1)
    Next
    If $i_mode = 0 Then Return $retval
    
    Local $tv_pos = ControlGetPos("", "", $i_treeview)
    Switch $i_mode
        Case 1
            $retval[0] += $tv_pos[0]
            $retval[1] += $tv_pos[1]
            $retval[2] += $tv_pos[0]
            $retval[3] += $tv_pos[1]
        Case 2
            $retval[2] -= $retval[0]
            $retval[3] -= $retval[1]
            $retval[0] += $tv_pos[0]
            $retval[1] += $tv_pos[1]
    EndSwitch
    
    Return $retval
EndFunc   ;==>_GuiCtrlTreeViewGetItemRect
Edited by Zedna
Link to comment
Share on other sites

  • 2 weeks later...

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