Jump to content

Click Item in List Help


Recommended Posts

Hello :huh2:

I need some help please, I made two examples the first one is how one would usually go about reading a click tree view item but not in the kind of script I need. I need my tree view to act more like my list view but have no idea how I go about doing that.

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

_Example_1()
_Example_2()
Exit

Func _Example_1()
GUICreate("Exmaple 1", 500, 500)
$Tree = GUICtrlCreateTreeView(0, 0, 200, 400)
$Test = GUICtrlCreateTreeViewItem("Test", $Tree)
$Click_Me_1 = GUICtrlCreateTreeViewItem("Click Me 1", $Test)
$Click_Me_2 = GUICtrlCreateTreeViewItem("Click Me 2", $Test)
$Click_Me_3 = GUICtrlCreateTreeViewItem("Click Me 3", $Test)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Click_Me_1
            MsgBox(0 , "Test", "You Clicked 1")
        Case $Click_Me_2
            MsgBox(0 , "Test", "You Clicked 2")
        Case $Click_Me_3
            MsgBox(0 , "Test", "You Clicked 3")
    EndSwitch
WEnd
EndFunc

Func _Example_2()
GUICreate("Example 2", 500, 500)
$List = GUICtrlCreateList("", 0, 0, 200, 400)
GUICtrlSetData($List, "Click Me 1|Click Me 2|Click Me 3")
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    If $Msg = $List Then MsgBox(0 , "" , GUICtrlRead($List)) ;This is where the magic happens...but how to add it to a tree  :geek: 
WEnd
EndFunc
Link to comment
Share on other sites

Do you mean something like this?

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

_Example_1()
Exit

Func _Example_1()
GUICreate("Exmaple 1", 500, 500)
$Tree = GUICtrlCreateTreeView(0, 0, 200, 400)
$Test = GUICtrlCreateTreeViewItem("Test", $Tree)
$Click_Me_1 = GUICtrlCreateTreeViewItem("Click Me 1", $Test)
GuiCtrlSetState($Click_Me_1, $GUI_FOCUS)
$Click_Me_2 = GUICtrlCreateTreeViewItem("Click Me 2", $Test)
$Click_Me_3 = GUICtrlCreateTreeViewItem("Click Me 3", $Test)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Click_Me_1
            MsgBox(0 , "Test", "You Clicked 1")
        Case $Click_Me_2
            MsgBox(0 , "Test", "You Clicked 2")
        Case $Click_Me_3
            MsgBox(0 , "Test", "You Clicked 3")
    EndSwitch
WEnd
EndFunc

#include <ByteMe.au3>

Link to comment
Share on other sites

Do you mean something like this?

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

_Example_1()
Exit

Func _Example_1()
GUICreate("Exmaple 1", 500, 500)
$Tree = GUICtrlCreateTreeView(0, 0, 200, 400)
$Test = GUICtrlCreateTreeViewItem("Test", $Tree)
$Click_Me_1 = GUICtrlCreateTreeViewItem("Click Me 1", $Test)
GuiCtrlSetState($Click_Me_1, $GUI_FOCUS)
$Click_Me_2 = GUICtrlCreateTreeViewItem("Click Me 2", $Test)
$Click_Me_3 = GUICtrlCreateTreeViewItem("Click Me 3", $Test)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Click_Me_1
            MsgBox(0 , "Test", "You Clicked 1")
        Case $Click_Me_2
            MsgBox(0 , "Test", "You Clicked 2")
        Case $Click_Me_3
            MsgBox(0 , "Test", "You Clicked 3")
    EndSwitch
WEnd
EndFunc

nope, but thanks for trying, what I am looking for is to get rid of the "Case" in the "While Loop" completely because the script needs to be able to make "New Cases"...so the 2nd example shows how it can be done with a "List" and not a "Tree"

My script has to set data to the "List/Tree" and that part can be done very easy but making

If $Msg = $List Then MsgBox(0 , "" , GUICtrlRead($List)) ;This is where the magic happens...but how to add it to a tree  :geek:
work for a "Tree" instead of a "List" has me at a lost :huh2:

[Edited] So to sum it up when I click on a "Option" in the "Tree" it will do a event...like the "List" does but without using "Cases"

Edited by SkellySoul
Link to comment
Share on other sites

#Include <GUITreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>

GUICreate("Exmaple 1", 500, 500)
$Tree = GUICtrlCreateTreeView(0, 0, 200, 400)
$Test = GUICtrlCreateTreeViewItem("Test", $Tree)
$Click_Me_1 = GUICtrlCreateTreeViewItem("Click Me 1", $Test)
$Click_Me_2 = GUICtrlCreateTreeViewItem("Click Me 2", $Test)
$Click_Me_3 = GUICtrlCreateTreeViewItem("Click Me 3", $Test)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    $Handle = _GUICtrlTreeView_GetSelection($Tree)
    $Read_Handle = _GUICtrlTreeView_GetText($Tree, $Handle)
    If $Read_Handle = $Read_Handle Then
        ;This is the same handle, do something...
    Else
        ;A new item has been clicked, do something...
        $Handle = _GUICtrlTreeView_GetSelection($Tree)
        $Read_Handle = _GUICtrlTreeView_GetText($Tree, $Handle)
        MsgBox(0, "", _GUICtrlTreeView_GetText($Tree, $Handle))
    EndIf
WEnd

Another attempt but failed :huh2:

Link to comment
Share on other sites

  • Moderators

SkellySoul,

Welcome to the wonderful world of Windows message handlers! :alien:

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

; Set flag
$fFlag = False

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 200, 300, BitOR($TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)

GUISetState()

; Fill Treeview
_GUICtrlTreeView_BeginUpdate($hTreeView)
$iOverview = _GUICtrlTreeView_Add($hTreeView, 0, "Overview")

For $i = 1 To 15
    $iHello = _GUICtrlTreeView_AddChild($hTreeView, $iOverview, "Item " & $i)
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
_GUICtrlTreeView_Expand($hTreeView)

; Register message
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Loop
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; If flag is set
    If $fFlag  Then
        ; Clear flag
        $fFlag = False
        ; Read and display the text
        ConsoleWrite(_GUICtrlTreeView_GetText ($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) & @CRLF)
    EndIf

WEnd

; Intercept the NOTIFY leassages
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    ; Read the data
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    ; See if it was our treeview and the required code
    Switch $hWndFrom
        Case $hTreeview
            Switch $iCode
                Case $NM_CLICK
                    ; The user has clicked the left mouse button within the control so set the flag
                    $fFlag = True
                    Return 0
            EndSwitch
    EndSwitch
EndFunc

If you are not used to coding with GUIRegisterMsg, I recommend the GUIRegisterMsg tutorial in the Wiki. ;)

Please ask if you have any questions. :huh2:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

SkellySoul,

Welcome to the wonderful world of Windows message handlers! :ph34r:

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

; Set flag
$fFlag = False

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 200, 300, BitOR($TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)

GUISetState()

; Fill Treeview
_GUICtrlTreeView_BeginUpdate($hTreeView)
$iOverview = _GUICtrlTreeView_Add($hTreeView, 0, "Overview")

For $i = 1 To 15
    $iHello = _GUICtrlTreeView_AddChild($hTreeView, $iOverview, "Item " & $i)
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
_GUICtrlTreeView_Expand($hTreeView)

; Register message
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Loop
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; If flag is set
    If $fFlag  Then
        ; Clear flag
        $fFlag = False
        ; Read and display the text
        ConsoleWrite(_GUICtrlTreeView_GetText ($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) & @CRLF)
    EndIf

WEnd

; Intercept the NOTIFY leassages
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    ; Read the data
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    ; See if it was our treeview and the required code
    Switch $hWndFrom
        Case $hTreeview
            Switch $iCode
                Case $NM_CLICK
                    ; The user has clicked the left mouse button within the control so set the flag
                    $fFlag = True
                    Return 0
            EndSwitch
    EndSwitch
EndFunc

If you are not used to coding with GUIRegisterMsg, I recommend the GUIRegisterMsg tutorial in the Wiki. :alien:

Please ask if you have any questions. :huh2:

M23

wow, that is exactly what I was looking for :) , however a small issue...it works fine with "_GUICtrlTreeView_Create()" but not with "GUICtrlCreateTreeView()" for some reason and I need "GUICtrlCreateTreeView()" because I do this...add color.

$Item = GUICtrlCreateTreeViewItem("Paid", $App_Tree)
GUICtrlSetImage($Item, $Application_Resources & "\Type_1.ico")
GUICtrlSetColor($Item, $Tree_Menu_Color)

Thank you for the help though I do appreciate it and if you could kindly help me fix this issue, I should be set ;)

Link to comment
Share on other sites

  • Moderators

SkellySoul,

As the genie said to Aladdin: "Your wish is my command!" :huh2:

Just make these changes to the script: ;)

; Creating TV
$hTreeView = GUICtrlCreateTreeView(10, 10, 200, 300, Default, $WS_EX_CLIENTEDGE) ; Do not need all the styles as they are default with native control
$hTV_Handle = GUICtrlGetHandle(-1) ; Add this line

; In the handler
Switch $hWndFrom
    Case $hTV_Handle ; Change this line to use the Handle and not the ControID

Any other requests? :alien:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

SkellySoul,

As the genie said to Aladdin: "Your wish is my command!" :huh2:

Just make these changes to the script: :(

; Creating TV
$hTreeView = GUICtrlCreateTreeView(10, 10, 200, 300, Default, $WS_EX_CLIENTEDGE) ; Do not need all the styles as they are default with native control
$hTV_Handle = GUICtrlGetHandle(-1) ; Add this line

; In the handler
Switch $hWndFrom
    Case $hTV_Handle ; Change this line to use the Handle and not the ControID

Any other requests? :D

M23

Amazing I have been stuck on this script for a week because I was unable to do this ;)

I would like to thank you very much and everyone else who tried to help :)

lol, I do have another request, but was waiting till this one got solved. I would start a new topic...but if your able to help me with it I won't need to bother opening a new topic and would appreciate it very much :mad2:

I have searched the forum and came nowhere close to finding a answer for this problem :alien:

The problem is having a GUI background with a transparent "Tree View" but with readable text.

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

$Width = 500
$Height = 500

$GUI = GUICreate("Example", $Width, $Height)
$Background = GUICtrlCreatePic(@ScriptDir & "\1.jpg", 0, 0, $Width, $Height)
$Tree = GUICtrlCreateTreeView(0, 0, $Width /2 , $Height)
$General = GUICtrlCreateTreeViewItem("General", $Tree)
GUICtrlSetColor(-1, 0x0000C0)
$Display = GUICtrlCreateTreeViewItem("Display", $Tree)
GUICtrlSetColor(-1, 0x0000C0)
$About = GUICtrlCreateTreeViewItem("About", $General)
$Comp = GUICtrlCreateTreeViewItem("Computer", $General)
$User = GUICtrlCreateTreeViewItem("User", $General)
$Res = GUICtrlCreateTreeViewItem("Resolution", $Display)
$Other = GUICtrlCreateTreeViewItem("Other", $Display)
GUICtrlSetState($General, $GUI_EXPAND)
GUICtrlSetState($Display, $GUI_EXPAND)
GUICtrlSetState($Background, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

If only this worked with a tree :ph34r:

GUICtrlSetBkColor($Tree, $GUI_BKCOLOR_TRANSPARENT)

Posted Image

Thank you very much :D

[Edited]

Valik did not say it's impossible he just said it's not possible...just saving my ass :blink:

but that was in 2006 and I know other languages are able to pull this off so surely Autoit must have some way of pulling it off just as well...

Edited by SkellySoul
Link to comment
Share on other sites

  • Moderators

SkellySoul,

I certainly do not know how to do it - and if Valik says it is not possible..... :huh2:

Try a new thread - but I fear you are going to be disappointed. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I think you're looking for something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WINAPI.au3>
#Include <GuiTreeView.au3>
#include <TreeViewConstants.au3>

Global $GUI_Parent, $GUI_Child, $Ctrl_TreeView, $hTreeView, $Ctrl_TreeView_Parent, $Ctrl_TreeView_Child
Global $iTransColor = 0x01010101 ;experiment to get the best look

$GUI_Parent = GUICreate("Test", 500, 500)
GUICtrlCreatePic(@DesktopDir & "\test.jpg", 0, 0, 500, 500)

#region TreeView
$GUI_Child = GUICreate("", 300, 200, 10, 10, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI_Parent)
$Ctrl_TreeView = GUICtrlCreateTreeView(0,0,300,200,BitOR($TVS_HASBUTTONS, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS))
GUICtrlSetBkColor($Ctrl_TreeView , $iTransColor)
_WinAPI_SetLayeredWindowAttributes($GUI_Child, $iTransColor, 255)
GUISetState(@SW_SHOW,$GUI_Child)
GUISwitch($GUI_Parent)
;~ $hTreeView = GUICtrlGetHandle($Ctrl_TreeView)
For $iParent = 0 To 4
    $Ctrl_TreeView_Parent = GUICtrlCreateTreeViewItem($iParent,$Ctrl_TreeView)
    For $iChild = 0 To 4
        $Ctrl_TreeView_Child = GUICtrlCreateTreeViewItem($iParent & "." & $iChild,$Ctrl_TreeView_Parent)
        For $iChild2 = 0 To 4
            GUICtrlCreateTreeViewItem($iParent & "." & $iChild & "." & $iChild2,$Ctrl_TreeView_Child)
        Next
    Next
Next
#EndRegion

GUISetState()

While 1
    Switch GUIGetMsg()
        Case 0
            ContinueLoop
        Case $GUI_EVENT_CLOSE
            Exit
;~      Case $GUI_EVENT_PRIMARYDOWN
;~          _GetClicked()
    EndSwitch
WEnd

;~ Func _GetClicked()
;~  Local $hItem = _GUICtrlTreeView_HitTestItem($hTreeView, _WinAPI_GetMousePosX(True, $hTreeView), _WinAPI_GetMousePosY(True, $hTreeView))
;~  If $hItem Then
;~      _GUICtrlTreeView_ClickItem($hTreeView,$hItem)
;~      ConsoleWrite($hItem & @CRLF)
;~  Else
;~      ConsoleWrite("Miss" & @CRLF)
;~  EndIf
;~ EndFunc

This is just an example. It has a number of issues:

- Clicking only works on the parts of the treeview that are still visible, making it hard to click an item. (you have to click the actual text of each item)

- The fonts are smoothed against $iTransColor, meaning that, you can either choose a color that results in a pixelated look, or have a trace of the used color around the letters. (experiment untill satisfied)

- I havn't looked into changing the "expand/close" symbol, but I think that should be easy.

I've attempted to improve the clicking behavior in the sections I commented out, but didn't get a nice result.

I think all problems are solvable, but I'm not sure how. Perhaps others have solutions.

Two other things you could look into are swithing all GUICtrlCreateTreeView(Item) with the commands from the TreeView UDF for extra flexibility and changing the background for items to white, It'll look worse, but clicking will be easier.

Link to comment
Share on other sites

  • Moderators

Tvern,

Nice example! :huh2:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

wow thanks a lot to the both of you :)

The example is awesome and it just goes to show that it actually is possible and I will try to get it working how I need it to work but if I have any problems I think I will open up a new topic and I hope the both of you notice it :ph34r:

I know lots of other users have in the passed looked for this functionally and if everyone pulls together to get it working I am sure it could be added as a UDF and that would be absolutely amazing :huh2:

Well time to go try somethings out and have some fun ;)

Thanks to all of you :alien:

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...