Sign in to follow this  
Followers 0
bubke

How to disable a tab-item

13 posts in this topic

Hello, I can't figure out how to disable a tab-item. I know it can be do with GUICtrlSetState, but I can't find the control-id for the tabitem, only for the tab control.

Hope anyone can help me.

Grtz, bubke

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I don't think you can. I just tried to do it myself the way I assumed it would work, and no go. Here's the code I used:

#include <GUIConstants.au3>
$gui = GUICreate('', 200, 200)
$tabCtrl = GUICtrlCreateTab(0, 0, 200, 200)
$tabItem1 = GUICtrlCreateTabItem('One')
$tabItem2 = GUICtrlCreateTabItem('Two')
$tabItem3 = GUICtrlCreateTabItem('Three')
GUICtrlCreateTabItem('')
GUISetState()

GUICtrlSetState($tabItem2, $GUI_DISABLE)

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

Like I said though, it doesn't work.

I also looked at the extra GUI tab functions and found no reference to being able to disable a tab.

By the way, as my example demonstrates, GUICtrlCreateTabItem will return the tab ID.

Edit: Correction, I shouldn't have said that you can't, because you most likely can using advanced events and such, but I don't think there's a simple way to just disable a tab item the way you would an input or button control.

Edited by Saunders

Share this post


Link to post
Share on other sites

Hello,

Thanks for your reply. Yes, I think too that's it impossible. The problem is that the ID of the tab is returned. Maybe it's possible in the next version of AutiIt.

Share this post


Link to post
Share on other sites

Hello,

Thanks for your reply. Yes, I think too that's it impossible. The problem is that the ID of the tab is returned. Maybe it's possible in the next version of AutiIt.

You can't disable a TabItem but with some heavy coding you might be able to simulate a disabled state. It will not appear as greyed-out though.

First you have to know that TabItems are 0 index based so the index for $tabItem2 would be 1

Now you can play with

If GUICtrlRead($tabCtrl) = 1 Then

At that point it's going to be a matter of figuring out how to force some action that will prevent the user from actually accessing the controls on that tab.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

GEOSoft, thanks for your tip! You are right that tabitems are indexed. I will try it.

Share this post


Link to post
Share on other sites
Thanks Gary. You were bound to have the answer for this one.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

... a more simple solution for that could be something like .....

Best regards, Reinhard

; Example of TAB Disable
#include <GUIConstants.au3>
#include <GuiTab.au3>

Global $main_GUI,$ok_button,$cancel_button

; This window has 2 ok/cancel-buttons
$main_GUI  = GUICreate("TAB in TAB",260,250,-1,-1)
    
    $ok_button      = GUICtrlCreateButton("OK",40,220,70,20)
    $cancel_button  = GUICtrlCreateButton("Cancel",150,220,70,20)

; Create the first child window that is implemented into the main GUI
$child1    = GUICreate("",230,170,15,35,BitOr($WS_CHILD,$WS_TABSTOP),-1,$main_GUI)
                $disTab2 = GUICtrlCreateCheckbox ("Disable Child2", 10, 10, 120, 20)
GUISetState()

; Create the second child window that is implemented into the main GUI
$child2    = GUICreate("",230,170,15,35,BitOr($WS_CHILD,$WS_TABSTOP),-1,$main_GUI)
    $listview2      = GUICtrlCreateListView("Col1|Col2",10,10,210,150,-1,$WS_EX_CLIENTEDGE)
    GUICtrlCreateListViewItem("ItemLong1|ItemLong12", $listview2)
    GUICtrlCreateListViewItem("ItemLong2|Item22", $listview2)

; Create the third child window that is implemented into the main GUI
$child3    = GUICreate("",230,170,15,35,BitOr($WS_CHILD,$WS_TABSTOP),-1,$main_GUI)
                GuiCtrlcreatelabel("Tab3",50,60,80,80)

; Switch back the main GUI and create the tabs
GUISwitch($main_GUI)
$main_tab       = GUICtrlCreateTab(10,10,240,200)
$child1tab      = GUICtrlCreateTabItem("Child1")
$child2tab      = GUICtrlCreateTabItem("Child2")
$child3tab      = GUICtrlCreateTabItem("Child3")
GUICtrlCreateTabItem("")

DIM $tabItemLast = 0

GUISetState()

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $GUI_EVENT_CLOSE, $cancel_button
            ExitLoop
            
        Case $main_tab
            $tabItem = GUICtrlRead($main_Tab)
            $Disabled=GUICtrlRead($DisTab2)
            if $tabItem = 1 and $disabled = $GUI_CHECKED Then
                _GUICtrlTabSetCurSel($main_tab,$tabitemLast)
                MsgBox(0,"","Tab2 is disabled")
                else
                if $tabItem <> $tabItemLast then TabSwitch($tabItem)
            endif
    EndSwitch
WEnd

func TabSwitch($tabItem)
    
    GUISetState(@SW_HIDE,$child1)
    GUISetState(@SW_HIDE,$child2)
    GUISetState(@SW_HIDE,$child3)      
    if $tabItem = 0 then GUISetState(@SW_SHOW,$child1)
    if $tabItem = 1 then GUISetState(@SW_SHOW,$child2)
    if $tabItem = 2 then GUISetState(@SW_SHOW,$child3)
   $tabItemLast = $tabItem
EndFunc
Edited by ReFran

Share this post


Link to post
Share on other sites

Hi! You tested your code before posting? I get error Unknown function name.: _GUICtrlTabSetCurSel($main_tab,$tabitemLast)

Share this post


Link to post
Share on other sites

Hi! You tested your code before posting? I get error Unknown function name.: _GUICtrlTabSetCurSel($main_tab,$tabitemLast)

Still using old version


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

#11 ·  Posted (edited)

Still using old version

Still waiting on an update script, where I can throw my old one on and get back the "new" one.

I thought Zedna would finaly do it, but isn't it also in US that at eastern a small animal fulfill some wishes?

best regards, Reinhard

PS: Replace _GUICtrlTabSetCurSel with _GUICtrl_TabSetCurSel if you work already with a newer version.

Edited by ReFran

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Still waiting on an update script, where I can throw my old one on and get back the "new" one.

Isn't it also in US that at eastern a small animal fulfill some wishes?

best regards, Reinhard

PS: Replace _GUICtrlTabSetCurSel with _GUICtrl_TabSetCurSel if you work already with a newer version.

Write one.

Then you won't have to wait.

Kiss a toad and find out.

Guessing your talking about the easter bunny. Good luck with that one

Edited by GaryFrost

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

Thanks GaryFrost for your solution! It'works like a charm!

Grtz

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