SEKOMD Posted July 9 Share Posted July 9 Could you please advise, I am creating a window that will serve as a menu. If you right-click on an item, a sub-menu will appear. Everything is fine, I understand how to do this. But I can't grasp the principle if multiple sub-menus are needed, for example: Item 1 > Menu_Item1 > Menu_MenuItem2 Of course, you can pre-create all possible variations... but how can you do this when you don't know how many sub-menus there will be? expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <WinAPI.au3> #include <StaticConstants.au3> Global $hGUI = GUICreate('MENU') Opt("GUIOnEventMode", 1) $LABEL1 = GUICtrlCreateLabel('Item #1', 0, 0, 200, 40) GUICtrlSetFont($LABEL1, 14, 400, Default, 'Tahoma') $LABEL2 = GUICtrlCreateLabel('Item #2', 0, 40, 200, 40) GUICtrlSetFont($LABEL2, 14, 400, Default, 'Tahoma') $LABEL3 = GUICtrlCreateLabel('Item #3', 0, 80, 200, 40) GUICtrlSetFont($LABEL3, 14, 400, Default, 'Tahoma') $LABEL4 = GUICtrlCreateLabel('Item #4', 0, 120, 200, 40) GUICtrlSetFont($LABEL4, 14, 400, Default, 'Tahoma') Global $_MouseClickRight = 0 GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_MouseClickRight") Func _MouseClickRight() $_MouseClickRight = 1 EndFunc ;==>_MouseClickRight ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) While Sleep(100) If $_MouseClickRight Then $_MouseClickRight = 0 ;MsgBox(64, '', 'RIGHT CLICK' & @CRLF & GUIGetCursorInfo($hGUI)[4]) ;create child menu $a = GUIGetCursorInfo($hGUI)[0] + WinGetPos($hGUI)[0] $b = GUIGetCursorInfo($hGUI)[1] + WinGetPos($hGUI)[1] $hGUI2 = GUICreate('MENU', Default, Default,$a,$b) $LABEL11 = GUICtrlCreateLabel('Item #11', 0, 0, 200, 40) GUICtrlSetFont($LABEL1, 14, 400, Default, 'Tahoma') $LABEL22 = GUICtrlCreateLabel('Item #22', 0, 40, 200, 40) GUICtrlSetFont($LABEL2, 14, 400, Default, 'Tahoma') $LABEL33 = GUICtrlCreateLabel('Item #33', 0, 80, 200, 40) GUICtrlSetFont($LABEL3, 14, 400, Default, 'Tahoma') $LABEL44 = GUICtrlCreateLabel('Item #44', 0, 120, 200, 40) GUICtrlSetFont($LABEL4, 14, 400, Default, 'Tahoma') GUISetState(@SW_SHOW, $hGUI2) EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Link to comment Share on other sites More sharing options...
SEKOMD Posted July 9 Author Share Posted July 9 Here's a bit of progress, but it's unclear how to make the menu appear where the mouse is positioned... expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <WinAPI.au3> #include <StaticConstants.au3> Opt("GUIOnEventMode", 1) Global $_MouseClickRight = 0 Global $hGUI ___MENU_TEST() Func ___MENU_TEST() If WinExists($hGUI) And $hGUI Then $a = GUIGetCursorInfo($hGUI)[0] + WinGetPos($hGUI)[0] $b = GUIGetCursorInfo($hGUI)[1] + WinGetPos($hGUI)[1] Else $a = WinGetPos($hGUI)[0] $b = WinGetPos($hGUI)[1] EndIf Local $hGUI = GUICreate('MENU', Default, Default, $a, $b) Local $LABEL1 = GUICtrlCreateLabel('Item #1', 0, 0, 200, 40) GUICtrlSetFont($LABEL1, 14, 400, Default, 'Tahoma') Local $LABEL2 = GUICtrlCreateLabel('Item #2', 0, 40, 200, 40) GUICtrlSetFont($LABEL2, 14, 400, Default, 'Tahoma') Local $LABEL3 = GUICtrlCreateLabel('Item #3', 0, 80, 200, 40) GUICtrlSetFont($LABEL3, 14, 400, Default, 'Tahoma') GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_MouseClickRight") GUISetState(@SW_SHOW, $hGUI) While Sleep(50) If $_MouseClickRight Then $_MouseClickRight = 0 ;MsgBox(64, '', 'RIGHT CLICK' & @CRLF & GUIGetCursorInfo($hGUI)[4]) ___MENU_TEST() ;create child menu ;$a = GUIGetCursorInfo($hGUI)[0] + WinGetPos($hGUI)[0] ;$b = GUIGetCursorInfo($hGUI)[1] + WinGetPos($hGUI)[1] ;$hGUI2 = GUICreate('MENU', Default, Default, $a, $b) EndIf WEnd EndFunc ;==>___MENU_TEST Func _MouseClickRight() $_MouseClickRight = 1 EndFunc ;==>_MouseClickRight Link to comment Share on other sites More sharing options...
Andreik Posted July 9 Share Posted July 9 (edited) Try this: expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <WinAPI.au3> #include <StaticConstants.au3> Opt("GUIOnEventMode", 1) Global $_MouseClickRight = 0 Global $hGUI ___MENU_TEST() Func ___MENU_TEST($iX = 0, $iY = 0) If WinExists($hGUI) And $hGUI Then $a = GUIGetCursorInfo($hGUI)[0] + WinGetPos($hGUI)[0] $b = GUIGetCursorInfo($hGUI)[1] + WinGetPos($hGUI)[1] Else $a = WinGetPos($hGUI)[0] $b = WinGetPos($hGUI)[1] EndIf If $iX Then $a = $iX If $iY Then $b = $iY Local $hGUI = GUICreate('MENU', Default, Default, $a, $b) Local $LABEL1 = GUICtrlCreateLabel('Item #1', 0, 0, 200, 40) GUICtrlSetFont($LABEL1, 14, 400, Default, 'Tahoma') Local $LABEL2 = GUICtrlCreateLabel('Item #2', 0, 40, 200, 40) GUICtrlSetFont($LABEL2, 14, 400, Default, 'Tahoma') Local $LABEL3 = GUICtrlCreateLabel('Item #3', 0, 80, 200, 40) GUICtrlSetFont($LABEL3, 14, 400, Default, 'Tahoma') GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_MouseClickRight") GUISetState(@SW_SHOW, $hGUI) While Sleep(50) If $_MouseClickRight Then $_MouseClickRight = 0 ;MsgBox(64, '', 'RIGHT CLICK' & @CRLF & GUIGetCursorInfo($hGUI)[4]) ___MENU_TEST(MouseGetPos(0), MouseGetPos(1)) ;create child menu ;$a = GUIGetCursorInfo($hGUI)[0] + WinGetPos($hGUI)[0] ;$b = GUIGetCursorInfo($hGUI)[1] + WinGetPos($hGUI)[1] ;$hGUI2 = GUICreate('MENU', Default, Default, $a, $b) EndIf WEnd EndFunc ;==>___MENU_TEST Func _MouseClickRight() $_MouseClickRight = 1 EndFunc ;==>_MouseClickRight Or if you don't necessarily need events mode on then you can try this: #include <GUIConstantsEx.au3> Global $aMsg, $iWinCount = 0 ___MENU_TEST() While True $aMsg = GUIGetMsg(1) Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUIDelete($aMsg[1]) $iWinCount -= 1 If $iWinCount = 0 Then Exit Case $GUI_EVENT_SECONDARYDOWN ___MENU_TEST(MouseGetPos(0), MouseGetPos(1)) EndSwitch WEnd Func ___MENU_TEST($iX = -1, $iY = -1) Local $hGUI = GUICreate('MENU', Default, Default, $iX, $iY) Local $LABEL1 = GUICtrlCreateLabel('Item #1', 0, 0, 200, 40) GUICtrlSetFont($LABEL1, 14, 400, Default, 'Tahoma') Local $LABEL2 = GUICtrlCreateLabel('Item #2', 0, 40, 200, 40) GUICtrlSetFont($LABEL2, 14, 400, Default, 'Tahoma') Local $LABEL3 = GUICtrlCreateLabel('Item #3', 0, 80, 200, 40) GUICtrlSetFont($LABEL3, 14, 400, Default, 'Tahoma') GUISetState(@SW_SHOW, $hGUI) $iWinCount += 1 Return $hGUI EndFunc Edited July 9 by Andreik SEKOMD 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
SEKOMD Posted July 9 Author Share Posted July 9 Andreik, Thank you so much!!!! Link to comment Share on other sites More sharing options...
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