Jump to content

Last item in treeview doesn't show expand button


this-is-me
 Share

Recommended Posts

In a dynamically added-to list view, the last item does not have a plus-button. Try this code on XP:

Opt("TrayIconDebug", 1)
#include <guiconstants.au3>
Global $TVS_CHECKBOXES = 0x100
dim $headers[1]
;$delrunning = 0
opt("wintitlematchmode", 4)
Opt("GuiOnEventMode", 1)
$winttl = "Files Listing"
$guihndl = GUICreate($winttl, 500, 300, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_GROUP, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
$tview = GuiCtrlCreateTreeView(0, 0, 500, 300, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES));
GUICtrlSetImage(-1,"shell32.dll",3,4); icon for default nonselected state
GUICtrlSetImage(-1,"shell32.dll",4,2); icon for default selected state
guisetonevent($GUI_EVENT_CLOSE, "exitfunc")
GUISetState(@SW_SHOW)

$drives = DriveGetDrive("fixed")
If Not @error Then
    For $i = 1 To $drives[0]
        $curdrv = StringUpper($drives[$i])
        If DriveStatus($curdrv & "\") = "READY" Then
            If FileExists($curdrv & "\Documents And Settings\") Then
                $users = FileFindFirstFile($curdrv & "\Documents And Settings\*.*")
                If $users <> - 1 Then
                    While 1
                        $cuser = FileFindNextFile($users)
                        If @error Then ExitLoop
                        If $cuser = "All Users" Or $cuser = "Default User" Or $cuser = "LocalService" Or $cuser = "NetworkService" Or $cuser = "." Or $cuser = ".." Then ContinueLoop
                        addfromdir($curdrv & "\Documents And Settings\" & $cuser & "\Desktop", 0, -1)
                        addfromdir($curdrv & "\Documents And Settings\" & $cuser & "\Favorites", 1, -1)
                        addfromdir($curdrv & "\Documents And Settings\" & $cuser & "\Start Menu", 1, -1)
                    Wend
                EndIf
                FileClose($users)
            EndIf
            addfromdir($curdrv & "\Windows\Desktop", 0, -1)
            addfromdir($curdrv & "\Windows\Favorites", 1, -1)
            addfromdir($curdrv & "\Windows\Start Menu", 1, -1)
        EndIf
    Next
EndIf

WinActivate($winttl)
Send("{HOME}")

while 1
    Sleep(1000)
Wend

func addfromdir($dir, $recurse, $subof)
    if Not FileExists($dir) Then Return
    local $curhdr = UBound($headers)
    ReDim $headers[$curhdr + 1]
    if $subof = -1 Then $subof = $tview
    $headers[$curhdr] = GUICtrlCreateTreeViewItem("{" & $dir & "}", $subof)
;GUICtrlSetState($headers[$curhdr], $GUI_EXPAND)
    local $curfile
    local $cur = FileFindFirstFile($dir & "\*.*")
    if $cur = -1 Then Return
    $subitems = 0
    While 1
        $curfile = FileFindNextFile($cur)
        If @error Then ExitLoop
        local $curdir = $dir & "\" & $curfile
        If $curfile = "." Or $curfile = ".." Then ContinueLoop
        if $recurse Then
            if StringInStr(FileGetAttrib($curdir), "D") Then
                addfromdir($curdir, $recurse, $headers[$curhdr])
                $subitems = 1
                ContinueLoop
            EndIf
        EndIf
        if StringInStr($curfile, ".lnk") Then
            $shrt = FileGetShortcut($curdir)
            $ctrl = GUICtrlCreateTreeViewItem("[" &  $curfile & "] - " & $shrt[0], $headers[$curhdr])
            GUICtrlSetOnEvent(-1, "guicheck")
            $subitems = 1
        EndIf
        if StringInStr($curfile, ".url") Then
            $ctrl = GUICtrlCreateTreeViewItem("[" &  $curfile & "] - " & IniRead($curdir, "InternetShortcut", "URL", "?"), $headers[$curhdr])
            GUICtrlSetOnEvent(-1, "guicheck")
            $subitems = 1
        EndIf
    Wend
    if $subitems = 0 Then
        GuiCtrlDelete($headers[$curhdr])
    Else
    ;GUICtrlSetState($headers[$curhdr], $GUI_EXPAND)
    EndIf
    FileClose($cur)
EndFunc

func guicheck()
    if BitAND(GUIRead(@GUI_CTRLID), $GUI_CHECKED) Then
        MsgBox(0,"",@GUI_CTRLID)
    EndIf
EndFunc

func exitfunc()
    Exit
EndFunc

If you click where a plus box should be, it expands, but this is very confusing to the user. It looks like a bug to me.

Who else would I be?
Link to comment
Share on other sites

Not really a bug, it's a refreshing thing.

We could implement an InvalidateRect-command to the treeviewitem-creation but with your script you would then have a good flicking GUI.

What about changing the line:

GUISetState(@SW_SHOW) to before

WinActivate($winttl) ?

Link to comment
Share on other sites

@holger, I want the progress to be visible as the treeview fills up. Like I said, I already have a workaround, but I know it is going to confuse the noobs. I mentioned it in case something could be done in the future on your side.

Who else would I be?
Link to comment
Share on other sites

@this-is-me: yeah, I know :)

Maybe we could build in after every item-creation an automatically expand and collabs...;)

No - maybe we could add the function to get the rectangle of the new item and then only update this region...

I will test it tomorrow at work cause I have to say, here at home I don't have this problem :)

Regards Holger

Edited by Holger
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...