bladem2003 Posted 4 hours ago Posted 4 hours ago Hey to all, I want to create a context menu on a tab button. On right-click, the tab should activate and a context menu should appear, just like in Scite. In the example below, i have to add a sleep statement to GUIRegisterMsg to wait until the tab is activated in order to determine which tab is active. Is there a better solution for this? #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Global $idTab $hgui = GUICreate("My GUI Tab", 210, 120) ; will create a dialog box that when displayed is centered $idTab = GUICtrlCreateTab(10, 10, 200, 100) GUICtrlCreateTabItem("tab0") GUICtrlCreateTabItem("tab----1") GUICtrlCreateTabItem("tab2") GUICtrlCreateTabItem("") ; end tabitem definition GUISetState(@SW_SHOW) GUIRegisterMsg($WM_CONTEXTMENU, "_WM_CONTEXTMENU") While 1 $idMsg = GUIGetMsg() If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Func _WM_CONTEXTMENU($hwnd, $iMsg, $wParam, $lParam) #forceref $hwnd, $iMsg, $wParam, $lParam If $wParam = GUICtrlGetHandle($idTab) Then MouseClick("left") Sleep(100) ; have to sleep while tab changing <---- this is bad ConsoleWrite("TabActive = " & GUICtrlRead($idTab) & @CRLF) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_CONTEXTMENU
Solution ioa747 Posted 3 hours ago Solution Posted 3 hours ago expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTab.au3> #include <WinAPIMisc.au3> Global $idTab, $hTab $hgui = GUICreate("My GUI Tab", 210, 120) $idTab = GUICtrlCreateTab(10, 10, 200, 100) $hTab = GUICtrlGetHandle($idTab) ; Get the handle once GUICtrlCreateTabItem("tab0") GUICtrlCreateTabItem("tab----1") GUICtrlCreateTabItem("tab2") GUICtrlCreateTabItem("") ; Create context menu $hMenu = GUICtrlCreateContextMenu($idTab) $hMenuItem = GUICtrlCreateMenuItem("Context Menu Item", $hMenu) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_CONTEXTMENU, "_WM_CONTEXTMENU") While 1 $idMsg = GUIGetMsg() If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Func _WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam If $wParam = $hTab Then Local $tPoint = _WinAPI_GetMousePos(True, $hTab) Local $iX = DllStructGetData($tPoint, "X") Local $iY = DllStructGetData($tPoint, "Y") Local $aHit = _GUICtrlTab_HitTest($hTab, $iX, $iY) If $aHit[0] <> -1 Then ;~ _GUICtrlTab_SetCurSel($hTab, $aHit[0]) ConsoleWrite("-> Tab: " & $aHit[0] & @CRLF) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc bladem2003 1 I know that I know nothing
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now