Jump to content

Rezising options for _GUICtrlTreeView_Create


Tjalve
 Share

Recommended Posts

Hello fellow coders.

Im currently making a GUI for a webapp. Im using a REST API to get information and display this in a Tree view. Its basically a scheduler of "tasks" and these tasks are great to display in a tree view.

The problem im having is that on some servers the tree can get rather large. So my GUI is reziable in ordet to be able to fit all the tasks in the view. I have then used GUICtrlSetResizing with diffrent options to get the GUI to look alright even when i resize it. It works fine an all GUI elements, except for the Tree-view. And if i remember correctly, the treeview item is another type of object and you cannot use regular GUI functions on it. Therefor im wondering of there are any alternatives?

 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 208, 220, 192, 124,$WS_SIZEBOX)
$idTV = _GUICtrlTreeView_Create($Form1, 4, 25, 200, 140)
GUICtrlSetResizing(-1,$GUI_DOCKMENUBAR)
$Button1 = GUICtrlCreateButton("Button1", 8, 168, 75, 25)
GUICtrlSetResizing(-1,$GUI_DOCKSTATEBAR)
$Text = GUICtrlCreateLabel("Text", 8, 8, 25, 17)
GUICtrlSetResizing(-1,$GUI_DOCKMENUBAR)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

This code is an example of my problem (run it and try to resize the window). If anyone has any ideas i would appreciate it :) 

Link to comment
Share on other sites

Can you elaborate on what you are doing with _GUICtrlTreeView_Create that you cannot do with GUICtrlCreateTreeView or what GuiTreeView UDF functions do not work with the "native" control?

Link to comment
Share on other sites

2 hours ago, Tjalve said:

I know that. But since i use a lot of the functionality from _GUICtrlTreeView_Create, i cannot just switch.

All or nearly most functions from GuiTreeView.UDF works with a native treeviewcontrol using the controlid. With using the handle (ControlGetHandle) of a native treeviewcontrol all functions are working.

Edited by AutoBert
Link to comment
Share on other sites

Im using several functions form the UDF. See list below. So you are saying that i could use these functions with the native function? That would be ideal if course. If so, how?

_GUICtrlTreeView_SetNormalImageList
_GUICtrlTreeView_Expand
_GUICtrlTreeView_DeleteAll
_GUICtrlTreeView_GetSelection
_GUICtrlTreeView_GetParentHandle
_GUICtrlTreeView_Add
_GUICtrlTreeView_AddChild
 

Link to comment
Share on other sites

Here a example using GUICtrlCreateTreeView and some functions of GuiTreeView.au3:

Spoiler
; *** Start added by AutoIt3Wrapper ***
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <APIShellExConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>
#include <File.au3>

Global Const $tagSHFILEINFO = 'ptr hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];'
Global $FOLDER_ICON_INDEX = _GUIImageList_GetFileIconIndex(@SystemDir, True, 1)
;Global $UP_ICON_INDEX = _GUIImageList_GetFileIconIndex($sIconDir & 'up.ico', True, 1)

;ConsoleWrite($sAutoItPath&@CRLF)

Global $idTV, $idRoot, $hIcon
Global $aDirs, $aFiles

; Create GUI
Global $hGui = GUICreate("Demo _GUICtrlTreeView_AddChild", 500, 700, 0, 0, $WS_SIZEBOX)
GUISetFont(14)
$idTV = GUICtrlCreateTreeView(2, 2, 494, 594)
GUICtrlSetResizing(-1, $GUI_DOCKTOP)
;$hTV = ControlGetHandle($hGui, '', $idTV)
;use $hTV if needed, the controlid is not accepted
_GUICtrlTreeView_SetNormalImageList($idTV, _GUIImageList_GetSystemImageList(True))
GUISetState(@SW_SHOW)
Global $sAutoItPath = StringReplace(StringReplace(@AutoItExe, '_x64', ''), 'autoit3.exe', '')
If Not FileExists($sAutoItPath & 'autoit3.exe') Then
    $sAutoItPath = ''
    If MsgBox($MB_YESNO, 'Ordner nicht gefunden', 'Möchten Sie selbst danach suchen?', 0, $hGui) = 6 Then
        $sAutoItPath = FileSelectFolder('AutoIt Ordner manuell suchen', 'c:\')
    EndIf
    If $sAutoItPath = '' Then Exit
EndIf

$idRoot = _GUICtrlTreeView_Add($idTV, 0, $sAutoItPath, $FOLDER_ICON_INDEX)
$aDirs = _FileListToArray($sAutoItPath, '*', 2)
If Not @error Then
    For $i = 1 To $aDirs[0]
        ; Add items
        _GUICtrlTreeView_AddChild($idTV, $idRoot, $aDirs[$i], $FOLDER_ICON_INDEX, $FOLDER_ICON_INDEX)
    Next
EndIf
$aFiles = _FileListToArray($sAutoItPath, '*', 1)
If Not @error Then
    For $i = 1 To $aFiles[0]
        ; Add items
        $hIcon = _GUIImageList_GetFileIconIndex($aFiles[$i], True)
        _GUICtrlTreeView_AddChild($idTV, $idRoot, $aFiles[$i], $hIcon);,$hIcon)
    Next
EndIf
_GUICtrlTreeView_Expand($idTV)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()


; Author: progandy (www.autoit.de)
Func _GUIImageList_GetSystemImageList($bLargeIcons = False)
    Local $dwFlags, $hIml, $FileInfo = DllStructCreate($tagSHFILEINFO)
    $dwFlags = BitOR($SHGFI_USEFILEATTRIBUTES, $SHGFI_SYSICONINDEX)
    If Not ($bLargeIcons) Then
        $dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
    EndIf
;~    '// Load the image list - use an arbitrary file extension for the
;~    '// call to SHGetFileInfo (we don't want to touch the disk, so use
;~    '// FILE_ATTRIBUTE_NORMAL && SHGFI_USEFILEATTRIBUTES).
    $hIml = _WinAPI_SHGetFileInfo(".txt", $FILE_ATTRIBUTE_NORMAL, _
            DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), $dwFlags)
    Return $hIml
EndFunc   ;==>_GUIImageList_GetSystemImageList

; Author: progandy (www.autoit.de)
Func _WinAPI_SHGetFileInfo($pszPath, $dwFileAttributes, $psfi, $cbFileInfo, $uFlags)
    Local $return = DllCall("shell32.dll", "dword_ptr", "SHGetFileInfo", "str", $pszPath, "DWORD", $dwFileAttributes, "ptr", $psfi, "UINT", $cbFileInfo, "UINT", $uFlags)
    If @error Then Return SetError(@error, 0, 0)
    Return $return[0]
EndFunc   ;==>_WinAPI_SHGetFileInfo

; Author: progandy (www.autoit.de)
Func _GUIImageList_GetFileIconIndex($sFileSpec, $bLargeIcons = False, $bForceLoadFromDisk = False)
    Local $dwFlags, $FileInfo = DllStructCreate($tagSHFILEINFO)
    $dwFlags = $SHGFI_SYSICONINDEX
    If $bLargeIcons Then
        $dwFlags = BitOR($dwFlags, $SHGFI_LARGEICON)
    Else
        $dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
    EndIf
;~ ' We choose whether to access the disk or not. If you don't
;~ ' hit the disk, you may get the wrong icon if the icon is
;~ ' not cached. But the speed is very good!
    If Not $bForceLoadFromDisk Then $dwFlags = BitOR($dwFlags, $SHGFI_USEFILEATTRIBUTES)
;~ ' sFileSpec can be any file. You can specify a
;~ ' file that does not exist and still get the
;~ ' icon, for example sFileSpec = "C:\PANTS.DOC"
    Local $lR = _WinAPI_SHGetFileInfo( _
            $sFileSpec, $FILE_ATTRIBUTE_NORMAL, DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), _
            $dwFlags _
            )
    If ($lR = 0) Then
        Return SetError(1, 0, -1)
    Else
        Return DllStructGetData($FileInfo, "iIcon")
    EndIf
EndFunc   ;==>_GUIImageList_GetFileIconIndex

 

 

Link to comment
Share on other sites

On 6/29/2018 at 6:02 PM, Tjalve said:

Im using several functions form the UDF. See list below

All of the functions you listed have examples in the help file which use the native GUICtrlCreateTreeView function, and not the _GUICtrlTreeView_Create.  

Link to comment
Share on other sites

Clearly there has been some development on this since i last worked on it.
I appreciate the help and the code examples and i will read it thoroughly and report back if i got everything to work. 

Thank you both AutoBert and spudw2k.

Link to comment
Share on other sites

Hi again i almost got it to work. The problem im having now is That i need to use _GUICtrlTreeView_AddChild in order to get the icons working (just as AutoBert did in his example). The problem with that is that my fuction to have some actions when an item is selected, no longer works.

I think i actullt got some help with this from the forum the last time i tried to do this. Becuase when i select something i need thing A to happen, based on what is selected. I got that working with the help from someone here in forums. To be honest, this is a little bit outside my comfort zone sinze i dont really understand how these actions work. But there is a function called "_WM_NOTIFY" thats used. 

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    ; Create NMTREEVIEW structure
    Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
            "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
            "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
            "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
            "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
            "struct;long PointX;long PointY;endstruct", $lParam)
    If DllStructGetData($tStruct, "hWndFrom") = $idTV Then
        Switch DllStructGetData($tStruct, "Code")
            ; If item selection changed
            Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                Local $hItem = DllStructGetData($tStruct, "NewhItem")
                ; Set flag to selected item handle
                If $hItem Then $hItemSelected = $hItem
        EndSwitch
    EndIf

EndFunc

This works when i use

$idTV = _GUICtrlTreeView_Create($hGui, $iBorderWidth, $iBorderWidth, $aPos[0]-2*$iBorderWidth-400, $aPos[1]-2*$iBorderWidth-30)

But not if i use:

$idTV = GUICtrlCreateTreeView( $iBorderWidth, $iBorderWidth, $aPos[0]-2*$iBorderWidth-400, $aPos[1]-2*$iBorderWidth-30, -1, $WS_EX_CLIENTEDGE )

Resizing works, icons works. But nothing happens when i select something.

So to build on my previous example. This is what I would like to do. This obviously does not work. But i would like to learn how to make it work :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 208, 220, 192, 124,$WS_SIZEBOX)
;~ $idTV = _GUICtrlTreeView_Create($Form1, 4, 25, 200, 140)
$idTV = GUICtrlCreateTreeView(4, 25, 200, 140)
$idRoot = _GUICtrlTreeView_Add($idTV, 0, "Root")
$child1 = _GUICtrlTreeView_AddChild($idTV,$idRoot,"Child1")
$child2 = _GUICtrlTreeView_AddChild($idTV,$child1,"Child2")
_GUICtrlTreeView_Expand($idTV)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idTV
            MsgBox(0,"","Some kind of action when i select one of the child objects")

    EndSwitch
WEnd

 

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