Jump to content
Sign in to follow this  
Tjalve

Rezising options for _GUICtrlTreeView_Create

Recommended Posts

Tjalve

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 :) 

Share this post


Link to post
Share on other sites
AutoBert

GUICtrlSetResizing only works with native controls, so try GUICtrlCreateTreeView.

Share this post


Link to post
Share on other sites
Tjalve

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

Share this post


Link to post
Share on other sites
spudw2k

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?

Share this post


Link to post
Share on other sites
AutoBert
Posted (edited)
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

Share this post


Link to post
Share on other sites
Tjalve

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
 

Share this post


Link to post
Share on other sites
AutoBert

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

 

 

  • Like 1

Share this post


Link to post
Share on other sites
spudw2k
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.  

Share this post


Link to post
Share on other sites
Tjalve

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.

Share this post


Link to post
Share on other sites
Tjalve

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

 

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Skysnake
      By Skysnake
      I think I am missing something obvious
      I want the "color bar" to stretch from side to side (entire width) of the GUI.  On resize it must expand / contract as necessary.  I guess the answer is easy, but I need a bit of help please?
      $hForm = GUICreate('myColor Picker', 300, 200,-1, -1, $WS_MAXIMIZEBOX + $WS_SYSMENU + $WS_CAPTION) ;color the GUI background ;GUISetBkColor($sColorformFile, $hForm) ; set the gui background color ;Local $mycolorLabel = GUICtrlCreateLabel("",10,10,300,10) ; a blank LABEL color bar Local $mycolorLabel = GUICtrlCreateGraphic( -1,-1,300,10) ; a blank GRAPHIC color bar GUICtrlSetResizing($mycolorLabel, $ws_sizebox);$GUI_DOCKMENUBAR);$GUI_DOCKAUTO) ;$GUI_DOCKBORDERS) GUICtrlSetBkColor($mycolorLabel,$sColorformFile) ; set the color for the label  
      This is an extract from here, by @Yashied
      $hForm = GUICreate('myColor Picker', 300, 200,-1, -1, $WS_MAXIMIZEBOX + $WS_SYSMENU + $WS_CAPTION) ;color the GUI background ;GUISetBkColor($sColorformFile, $hForm) ; set the gui background color ;Local $mycolorLabel = GUICtrlCreateLabel("",10,10,300,10) ; a blank LABEL color bar Local $mycolorLabel = GUICtrlCreateGraphic( -1,-1,300,10) ; a blank GRAPHIC color bar GUICtrlSetResizing($mycolorLabel, $ws_sizebox);$GUI_DOCKMENUBAR);$GUI_DOCKAUTO) ;$GUI_DOCKBORDERS) GUICtrlSetBkColor($mycolorLabel,$sColorformFile) ; set the color for the label Specifically my issue is with that $mycolorLabel
      Thanks, Skysnake
       
    • Inververs
      By Inververs
      Help me please with resizing of _GUICtrlComboBox_Create control
      It should resizing like native Combo with
      GUICtrlSetResizing($GUI_CMB_LIST, BitOR($GUI_DOCKRIGHT, $GUI_DOCKLEFT, $GUI_DOCKHEIGHT, $GUI_DOCKTOP)) Thank you.
    • Iczer
      By Iczer
      I have troubles with moving script to 64bit - functions "_GUICtrlTreeView_GetImageIndex()" and "_GUICtrlTreeView_GetText()" stop working without any errors
      treeView control belong some x86 application - and x86 script work with it .
      What i can do about it? Is it bug in UDF?
      #AutoIt3Wrapper_UseX64=Y #include <GuiTreeView.au3> Func SubFunction_GetState($hWnd) Local $TVShandle, $TVSSelHandle, $TVSCount, $TVSParentHandle, $TVSS, $i, $TVSItemHandle, $TVSItemIcon AutoItSetOption("WinTitleMatchMode", 2) WinWaitActive($hWnd) $TVShandle = ControlGetHandle($hWnd, "", "[NAME:_treeView]") $TVSSelHandle = _GUICtrlTreeView_GetSelection($TVShandle) ConsoleWrite(@crlf&"$TVSSelHandle = "&$TVSSelHandle&@crlf&"@Error = "&@error&@crlf) $TVSCount = _GUICtrlTreeView_GetSiblingCount($TVShandle, $TVSSelHandle) ConsoleWrite(@crlf&"$TVSCount = "&$TVSCount&@crlf&"@Error = "&@error&@crlf) $TVSParentHandle = _GUICtrlTreeView_GetParentHandle($TVShandle) ConsoleWrite(@crlf&"$TVSParentHandle = "&$TVSParentHandle&@crlf&"@Error = "&@error&@crlf) Local $TVSS[1] = [0] For $i = 0 To $TVSCount-1 $TVSItemHandle = _GUICtrlTreeView_GetItemByIndex($TVShandle, $TVSParentHandle, $i) ConsoleWrite(@crlf&"$TVSItemHandle = "&$TVSItemHandle&@crlf&"@Error = "&@error&@crlf) $TVSItemIcon = _GUICtrlTreeView_GetImageIndex($TVShandle, $TVSItemHandle) ConsoleWrite("$TVSItemIcon = "&$TVSItemIcon&@crlf&"@Error = "&@error&@crlf) ConsoleWrite("_GUICtrlTreeView_GetText = "&_GUICtrlTreeView_GetText($TVShandle, $TVSItemHandle)&@crlf&"@Error = "&@error&@crlf) If $TVSItemIcon = 7 Then ReDim $TVSS[UBound($TVSS)+1] $TVSS[0] += 1 $TVSS[$TVSS[0]] = $TVSItemHandle ConsoleWrite("_GUICtrlTreeView_GetText = !!!"&@crlf) EndIf Next EndFunc x86 script output:
      $TVSSelHandle = 0x066F3FD0 @Error = 0 $TVSCount = 40 @Error = 0 $TVSParentHandle = 0x003CBFB8 @Error = 0 $TVSItemHandle = 0x066F3930 @Error = 0 $TVSItemIcon = 5 @Error = 0 _GUICtrlTreeView_GetText = Item01 @Error = 0 x64 script output:
      $TVSSelHandle = 0x00000000066F3FD0 @Error = 0 $TVSCount = 40 @Error = 0 $TVSParentHandle = 0x00000000003CBFB8 @Error = 0 $TVSItemHandle = 0x00000000066F3930 @Error = 0 $TVSItemIcon = 0 @Error = 0 _GUICtrlTreeView_GetText = @Error = 0  
    • Terenz
      By Terenz
      Hi
      It's the fist time i'll try to make a gui resizable and i have a problem with it.
      Check this:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.Au3> $hGUI = GUICreate("I'm a test", 521, 372, -1, -1, $WS_SIZEBOX + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) GUICtrlCreateLabel("I'm a label", 35, 253, 55, 17) GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKHCENTER + $GUI_DOCKHEIGHT) $Input = GUICtrlCreateInput("", 12, 269, 100, 21) GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKHCENTER + $GUI_DOCKHEIGHT) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd When is "normal" is the label is centered with the input, when i'm maximize the label is not centered in the input. I know the input become bigger in width and i like it, but there is a way to get the label centered with the input when maximize the window? Thanks
    • xavierh
      By xavierh
      Friends,
      I have written a program that among other things displays data in 3 listboxes. when the window has its original size, it works fine. But if I increase the size the window vertically the listboxes stretch as they should, and I can't select their top entries with the mouse . The last listbox entries are not affected. The more I stretch the window vertically, the more entries become out of reach by the mouse. Also the highest entry that can be selected by the mouse is iffy. It has to be low on the entry.
      But the keyboard arrow keys can select them with no problem.

      The listboxes are resized with the window because of commands like
      GUICtrlSetResizing ( $ControlHandle, $GUI_DOCKTOP + $GUI_DOCKSIZE + $GUI_DOCKRIGHT )
      and that's probably where there is a problem with listview selection.
      My OS is windows 2008R1, and I've tried this using both beta 17 and version 3.3.6.1, if that has anything to do with it.
      Ideas anyone?

      Here is the code to build a sample UI to reproduce the problem. It puts a list the folders into a listbox. Run it, try to select the top entries, then stretch the window vertically and try to select the top entries:

      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt('MustDeclareVars', 1) Dim $Win, $lblFolderList, $lbFolders Main () Func Main () $Win = GUICreate("Test Script", @DesktopWidth / 2 - 255, 188, 192, @DesktopHeight / 2 - 45, $WS_OVERLAPPEDWINDOW);$WS_SIZEBOX + $WS_MINIMIZE) $lblFolderList = GUICtrlCreateLabel("Folders List", 4, 8, 37, 17) GUICtrlSetResizing ( $lblFolderList, $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKTOP ) $lbFolders = GUICtrlCreateList("", 4, 24, 65, 168) GUICtrlSetResizing ( $lbFolders, $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKTOP + $GUI_DOCKBOTTOM ) GUISetState(@SW_SHOW) PopulateFolders() GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 Sleep ( 1000 ) WEnd EndFunc Func OnExit() Exit EndFunc Func PopulateFolders() Dim $Search, $Found Dim $InitDir = "C:\" GUICtrlSetData ( $lbFolders, "|" ) $Search = FileFindFirstFile ( $InitDir & "\*.*" ) if $Search > -1 Then While 1 $Found = FileFindNextFile ( $Search ) if @error Then ExitLoop If @extended = 1 Then GUICtrlSetData ( $lbFolders, $Found ) EndIf WEnd EndIf EndFunc
×