Sign in to follow this  
Followers 0
AppTux

Guictrltreeview help

5 posts in this topic

I'm making a program for reading all the drives etc. I made a treeview with the fixed drives and the removable drives.

Now, I want to make it that if you click by example the C: drive in the treeview, you see a different content instead of before you clicked it.

But because every pc has another count of drives, I made a array with max 7 fixed disks.

With the functions I used, the GUIGetMsg() won't work on the items in the treeview.

What should be used to check if the item is clicked.

How can I make a loop or whatever to make it possible to check only for the used items? Otherwise you get always a msg.

My code so far:

$TRVI = GUICtrlCreateTreeView(7, 95, 150, 375)
$TRVIMG = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($TRVIMG, "Data\wdrive-drive-icon.ico", 0)
_GUIImageList_AddIcon($TRVIMG, "Data\wdrive-removable-icon.ico", 0)
_GUIImageList_AddIcon($TRVIMG, "Data\wdrive-wait-icon.ico", 0)
_GUICtrlTreeView_SetNormalImageList($TRVI, $TRVIMG)
$PLWA = _GUICtrlTreeView_Add($TRVI, 0, "Please wait...",2,2)
_GUICtrlTreeView_BeginUpdate($TRVI)
$TVD = _GUICtrlTreeView_Add($TRVI, 0, "Hard disks", 0, 0)
$TVR = _GUICtrlTreeView_Add($TRVI, 0, "Removable hardware", 1, 1)
$DRIVE = DriveGetDrive("FIXED")
$DREM = DriveGetDrive("REMOVABLE")
For $X = 1 To $DRIVE[0]
    If $X > 7 Then ExitLoop
    $DLETTER = _StringProper($DRIVE[$X])
    $LABEL = DriveGetLabel($DRIVE[$X])
    If $LABEL = "" Then
        $TXT = $DLETTER
    Else
        $TXT = $DLETTER & " " & $LABEL
    EndIf
    $FIXED[$X] = _GUICtrlTreeView_AddChild($TRVI, $TVD, $TXT, 0, 0)
Next
For $X = 1 To $DREM[0]
    If $X > 10 Then ExitLoop
    $DLETTER = _StringProper($DREM[$X])
    $LABEL = DriveGetLabel($DREM[$X])
    If $LABEL = "" Then
        $TXT = $DLETTER
    Else
        $TXT = $DLETTER & " " & $LABEL
    EndIf
    $REMOVABLE[$X] = _GUICtrlTreeView_AddChild($TRVI, $TVR, $TXT, 1, 1)
Next
_GUICtrlTreeView_Delete($TRVI,$PLWA)
_GUICtrlTreeView_EndUpdate($TRVI)
_GUICtrlTreeView_Expand($TRVI, 0, True)
_GUICtrlTreeView_SelectItem($TRVI, $TVD)
;---==>End of Treeview---;

I still have no code for getting message from the items.

I really hope you understand what I mean.

Thanks in advance, Apptux


PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.

Share this post


Link to post
Share on other sites



AppTux,

Just posting an orphan snippet like that is not the way to get help quickly. :x

No-one is going to waste their time adding all the missing code to get an idea of what you are trying to do. I would be happy to look at your problem if you post a script which at least runs without errors - i.e. has a GUI, all the required include files and declared arrays.

To give you a good start, this is how you can get the selected treeview item by double-clicking or by using a button:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <Array.au3>

Global $aData[5] = [4, "Item 1", "Item 2", "Item 3", "Item 4"]
Global $aItem_Handles[UBound($aData)]

Global $hMain_GUI = GUICreate("TreeView Demo", 500, 500)

$hTree = GUICtrlCreateTreeView(10, 10, 280, 280)
$hRoot = GUICtrlCreateTreeViewItem("Root", $hTree)
For $i = 1 To $aData[0]
    $aItem_Handles[$i] = GUICtrlGetHandle(GUICtrlCreateTreeViewItem($aData[$i], $hRoot))
Next

$hButton = GUICtrlCreateButton("Check", 10, 400, 80, 30)

GUISetState()

; Initialise "DoubleClick on TreeView function"
GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")

Global $fDblClk = False

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            MsgBox(0, "Read", "The currently selected item is " & GUICtrlRead($hTree, 1))
    EndSwitch

    ; Check if tree view double clicked
    If $fDblClk = True Then
        $sText = _GUICtrlTreeView_GetText($hTree, _GUICtrlTreeView_GetSelection($hTree))
        MsgBox(0, "Hit", "You double clicked on " & $sText )
        $fDblClk = False
    EndIf
WEnd

Func MY_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    Switch $wParam
        Case $hTree
            Local $tagNMHDR = DllStructCreate("int;int;int", $lParam)
            If @error Then Return
            If DllStructGetData($tagNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
    EndSwitch

EndFunc  ;==>MY_WM_NOTIFY

See you soon! :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Sorry for that, I'm not often on this forum, so I don't think about that things... I'm sorry. :x

I'll try to make a working script including the 'missing' code :P

AppTux


PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.

Share this post


Link to post
Share on other sites

Thanks!!!

This works perfect for me.

Now I get the name of the selected treeviewitem, now can I make a function what's reading the name of the item, and put the right content on the right place. I'll modify my script so you can understand what I wanted.

I'll post soon!

AppTux


PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.

Share this post


Link to post
Share on other sites

Modified code:

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <String.au3>

$DRIVE = DriveGetDrive("FIXED")
$DREM = DriveGetDrive("REMOVABLE")
Global $FIXED[$DRIVE[0]+1], $REMOVABLE[$DREM[0]+1], $fDblClk = False

$MGUI = GUICreate("WindowsDrive", 150, 425, -1, -1)
$PCF = GUICtrlCreateLabel("Displays name of selected item", 0, 377, 150, 45, $SS_NOTIFY)
GUICtrlSetBkColor($PCF, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont($PCF, 9, 400, "", "Segoe UI")

GUISetState()

;---Treeview---Why here? Otherwise it won't be displayed;
$TRVI = GUICtrlCreateTreeView(0, 0, 150, 375)
$TRVIMG = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($TRVIMG, "Data\wdrive-drive-icon.ico", 0);harddrive icon
_GUIImageList_AddIcon($TRVIMG, "Data\wdrive-removable-icon.ico", 0);removable media icon
_GUIImageList_AddIcon($TRVIMG, "Data\wdrive-wait-icon.ico", 0);please wait icon
_GUICtrlTreeView_SetNormalImageList($TRVI, $TRVIMG)
$PLWA = _GUICtrlTreeView_Add($TRVI, 0, "Please wait...",2,2)
_GUICtrlTreeView_BeginUpdate($TRVI)
$TVD = _GUICtrlTreeView_Add($TRVI, 0, "Hard disks", 0, 0)
$TVR = _GUICtrlTreeView_Add($TRVI, 0, "Removable media", 1, 1)
For $X = 1 To $DRIVE[0]
    ConsoleWrite("$DRIVE["&$X&"]"&@CR)
    If $X > 7 Then ExitLoop
    $DLETTER = _StringProper($DRIVE[$X])
    $LABEL = DriveGetLabel($DRIVE[$X])
    If $LABEL = "" Then
        $TXT = $DLETTER
    Else
        $TXT = $DLETTER & " " & $LABEL
    EndIf
    $FIXED[$X] = GUICtrlGetHandle(_GUICtrlTreeView_AddChild($TRVI, $TVD, $TXT, 0, 0))
    ;$FIXED[$X] = _GUICtrlTreeView_AddChild($TRVI, $TVD, $TXT, 0, 0)
Next
For $X = 1 To $DREM[0]
    If $X > 10 Then ExitLoop
    $DLETTER = _StringProper($DREM[$X])
    $LABEL = DriveGetLabel($DREM[$X])
    If $LABEL = "" Then
        $TXT = $DLETTER
    Else
        $TXT = $DLETTER & " " & $LABEL
    EndIf
    $REMOVABLE[$X] = _GUICtrlTreeView_AddChild($TRVI, $TVR, $TXT, 1, 1)
Next
_GUICtrlTreeView_Delete($TRVI,$PLWA)
_GUICtrlTreeView_EndUpdate($TRVI)
_GUICtrlTreeView_Expand($TRVI, 0, True)
_GUICtrlTreeView_SelectItem($TRVI, $TVD)
;---==>End of Treeview---;

GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    If $fDblClk = True Then
        $sText = _GUICtrlTreeView_GetText($TRVI, _GUICtrlTreeView_GetSelection($TRVI))
        _SetTheData($sText)
        $fDblClk = False
    EndIf
WEnd
Func _SetTheData($sTXT)
    GUICtrlSetData($PCF,$sTXT);with this name can I go on with displaying it
EndFunc

Func MY_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    Switch $wParam
        Case $TRVI
            Local $tagNMHDR = DllStructCreate("int;int;int", $lParam)
            If @error Then Return
            If DllStructGetData($tagNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
    EndSwitch

EndFunc  ;==>MY_WM_NOTIFY

I hope you now understand what I meant.


PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.

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  
Followers 0