Jump to content

context menu freeze loop


jvds
 Share

Recommended Posts

I want to create a context menu that does not freeze the script while the menu is open, is that possible?, here is a modified sample script, when the menu is open the loop is stuck

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    GUICreate("My GUI Context Menu", 300, 200)

    Local $idContextmenu = GUICtrlCreateContextMenu()

    Local $idNewsubmenu = GUICtrlCreateMenu("new", $idContextmenu)
    Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)

    Local $idButton = GUICtrlCreateButton("OK", 100, 100, 70, 20)
    Local $idButtoncontext = GUICtrlCreateContextMenu($idButton)
    Local $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext)

    Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu)
    Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu)
    GUICtrlCreateMenuItem("", $idContextmenu) ; separator

    Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idButton
                MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'OK')
            Case $idMenuAbout
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'About')
            Case $idMenuOpen
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Open')
            Case $idMenuSave
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Save')
            Case $idMenuInfo
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info')
            Case $idNewsubmenuText
                MsgBox($MB_SYSTEMMODAL, "SubMenu Selected", 'Text')
        EndSwitch
        
        sleep(1000)
        ConsoleWrite('test loop'&@CRLF)
            
    WEnd
    GUIDelete()
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Make the context menu modeless. Add these two lines

Local $hCM = GUICtrlGetHandle( $idContextmenu )
_GUICtrlMenu_SetMenuStyle($hCM, BitXOR(_GUICtrlMenu_GetMenuStyle($hCM), $MNS_MODELESS))

immediately after this line

Local $idContextmenu = GUICtrlCreateContextMenu()

You can repeat that for all context menus.

Also add

#include <GuiMenu.au3>

at the top of the script.

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...