lemony Posted May 14, 2008 Share Posted May 14, 2008 (edited) Hey guys,Sometimes I see programs that have context menus that work like a group of radio buttons or checkboxes.I wonder... is this possible with AutoIt?edit: It's possible! GUICtrlCreateMenuItem... Today is just not my day... don't mind me Edited May 14, 2008 by lemony Link to comment Share on other sites More sharing options...
Malkey Posted May 14, 2008 Share Posted May 14, 2008 Hey guys, Sometimes I see programs that have context menus that work like a group of radio buttons or checkboxes. I wonder... is this possible with AutoIt? edit: It's possible! GUICtrlCreateMenuItem... Today is just not my day... don't mind me I did this little example before your edit and could not work out how to put radio buttons in a context menu. If anyone has any ideas if it can be done and how it can be done, I would be interested to know. expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Local $hGui, $ContextMenu, $menu1,$menu2,$subMenu1,$separator1,$MenuItemExit $hGui = GUICreate("GDI1",200, 200, -1,-1) $ContextMenu = GUICtrlCreateContextMenu() $menu1 = GUICtrlCreateMenuItem("Toggle on/off", $ContextMenu) GUICtrlSetState($menu1, $GUI_UNCHECKED) GUICtrlSetOnEvent($menu1, "menu1Func") $menu2 = GUICtrlCreateMenu("To Submenu", $ContextMenu) $subMenu1 = GUICtrlCreateMenuItem("Submenu1)", $menu2) GUICtrlSetOnEvent($subMenu1, "Submenu1Func") $separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line $MenuItemExit = GUICtrlCreateMenuItem("Exit", $ContextMenu) GUICtrlSetOnEvent($MenuItemExit, "Quit") GUISetState() While 1 sleep(10) Wend Func menu1func() If BitAND(GUICtrlRead($menu1), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($menu1, $GUI_UNCHECKED) ;Extra Commands here, if needed.... Else GUICtrlSetState($menu1, $GUI_CHECKED) GUISetState(@SW_SHOW, $hGui) ;Extra Commands here, if needed.... EndIf Return 1 EndFunc ;==>ShowaOrig Func Submenu1Func() MsgBox(0,"","Submenu function here") EndFunc Func Quit() Local $e $e = MsgBox(1, "Exit", "Press OK to Exit") If $e = 1 Then Exit Return 1 EndFunc ;==>Quit Link to comment Share on other sites More sharing options...
lemony Posted May 15, 2008 Author Share Posted May 15, 2008 Hey Malkey, Radio buttons, I don't know. But I was able to figure out the checkbox way just like you did. Link to comment Share on other sites More sharing options...
lemony Posted May 15, 2008 Author Share Posted May 15, 2008 (edited) Got it! expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Local $hGui, $ContextMenu, $menu1,$menu2,$subMenu1,$separator1,$MenuItemExit $hGui = GUICreate("GDI1",200, 200, -1,-1) $ContextMenu = GUICtrlCreateContextMenu() $menu1 = GUICtrlCreateMenuItem("Toggle on/off", $ContextMenu) GUICtrlSetState($menu1, $GUI_UNCHECKED) GUICtrlSetOnEvent($menu1, "menu1Func") $menu2 = GUICtrlCreateMenu("To Submenu", $ContextMenu) $subMenu1 = GUICtrlCreateMenuItem("Submenu1)", $menu2) GUICtrlSetOnEvent($subMenu1, "Submenu1Func") $separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line $radiotest = GUICtrlCreateMenu("Radio Test", $ContextMenu) $radio1 = GUICtrlCreateMenuItem("Radio Option1", $radiotest, -1, 1) GUICtrlSetState(-1, $GUI_CHECKED) $radio2 = GUICtrlCreateMenuItem("Radio Option2", $radiotest, -1, 1) $radio3 = GUICtrlCreateMenuItem("Radio Option3", $radiotest, -1, 1) $radio4 = GUICtrlCreateMenuItem("Radio Option4", $radiotest, -1, 1) GUICtrlCreateMenuItem("", $radiotest) $radioa = GUICtrlCreateMenuItem("Radio OptionA", $radiotest, -1, 1) $radiob = GUICtrlCreateMenuItem("Radio OptionB", $radiotest, -1, 1) GUICtrlSetState(-1, $GUI_CHECKED) $radioc = GUICtrlCreateMenuItem("Radio OptionC", $radiotest, -1, 1) GUICtrlCreateMenuItem("", $ContextMenu) $MenuItemExit = GUICtrlCreateMenuItem("Exit", $ContextMenu) GUICtrlSetOnEvent($MenuItemExit, "Quit") GUISetState() While 1 sleep(10) Wend Func menu1func() If BitAND(GUICtrlRead($menu1), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($menu1, $GUI_UNCHECKED) ;Extra Commands here, if needed.... Else GUICtrlSetState($menu1, $GUI_CHECKED) GUISetState(@SW_SHOW, $hGui) ;Extra Commands here, if needed.... EndIf Return 1 EndFunc ;==>ShowaOrig Func Submenu1Func() MsgBox(0,"","Submenu function here") EndFunc Func Quit() Local $e $e = MsgBox(1, "Exit", "Press OK to Exit") If $e = 1 Then Exit Return 1 EndFunc ;==>Quit Edited May 15, 2008 by lemony pixelsearch 1 Link to comment Share on other sites More sharing options...
Malkey Posted May 15, 2008 Share Posted May 15, 2008 Radio buttons in context menu - amazingly easy, now that I know. The last optional parameter in the GUICtrlCreateMenuItem function. Thanks for the heads up. 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