Sign in to follow this  
Followers 0
d2addict4

How to see if a tab item is clicked?

24 posts in this topic

#1 ·  Posted (edited)

How would I disable the tabitem? I tried GUICtrlSetState($SettingsTab, $GUI_DISABLE) but it doesn't work, I have info that I need on this tab that is readable, but cannot be accessed.

New question, how do I check to see if a tab-item is clicked, bring up an input box, and then if it is a specified password, continue onto the tab, else, return to a tab I specify.

Edited by d2addict4

Share this post


Link to post
Share on other sites



You need to disable the actual controls in the tab, not the tab itself. Set input and edit controls to readonly, and disable all others.

Share this post


Link to post
Share on other sites

How would I disable the tabitem? I tried GUICtrlSetState($SettingsTab, $GUI_DISABLE) but it doesn't work, I have info that I need on this tab that is readable, but cannot be accessed.

I think this might be what you need.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

hmm that didnt really help (martins), but I found a work-around (Disabling the controls), okay new question,

how do I see when a certain tab is clicked? then before it switches to that tab, have a inputbox if they get the password right, allow then to go to the tab (continue to go to it) but if its wrong, then return back to the other tab

Edited by d2addict4

Share this post


Link to post
Share on other sites

"be smart, drink your wine"

Share this post


Link to post
Share on other sites
Could you please re-read the topic. I don't want them to stop looking at it, as you pointed out. I want in my loop, a case statement so I can see when it's clicked.

Share this post


Link to post
Share on other sites

so how do I see if a tab item is clicked?

You can use _GUICtrlTab_HitTest() to see if a tab is clicked or not

Share this post


Link to post
Share on other sites

We can read just fine. What we do is, offering you a more pro-looking solution. The TCN_SELCHANGING notification happens when a tab button is clicked. Don't blame us if you fail to comprehend that, nooblet.

What you want is

;gui...
$yourtab = GUICtrlCreateTab(0,0, 200,100)
;other...

;msgloop:
Switch GuiGetMsg()
    Case $GUI_EVENT_CLOSE
        Exit
    Case $yourtab
        MsgBox(0,'','You clicked tab page #' & GUICtrlRead($yourtab))
EndSwitch

Difference is that TCN_SELCHANGING happens before new page is showed, and you can prevent activation. GUI event triggers after the page is showed.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

We can read just fine. What we do is, offering you a more pro-looking solution. The TCN_SELCHANGING notification happens when a tab button is clicked. Don't blame us if you fail to comprehend that, nooblet.

What you want is

;gui...
$yourtab = GUICtrlCreateTab(0,0, 200,100)
;other...

;msgloop:
Switch GuiGetMsg()
    Case $GUI_EVENT_CLOSE
        Exit
    Case $yourtab
        MsgBox(0,'','You clicked tab page #' & GUICtrlRead($yourtab))
EndSwitch

Difference is that TCN_SELCHANGING happens before new page is showed, and you can prevent activation. GUI event triggers after the page is showed.

Well i do need it to display a inputbox before the tab shows, and if cancel is pressed, or the password is wrong, stay at that tab. else, continue to that tab Edited by d2addict4

Share this post


Link to post
Share on other sites

@siao, I'm impressed.

A response like that deserves emphasis and and 2 x :)

n00blet will part of my vocabulary from here on in.

:(

Share this post


Link to post
Share on other sites

well now that im named as a nooblet, can you guys still help me out? I figured out what exactly that does, and i got it to work, sort of, it will do it on all tab clicks though, hes my code.

please help the nooblet out

#include <GUIConstants.au3>
#Include <GuiTab.au3>
;~ Const $WM_NOTIFY = 0x4E
Opt("GUIOnEventMode", 1)
$Gui = GUICreate("Forced Tab Demo", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "GuiClose")
$TabControl = GUICtrlCreateTab(5, 5, 390, 250)
$TabSheet1 = GUICtrlCreateTabItem("Step #1")
$lbl1 = GUICtrlCreateLabel("Label1", 100, 100)
$TabSheet2 = GUICtrlCreateTabItem("Step #2")
$lbl2 = GUICtrlCreateLabel("Label2", 100, 150)
$TabSheet3 = GUICtrlCreateTabItem("Step #3")
$lbl3 = GUICtrlCreateLabel("Label3", 100, 200)
GUICtrlCreateTabItem("")
$btnBack = GUICtrlCreateButton("&Back", 100, 260, 100, 25)
GUICtrlSetOnEvent(-1, "btnBackClick")
$btnNext = GUICtrlCreateButton("&Next", 200, 260, 100, 25)
GUICtrlSetOnEvent(-1, "btnNextClick")
Global $activeTab = _GUICtrlTab_GetCurSel($TabControl)
GUIRegisterMsg($WM_NOTIFY, "On_WM_NOTIFY")
GUISetState(@SW_SHOW,$Gui)

While 1
    Sleep(100)
WEnd

Func btnBackClick()
    If $activeTab = 0 Then Return
    $activeTab -= 1
    _GUICtrlTab_SetCurFocus($TabControl, $activeTab)
EndFunc
Func btnNextClick()
    If $activeTab = (_GUICtrlTab_GetItemCount($TabControl) - 1) Then Return
    $activeTab += 1
    _GUICtrlTab_SetCurFocus($TabControl, $activeTab)
EndFunc
Func GuiClose()
    Exit
EndFunc
Func On_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    If $wParam = $TabControl Then
        Local $stNMHDR = DllStructCreate("hwnd;uint;int code", $lParam)
        Local $code = DllStructGetData($stNMHDR, "code")
        $stNMHDR = 0
        If $code == $TCN_SELCHANGING And $activeTab = _GUICtrlTab_GetCurFocus($TabControl) Then
        InputBox("Test", "test")
        If @error Then Return True
        EndIf
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Different approach:

#include <GUIConstants.au3>
#Include <GuiTab.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
$Gui = GUICreate("Subclassed Tab Demo", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "GuiClose")
$TabControl = GUICtrlCreateTab(5, 5, 390, 250)
$TabSheet1 = GUICtrlCreateTabItem("Step #1")
$lbl1 = GUICtrlCreateLabel("Label1", 100, 100)
$TabSheet2 = GUICtrlCreateTabItem("Step #2 (with password)")
$lbl2 = GUICtrlCreateLabel("Label2", 100, 150)
$TabSheet3 = GUICtrlCreateTabItem("Step #3")
$lbl3 = GUICtrlCreateLabel("Label3", 100, 200)
GUICtrlCreateTabItem("")
$btnBack = GUICtrlCreateButton("&Back", 100, 260, 100, 25)
GUICtrlSetOnEvent(-1, "btnBackClick")
$btnNext = GUICtrlCreateButton("&Next", 200, 260, 100, 25)
GUICtrlSetOnEvent(-1, "btnNextClick")

;Password related variables:
Global $iPswPage = 0, $sPassword = "password"

;subclass tab control:
Global $wTCProcNew, $wTCProcOld
$wTCProcNew = DllCallbackRegister("_TCMsgProc","uint","hwnd;uint;wparam;lparam")
$wTCProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($TabControl), -4, DllCallbackGetPtr($wTCProcNew))

GUISetState(@SW_SHOW,$Gui)

While 1
    Sleep(100)
WEnd

Func _TCMsgProc($hWnd, $Msg, $wParam, $lParam)
    Switch $Msg
        Case 0x201 ;Const $WM_LBUTTONDOWN = 0x201
            Local $iX = BitAND($lParam, 0xffff), $iY = BitShift($lParam, 16), $aHit = _GUICtrlTab_HitTest($hWnd, $iX, $iY)
            If $aHit[0] = $iPswPage Then
                If InputBox("Password","Enter password") <> $sPassword Then Return 0
            EndIf           
        Case 0x100 ;Const $WM_KEYDOWN = 0x100
            If ($wParam = 0x25 And $iPswPage = GUICtrlRead($TabControl)-1) Or ($wParam = 0x27 And $iPswPage = GUICtrlRead($TabControl)+1) Then
                If InputBox("Password","Enter password") <> $sPassword Then Return 0
            EndIf
    EndSwitch
    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wTCProcOld, $hWnd, $Msg, $wParam, $lParam)
EndFunc
Func GuiClose()
    _WinAPI_SetWindowLong(GUICtrlGetHandle($TabControl), -4, $wTCProcOld)
    DllCallbackFree($wTCProcNew)
    Exit
EndFunc

;not needed anymore, just an example to show that currently this method doesn't protect against _GUICtrlTab_SetCurFocus()
Func btnBackClick()
    Local $iCurr = GUICtrlRead($TabControl), $iMin = 0
    If $iCurr = $iMin Then Return
    _GUICtrlTab_SetCurFocus($TabControl, $iCurr-1)
EndFunc
Func btnNextClick()
    Local $iCurr = GUICtrlRead($TabControl), $iMax = _GUICtrlTab_GetItemCount($TabControl) - 1
    If $iCurr = $iMax Then Return
    _GUICtrlTab_SetCurFocus($TabControl, $iCurr+1)
EndFunc

Edit: sorry, forgot to note that this needs v3.2.11+

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

And this does nothing but crash my computer?

i run this, and it just displays the little loading icon...then wont respond...the GUI shows partly...and it does nothing...?

i found out whats causing this...

this is:

$wTCProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($TabControl), -4, DllCallbackGetPtr($wTCProcNew))
Edited by d2addict4

Share this post


Link to post
Share on other sites

Some of those functions require v3.2.11 betas or v.3.2.12 RC. I forgot to state that, thinking it's easy enough to figure out - Au3Check should give you error if you run it in Scite using older version, such as v3.2.10 prod.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

well i cant use beta for this project.its already completed like 90%.but it does work good.

actually...i got to learn the new includes...and it will work...yay

thanks so much saio your the bomb

Edited by d2addict4

Share this post


Link to post
Share on other sites

okay it works for the second tab item, how to make it work for the first ( like 0 is the first... 1 is the second.. 2 is the third)

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Set $iPswPage variable to whatever tab item index you need. Right now it's $iPswPage = 1, which means second tab item.

Edited by Siao

"be smart, drink your wine"

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