Sign in to follow this  
Followers 0
Gozzgug

Tabbed Items

8 posts in this topic

I have gui with numerous tabs. I would like to do a validation check on the currently selected tab when you click to exit to the next tab. Are there any events to handle this?

Sorry for the double post. I posted this originally in the general help area and I think it needs to be here.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

I don't know if there has been a solution to this that I missed somewhere, but if not can someone think of a solution to it now?

EDIT: Using GuiRegisterMsg() with $WM_NOTIFY does something but I haven't figured how to make it recognize the tab click.

EDIT2: I've already looked through what AutoItLib has to offer but it doesn't seem to have what I'm looking for, unless I missed it.

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

Pay attention to $TCN_SELCHANGING

#include <GuiConstants.au3>
#include <GuiTab.au3>

Opt('MustDeclareVars', 1)

$Debug_TAB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTab

_Main()

Func _Main()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("Tab Control Create", 400, 300)
    $hTab = _GUICtrlTab_Create ($hGUI, 2, 2, 396, 296)
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Add tabs
    _GUICtrlTab_InsertItem ($hTab, 0, "Tab 1")
    _GUICtrlTab_InsertItem ($hTab, 1, "Tab 2")
    _GUICtrlTab_InsertItem ($hTab, 2, "Tab 3")
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $fValid
    $hWndTab = $hTab
    If Not IsHWnd($hTab) Then $hWndTab = GUICtrlGetHandle($hTab)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $NM_CLICK  ; The user has clicked the left mouse button within the control
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom: " & @TAB & $iIDFrom & @LF & _
                            "-->Code: " & @TAB & $iCode)
                    ; The return value is ignored by the tab control
                Case $NM_DBLCLK  ; The user has double-clicked the left mouse button within the control
                    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK  ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK  ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RELEASEDCAPTURE ; control is releasing mouse capture
                    _DebugPrint("$NM_RELEASEDCAPTURE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $TCN_SELCHANGING
                    _DebugPrint("$TCN_SELCHANGING" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Item: " & @TAB & _GUICtrlTab_GetCurSel($hTab))
                    ; could do validation here and determine return
                    $fValid = False
                    If Not $fValid Then
                        Return True ; prevent the selection from changing
                    Else
                        Return False ; FALSE to allow the selection to change
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

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

.....

EDIT2: I've already looked through what AutoItLib has to offer but it doesn't seem to have what I'm looking for, unless I missed it.

If your looking to find out if a tab has been hit on then you missed it...

Maybe look in the A3LTabControl.au3 then look at _Tab_HitTest($hWnd, $iX, iY)

use tab hittest to find the tab you've hit on.

Works pretty sweet for many things as it reports what's been hit, eg: the tab index and or on the tab text and or on tab icon.

Not sure exactly what your after but a crude example of what I mean, but you could do it a lot better to suite your needs maybe.. here

Cheers

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If your looking to find out if a tab has been hit on then you missed it...

Maybe look in the A3LTabControl.au3 then look at _Tab_HitTest($hWnd, $iX, iY)

use tab hittest to find the tab you've hit on.

Works pretty sweet for many things as it reports what's been hit, eg: the tab index and or on the tab text and or on tab icon.

Not sure exactly what your after but a crude example of what I mean, but you could do it a lot better to suite your needs maybe.. here

Cheers

No need to go through all that as I pointed out $TCN_SELCHANGING you can either allow the tab selection to change or not, put validation code there to make the decision.

Not much missing from the Beta help in the tab department that is in the A3L libraries, most have been combined with the libraries that were already there.

Edit: Must be getting tired, _GUICtrlTab_HitTest is in the help

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

I really should move onto that beta.. <_<

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