Jump to content
Sign in to follow this  
erebus

_GUICtrlTabGetCurSel not working...

Recommended Posts

erebus

Hello,

Here is the sample script I 've written so far:

#include <GUIConstants.au3>
#include <GUITab.au3>

$basedir = @DocumentsCommonDir & "\..\Start Menu\"

GUICreate("title", 900, 600)

$tab = GUICtrlCreateTab(10, 50, 250, 400)

$gen_cat = Inspect($basedir, "*", 2) ; General categories (tabs)
$gen_cat = StringSplit($gen_cat, "|")

Global $tab[$gen_cat[0] + 1], $tab_tv[$gen_cat[0] + 1], $tab_tv_cat[1], $tab_tv_item[1]

For $i = 1 To $gen_cat[0]
    $tab[$i] = GUICtrlCreateTabItem($gen_cat[$i])
    $tab_tv[$i] = GUICtrlCreateTreeView(18, 80, 232, 360, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    $sub_cat = Inspect($basedir & "\" & $gen_cat[$i], "*", 2)
    $sub_cat = StringSplit($sub_cat, "|")
    For $x = 1 To $sub_cat[0]
        ReDim $tab_tv_cat[$sub_cat[0] + 1]
        $tab_tv_cat[$x] = GUICtrlCreateTreeViewItem($sub_cat[$x], $tab_tv[$i])
        $sub_cat_item = Inspect($basedir & "\" & $gen_cat[$i] & "\" & $sub_cat[$x], "*.lnk", 1)
        $sub_cat_item = StringSplit($sub_cat_item, "|")
        For $y = 1 To $sub_cat_item[0]
            ReDim $tab_tv_item[$sub_cat_item[0] + 1]
            $sub_cat_item[$y] = StringTrimRight($sub_cat_item[$y], 4) ; Strip the ".lnk" extension from our treeview
            $tab_tv_item[$y] = GUICtrlCreateTreeViewItem($sub_cat_item[$y], $tab_tv_cat[$x])
        Next
    Next
Next

GUICtrlCreateTabItem("")    ; end tabitem definition

$button = GUICtrlCreateButton("Selected?", 300, 300)

GUISetState()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button
            $cur_tab = _GUICtrlTabGetCurSel($tab)
            msgbox(0,"",$cur_tab)
    EndSwitch
WEnd
    
; ===========>

Func Inspect($sPath, $sFilter = "*", $iFlag = 0)
    Dim $sFileList
    $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch = -1 Then Return SetError(4, 4, "")
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then
            SetError(0)
            ExitLoop
        EndIf
        If $iFlag = 1 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
        If $iFlag = 2 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
        $sFileList = $sFileList & $sFile & "|"
    WEnd
    If StringRight($sFileList, 1) = "|" Then $sFileList = StringTrimRight($sFileList, 1)
    FileClose($hSearch)
    Return $sFileList
EndFunc

The problem is that _GUICtrlTabGetCurSel is always reporting -1 instead of 0 (or more if more tabs have been created). Can anybody tell me what's going wrong?

Also, is there a better way (when having many tabs) to know which is the actual selected TreeViewItem each time (instead of first finding the Tab)?

Thank you all in advance for reading this,

Share this post


Link to post
Share on other sites
GaryFrost

Nothing wrong with the function, pay attention to what you did with the variable $tab

#include <GUIConstants.au3>
#include <GUITab.au3>

$basedir = @DocumentsCommonDir & "\..\Start Menu\"

GUICreate("title", 900, 600)

$tab = GUICtrlCreateTab(10, 50, 250, 400)

$gen_cat = Inspect($basedir, "*", 2) ; General categories (tabs)
$gen_cat = StringSplit($gen_cat, "|")

;~ Global $tab[$gen_cat[0] + 1], $tab_tv[$gen_cat[0] + 1], $tab_tv_cat[1], $tab_tv_item[1] ; what you had
Global $tab_item[$gen_cat[0] + 1], $tab_tv[$gen_cat[0] + 1], $tab_tv_cat[1], $tab_tv_item[1]

For $i = 1 To $gen_cat[0]
;~  $tab[$i] = GUICtrlCreateTabItem($gen_cat[$i]) ; what you had
    $tab_item[$i] = GUICtrlCreateTabItem($gen_cat[$i])
    $tab_tv[$i] = GUICtrlCreateTreeView(18, 80, 232, 360, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    $sub_cat = Inspect($basedir & "\" & $gen_cat[$i], "*", 2)
    $sub_cat = StringSplit($sub_cat, "|")
    For $x = 1 To $sub_cat[0]
        ReDim $tab_tv_cat[$sub_cat[0] + 1]
        $tab_tv_cat[$x] = GUICtrlCreateTreeViewItem($sub_cat[$x], $tab_tv[$i])
        $sub_cat_item = Inspect($basedir & "\" & $gen_cat[$i] & "\" & $sub_cat[$x], "*.lnk", 1)
        $sub_cat_item = StringSplit($sub_cat_item, "|")
        For $y = 1 To $sub_cat_item[0]
            ReDim $tab_tv_item[$sub_cat_item[0] + 1]
            $sub_cat_item[$y] = StringTrimRight($sub_cat_item[$y], 4) ; Strip the ".lnk" extension from our treeview
            $tab_tv_item[$y] = GUICtrlCreateTreeViewItem($sub_cat_item[$y], $tab_tv_cat[$x])
        Next
    Next
    GUICtrlCreateTabItem("") ; end tabitem definition
Next

$button = GUICtrlCreateButton("Selected?", 300, 300)

GUISetState()
MsgBox(0, "", _GUICtrlTabGetCurSel($tab))
; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button
            $cur_tab = _GUICtrlTabGetCurSel($tab)
            MsgBox(0, "", $cur_tab)
    EndSwitch
WEnd

; ===========>

Func Inspect($sPath, $sFilter = "*", $iFlag = 0)
    Dim $sFileList
    $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch = -1 Then Return SetError(4, 4, "")
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then
            SetError(0)
            ExitLoop
        EndIf
        If $iFlag = 1 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
        If $iFlag = 2 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
        $sFileList = $sFileList & $sFile & "|"
    WEnd
    If StringRight($sFileList, 1) = "|" Then $sFileList = StringTrimRight($sFileList, 1)
    FileClose($hSearch)
    Return $sFileList
EndFunc   ;==>Inspect

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
erebus

Oh God...

Thank you very much for pointing that out. Silly me... :)

Share this post


Link to post
Share on other sites
erebus

I have another question...

How can I control a double click on a treeviewitem in this code? (let's say to show a msgbox, but without having to push on the button).

Thank you,

Share this post


Link to post
Share on other sites
erebus

Nobody?

Share this post


Link to post
Share on other sites
Achilles

@GaryFrost: You solution doesn't work for me.

But my concern is that _GUICtrlTabGetCurSel() in the helpfile isn't working either... Any ideas?

EDIT: Upon more research I found that my problem is that I'm using Beta. I tried specifically using the _GuiCtrlTabGetCurSel() from AutoIt 3 (not beta) and it doesn't work because _IsClassName() is not a known function.

In the new version of Beta it seems that it contains many of PaulIA's functions but I have yet to find an example of tabs (using AutoItlib or the newest version of beta) that works (I'm probably doing it wrong).

When I tried changing my current project to use the _GUICtrlTab_Create() and other such function I ended up with all my labels, rads, buttons and whatever else on top of eachother and I don't know why.

Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
GaryFrost

@GaryFrost: You solution doesn't work for me.

But my concern is that _GUICtrlTabGetCurSel() in the helpfile isn't working either... Any ideas?

EDIT: Upon more research I found that my problem is that I'm using Beta. I tried specifically using the _GuiCtrlTabGetCurSel() from AutoIt 3 (not beta) and it doesn't work because _IsClassName() is not a known function.

In the new version of Beta it seems that it contains many of PaulIA's functions but I have yet to find an example of tabs (using AutoItlib or the newest version of beta) that works (I'm probably doing it wrong).

When I tried changing my current project to use the _GUICtrlTab_Create() and other such function I ended up with all my labels, rads, buttons and whatever else on top of eachother and I don't know why.

#include <GUIConstants.au3>
#include <GUITab.au3>

;~ $basedir = @DocumentsCommonDir & "\..\Start Menu\"
$basedir = "c:\"

GUICreate("title", 900, 600)

$tab = GUICtrlCreateTab(10, 50, 250, 400)

$gen_cat = Inspect($basedir, "*", 2) ; General categories (tabs)
$gen_cat = StringSplit($gen_cat, "|")

;~ Global $tab[$gen_cat[0] + 1], $tab_tv[$gen_cat[0] + 1], $tab_tv_cat[1], $tab_tv_item[1] ; what you had
Global $tab_item[$gen_cat[0] + 1], $tab_tv[$gen_cat[0] + 1], $tab_tv_cat[1], $tab_tv_item[1]

For $i = 1 To $gen_cat[0]
;~  $tab[$i] = GUICtrlCreateTabItem($gen_cat[$i]) ; what you had
    $tab_item[$i] = GUICtrlCreateTabItem($gen_cat[$i])
    $tab_tv[$i] = GUICtrlCreateTreeView(18, 80, 232, 360, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    $sub_cat = Inspect($basedir & "\" & $gen_cat[$i], "*", 2)
    $sub_cat = StringSplit($sub_cat, "|")
    For $x = 1 To $sub_cat[0]
        ReDim $tab_tv_cat[$sub_cat[0] + 1]
        $tab_tv_cat[$x] = GUICtrlCreateTreeViewItem($sub_cat[$x], $tab_tv[$i])
        $sub_cat_item = Inspect($basedir & "\" & $gen_cat[$i] & "\" & $sub_cat[$x], "*.lnk", 1)
        $sub_cat_item = StringSplit($sub_cat_item, "|")
        For $y = 1 To $sub_cat_item[0]
            ReDim $tab_tv_item[$sub_cat_item[0] + 1]
            $sub_cat_item[$y] = StringTrimRight($sub_cat_item[$y], 4) ; Strip the ".lnk" extension from our treeview
            $tab_tv_item[$y] = GUICtrlCreateTreeViewItem($sub_cat_item[$y], $tab_tv_cat[$x])
        Next
    Next
    GUICtrlCreateTabItem("") ; end tabitem definition
Next

$button = GUICtrlCreateButton("Selected?", 300, 300)

GUISetState()
MsgBox(0, "", _GUICtrlTab_GetCurSel($tab))
; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button
            $cur_tab = _GUICtrlTab_GetCurSel($tab)
            MsgBox(0, "", $cur_tab)
    EndSwitch
WEnd

; ===========>

Func Inspect($sPath, $sFilter = "*", $iFlag = 0)
    Dim $sFileList
    $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch = -1 Then Return SetError(4, 4, "")
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then
            SetError(0)
            ExitLoop
        EndIf
        If $iFlag = 1 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
        If $iFlag = 2 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
        $sFileList = $sFileList & $sFile & "|"
    WEnd
    If StringRight($sFileList, 1) = "|" Then $sFileList = StringTrimRight($sFileList, 1)
    FileClose($hSearch)
    Return $sFileList
EndFunc   ;==>Inspect

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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  

×