AlienStar Posted November 23, 2020 Share Posted November 23, 2020 2 hours ago, Nine said: I think I understand what you mean (not exactly sure). But anyway here a stronger approach I would use : expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> _Main() Func _Main() Local $array[8] = ["Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri"] $hGUI = GUICreate("", 500, 300) $listview = GUICtrlCreateListView("categories", 20, 20, 460, 180) $mMenu = GUICtrlCreateContextMenu($listview) Local $aMenuId[UBound($array)] For $i = 0 To UBound($array) - 1 $aMenuId[$i] = GUICtrlCreateMenuItem($array[$i], $mMenu) Next $idButton = GUICtrlCreateButton("OK", 200, 220, 100, 25) Local $idTemp = GUICtrlCreateMenuItem("end", $mMenu) _ArrayAdd($array, "end") _ArrayAdd($aMenuId, $idTemp) GUISetState(@SW_SHOW) While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_NONE ; not truly required but it will prevent triggering Case Else for nothing Case $GUI_EVENT_CLOSE Exit Case $idButton ConsoleWrite ("Button was pressed" & @CRLF) Case Else For $i = 0 To UBound($aMenuId) - 1 If $iMsg = $aMenuId[$i] Then MsgBox(0, "Menu Selection", $array[$i]) Next EndSwitch WEnd EndFunc ;==>_Main amazing thanks so much my friend now I tried to delete an item but it still shown in the menu _ArrayDelete($aMenuId,1) _ArrayDelete($array,1) Link to comment Share on other sites More sharing options...
Nine Posted November 23, 2020 Share Posted November 23, 2020 You also need to GUICtrlDelete the control... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AlienStar Posted November 23, 2020 Share Posted November 23, 2020 2 hours ago, Nine said: You also need to GUICtrlDelete the control... would you please explain more to delete a menu item ? Link to comment Share on other sites More sharing options...
Nine Posted November 23, 2020 Share Posted November 23, 2020 Button deletes 4th menu item altogether : expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> _Main() Func _Main() Local $array[8] = ["Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri"] $hGUI = GUICreate("", 500, 300) $listview = GUICtrlCreateListView("categories", 20, 20, 460, 180) $mMenu = GUICtrlCreateContextMenu($listview) Local $aMenuId[UBound($array)] For $i = 0 To UBound($array) - 1 $aMenuId[$i] = GUICtrlCreateMenuItem($array[$i], $mMenu) Next $idButton = GUICtrlCreateButton("OK", 200, 220, 100, 25) Local $idTemp = GUICtrlCreateMenuItem("end", $mMenu) _ArrayAdd($array, "end") _ArrayAdd($aMenuId, $idTemp) GUISetState(@SW_SHOW) While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_NONE ; not truly required but it will prevent triggering Case Else for nothing Case $GUI_EVENT_CLOSE Exit Case $idButton ConsoleWrite ("Button was pressed" & @CRLF) ; delete 4th menu item GUICtrlDelete($aMenuId[4]) _ArrayDelete($aMenuId, 4) _ArrayDelete($array, 4) Case Else For $i = 0 To UBound($aMenuId) - 1 If $iMsg = $aMenuId[$i] Then MsgBox(0, "Menu Selection", $array[$i]) Next EndSwitch WEnd EndFunc ;==>_Main AlienStar 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AlienStar Posted November 28, 2020 Share Posted November 28, 2020 On 11/23/2020 at 10:27 PM, Nine said: Button deletes 4th menu item altogether : expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> _Main() Func _Main() Local $array[8] = ["Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri"] $hGUI = GUICreate("", 500, 300) $listview = GUICtrlCreateListView("categories", 20, 20, 460, 180) $mMenu = GUICtrlCreateContextMenu($listview) Local $aMenuId[UBound($array)] For $i = 0 To UBound($array) - 1 $aMenuId[$i] = GUICtrlCreateMenuItem($array[$i], $mMenu) Next $idButton = GUICtrlCreateButton("OK", 200, 220, 100, 25) Local $idTemp = GUICtrlCreateMenuItem("end", $mMenu) _ArrayAdd($array, "end") _ArrayAdd($aMenuId, $idTemp) GUISetState(@SW_SHOW) While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_NONE ; not truly required but it will prevent triggering Case Else for nothing Case $GUI_EVENT_CLOSE Exit Case $idButton ConsoleWrite ("Button was pressed" & @CRLF) ; delete 4th menu item GUICtrlDelete($aMenuId[4]) _ArrayDelete($aMenuId, 4) _ArrayDelete($array, 4) Case Else For $i = 0 To UBound($aMenuId) - 1 If $iMsg = $aMenuId[$i] Then MsgBox(0, "Menu Selection", $array[$i]) Next EndSwitch WEnd EndFunc ;==>_Main sorry for delay but I thought my self that I've replied thanks so much my friend you are amazing 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