Jump to content

Submenu


legend
 Share

Recommended Posts

#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Enum $idOpen = 1000, $idSave, $idInfo

Global $GUI, $listview, $hMenu

_Main()

Func _Main()
    ; Create GUI
    $GUI = GUICreate("Menu", 400, 300)

    $listview = GUICtrlCreateListView("test1|test2|test3|test4", 5, 5, 390, 290)
    GUICtrlCreateListViewItem("item1|item2|item3|item4", $listview)
    GUICtrlCreateListViewItem("test1|test2|test3|test4", $listview)

    $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)


    ; Register message handlers
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    GUISetState()

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom, $iCode, $tNMHDR, $tInfo

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $listview
            Switch $iCode
                Case $NM_CLICK, $NM_RCLICK
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)

                    If DllStructGetData($tInfo, "Item") > -1 Then
                        _GUICtrlMenu_TrackPopupMenu($hMenu, $GUI)
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $idOpen
            _WinAPI_ShowMsg("Open")
        Case $idSave
            _WinAPI_ShowMsg("Save")
        Case $idInfo
            _WinAPI_ShowMsg("Info")
    EndSwitch
EndFunc   ;==>WM_COMMAND

How can i make a submenu under one of the menu points when right clicking?

Link to comment
Share on other sites

#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Enum $idOpen = 1000, $idSave, $idInfo, $idSub1, $idSub2

Global $GUI, $listview, $hMenu

_Main()

Func _Main()
    ; Create GUI
    $GUI = GUICreate("Menu", 400, 300)

    $listview = GUICtrlCreateListView("test1|test2|test3|test4", 5, 5, 390, 290)
    GUICtrlCreateListViewItem("item1|item2|item3|item4", $listview)
    GUICtrlCreateListViewItem("test1|test2|test3|test4", $listview)

    ; ----- Create subitem menu -----
    $hSubItems1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hSubItems1, 0, "SubItem &1", $idSub1)
    _GUICtrlMenu_InsertMenuItem($hSubItems1, 1, "SubItem &2", $idSub2)
    ; -------------------------------

    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave)
    _GUICtrlMenu_InsertMenuItem($hMenu, 2, "Info", $idInfo)
    _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem($hMenu, 4, "More", 0, $hSubItems1) ; <---- append subitems here


    ; Register message handlers
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    GUISetState()

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom, $iCode, $tNMHDR, $tInfo

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $listview
            Switch $iCode
                Case $NM_CLICK, $NM_RCLICK
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)

                    If DllStructGetData($tInfo, "Item") > -1 Then
                        _GUICtrlMenu_TrackPopupMenu($hMenu, $GUI)
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $idOpen
            _WinAPI_ShowMsg("Open")
        Case $idSave
            _WinAPI_ShowMsg("Save")
        Case $idInfo
            _WinAPI_ShowMsg("Info")
; ---- submeenus ----
        Case $idSub1
            _WinAPI_ShowMsg("submenu1")
        Case $idSub2
            _WinAPI_ShowMsg("submenu2")
    EndSwitch
EndFunc   ;==>WM_COMMAND

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

10 hours ago, Gianni said:
#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Enum $idOpen = 1000, $idSave, $idInfo, $idSub1, $idSub2

Global $GUI, $listview, $hMenu

_Main()

Func _Main()
    ; Create GUI
    $GUI = GUICreate("Menu", 400, 300)

    $listview = GUICtrlCreateListView("test1|test2|test3|test4", 5, 5, 390, 290)
    GUICtrlCreateListViewItem("item1|item2|item3|item4", $listview)
    GUICtrlCreateListViewItem("test1|test2|test3|test4", $listview)

    ; ----- Create subitem menu -----
    $hSubItems1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hSubItems1, 0, "SubItem &1", $idSub1)
    _GUICtrlMenu_InsertMenuItem($hSubItems1, 1, "SubItem &2", $idSub2)
    ; -------------------------------

    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave)
    _GUICtrlMenu_InsertMenuItem($hMenu, 2, "Info", $idInfo)
    _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem($hMenu, 4, "More", 0, $hSubItems1) ; <---- append subitems here


    ; Register message handlers
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    GUISetState()

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom, $iCode, $tNMHDR, $tInfo

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $listview
            Switch $iCode
                Case $NM_CLICK, $NM_RCLICK
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)

                    If DllStructGetData($tInfo, "Item") > -1 Then
                        _GUICtrlMenu_TrackPopupMenu($hMenu, $GUI)
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $idOpen
            _WinAPI_ShowMsg("Open")
        Case $idSave
            _WinAPI_ShowMsg("Save")
        Case $idInfo
            _WinAPI_ShowMsg("Info")
; ---- submeenus ----
        Case $idSub1
            _WinAPI_ShowMsg("submenu1")
        Case $idSub2
            _WinAPI_ShowMsg("submenu2")
    EndSwitch
EndFunc   ;==>WM_COMMAND

 

it's working great, how would I get the name of the selected item in the listview, when i right click, and selects one of the menus?

 

Link to comment
Share on other sites

8 hours ago, legend said:

How would I get the name of the selected item in the listview...

You can get it directly during the WM_NOTIFY() function, by adding a line to the code :

If DllStructGetData($tInfo, "Item") > -1 Then
    ConsoleWrite($tInfo.Item & "   " & $tInfo.SubItem & "   " & _
        _GUICtrlListView_GetItemText($listview, $tInfo.Item, $tInfo.SubItem) & @crlf)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $GUI)
EndIf

 

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