Jump to content

Change popup menu item?


dickep
 Share

Recommended Posts

OK, it is a stretch but I want to have the popup menu item change when you click on it. I have an idea to use it in an application, but need to find out if I can do this.

Here is some code I found and modified to try it.

Let me know why it just keep adding items - I have an inkling, but.... you can help me

#Include <Constants.au3>
#Include <GUIMenu.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

Global Enum $idOpen = 1000, $idSave, $idInfo, $idExit
global $mThis = 1
$hWnd = GUICreate('')
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, 'Open', $idOpen)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, 'Save', $idSave)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, '', 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, 'Info', $idInfo)
_GUICtrlMenu_InsertMenuItem($hMenu, 4, 'Exit', $idExit)
DllCall('user32.dll', 'int', 'SetForegroundWindow', 'hwnd', $hWnd)

while 1
_GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
WEnd
_GUICtrlMenu_DestroyMenu($hMenu)

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch $wParam
        Case $idOpen
            MsgBox(0, '', 'Open')
        Case $idSave
            MsgBox(0, '', 'Save')
            if $mThis then
                _GUICtrlMenu_InsertMenuItem($hMenu, 1, 'Not Saved', $idSave)
                $mThis = not $mThis
            Else
                _GUICtrlMenu_InsertMenuItem($hMenu, 1, 'Saved', $idSave)
                $mThis = not $mThis
            endif
        Case $idInfo
            MsgBox(0, '', 'Info')
        Case $idExit
            Exit
    EndSwitch
EndFunc   ;==>WM_COMMAND
Link to comment
Share on other sites

  • Moderators

dickep,

Try it this way: :mellow:

If $mThis Then
    _GUICtrlMenu_SetItemText($hMenu, 1, 'Not Saved')
    $mThis = Not $mThis
Else
    _GUICtrlMenu_SetItemText($hMenu, 1, 'Saved')
    $mThis = Not $mThis
EndIf

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#Include <Constants.au3>
#Include <GUIMenu.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

Global Enum $idOpen = 1000, $idSave, $idInfo, $idExit
global $mThis = 1
$hWnd = GUICreate('')
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, 'Open', $idOpen)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, 'Save', $idSave)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, '', 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, 'Info', $idInfo)
_GUICtrlMenu_InsertMenuItem($hMenu, 4, 'Exit', $idExit)
DllCall('user32.dll', 'int', 'SetForegroundWindow', 'hwnd', $hWnd)

while 1
_GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
WEnd
_GUICtrlMenu_DestroyMenu($hMenu)

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch $wParam
        Case $idOpen
            MsgBox(0, '', 'Open')
        Case $idSave
            MsgBox(0, '', 'Save')
            if $mThis then
;~                 _GUICtrlMenu_InsertMenuItem($hMenu, 1, 'Not Saved', $idSave)
                _GUICtrlMenu_SetItemText ($hMenu, 1, 'Not Saved')
                $mThis = not $mThis
            Else
;~                 _GUICtrlMenu_InsertMenuItem($hMenu, 1, 'Saved', $idSave)
                _GUICtrlMenu_SetItemText ($hMenu, 1, 'Saved')
                $mThis = not $mThis
            endif
        Case $idInfo
            MsgBox(0, '', 'Info')
        Case $idExit
            Exit
    EndSwitch
EndFunc   ;==>WM_COMMAND

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Again, you come to my aid.

I missed the _GUICtrlMenu_SetItemText item in the help file. I looked but, well, to these old eyes they all look alike.

Thanks again Melba23, it was something "simple" - like me.

E

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