Jump to content

Right click on a tab


jftuga
 Share

Recommended Posts

Is there a way to make GUICtrlCreateTab & GUICtrlCreateTabItem handle right clicking? The functionality that I am looking for would be similar to TrayCreateMenu & TrayCreateItem.

I would like to be able to right-click on a TabItem and then see a dropdown menu that I had created.

Thanks,

-John

Edited by jftuga
Link to comment
Share on other sites

#include <GuiConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.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 Enum $idOpen = 1000, $idSave, $idInfo

Global $hTab

_Main()

Func _Main()
    Local $tab0, $tab0input, $tab0OK, $tab1, $tab1combo, $tab1OK, $tab2, $tab2OK

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

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    $tab0 = GUICtrlCreateTabItem("tab0")
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    $tab0OK = GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    $tab0input = GUICtrlCreateInput("default", 80, 50, 70, 20)

    $tab1 = GUICtrlCreateTabItem("tab----1")
    GUICtrlCreateLabel("label1", 30, 80, 50, 20)
    $tab1combo = GUICtrlCreateCombo("", 20, 50, 60, 120)
    GUICtrlSetData(-1, "Trids|CyberSlug|Jon|Tylo", "Jon"); default Jon
    $tab1OK = GUICtrlCreateButton("OK1", 80, 50, 50, 20)

    $tab2 = GUICtrlCreateTabItem("tab2")
    GUICtrlSetState(-1, $GUI_SHOW); will be display first
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    $tab2OK = GUICtrlCreateButton("OK2", 140, 50, 50)

    GUICtrlCreateTabItem(""); end tabitem definition
    
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Func _Tab_RClick($iIndex, $hWnd)
    _DebugPrint("Right Clicked: " & $iIndex)
    Local $hMenu, $iSelected
    
    Switch $iIndex
        Case 0
            $hMenu = _GUICtrlMenu_CreatePopup()
            _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen)
            _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave)
            _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
            _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $idInfo)
            $iSelected = _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, -1, -1, 1, 1, 2)
            _DebugPrint("$iSelected = " & $iSelected)
            _GUICtrlMenu_DestroyMenu($hMenu)
        Case 1
        Case 2
    EndSwitch
    
EndFunc   ;==>_Tab_RClick

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab
    $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_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)
                    _Tab_RClick(_GUICtrlTab_GetCurSel($hWndFrom), $hWndFrom)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
            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.

 

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...