bladem2003 Posted May 3 Posted May 3 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 May 3 Solution Posted May 3 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
Nine Posted May 4 Posted May 4 Another approach : expandcollapse popup; From Nine #include <WindowsConstants.au3> #include <GUIConstants.au3> #include <StructureConstants.au3> #include <GuiTab.au3> Opt("MustDeclareVars", True) Example() Func Example() GUICreate("Example", 210, 120) Local $idTab = GUICtrlCreateTab(10, 10, 200, 100) GUICtrlCreateTabItem("tab0") GUICtrlCreateTabItem("tab----1") GUICtrlCreateTabItem("tab2") GUICtrlCreateTabItem("") ; end tabitem definition GUISetState() GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example Func WM_NOTIFY($hwnd, $iMsg, $wParam, $lParam) Local Static $iTab Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Switch $tNMHDR.Code Case $NM_RCLICK _SendMessage($tNMHDR.hwndFrom, $TCM_SETCURSEL, $iTab) ; something here Case Else $iTab = $wParam EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY bladem2003 and ioa747 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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