Jump to content

Context menu that functions like a group of radio buttons or checkboxes?


 Share

Recommended Posts

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 by lemony
Link to comment
Share on other sites

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.

#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

Got it!

#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 by lemony
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...