TinyHacker Posted August 10, 2010 Share Posted August 10, 2010 hello: in this script, openning a file.. creates a new "menuitem" in "$recentfilesmenu"! So.. what if i wanted to show a "msgbox" which shows the "file name" when i click on that "menuitem" which holdes that name??? #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Opt('MustDeclareVars', 1) Local $defaultstatus = "Ready", $status, $filemenu, $fileitem Local $helpmenu, $saveitem, $infoitem, $exititem, $recentfilesmenu Local $separator1, $viewmenu, $viewstatusitem, $okbutton, $cancelbutton Local $statuslabel, $msg, $file GUICreate("My GUI menu", 300, 200) $filemenu = GUICtrlCreateMenu("&File") $fileitem = GUICtrlCreateMenuItem("Open", $filemenu) $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu, 1) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $fileitem Then $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)") If @error <> 1 Then GUICtrlCreateMenuItem($file, $recentfilesmenu) EndIf If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 10, 2010 Share Posted August 10, 2010 Keep track of your items in an array: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <Array.au3> Opt("GuiOnEventMode", 1) ; Array to hold items ; [0] = ID ; [1] = Text Global $aRecentFiles[1][2] = [[0, ""]] Global $hGUI = GUICreate("My GUI menu", 300, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") Global $FileMenu = GUICtrlCreateMenu("&File") Global $OpenItem = GUICtrlCreateMenuItem("Open", $FileMenu) GUICtrlSetOnEvent(-1, "_MenuHit") Global $RecentFilesSubmenu = GUICtrlCreateMenu("Recent Files", $FileMenu, 1) GUISetState() While 1 Sleep(20) WEnd Func _MenuHit() Local $sNewFile, $idNewItem, $sText Switch @GUI_CtrlId Case $OpenItem $sNewFile = FileOpenDialog("Choose file...", @TempDir, "All (*.*)") If Not @error Then $idNewItem = GUICtrlCreateMenuItem($sNewFile, $RecentFilesSubmenu) GUICtrlSetOnEvent(-1, "_MenuHit") ; Add to global array ReDim $aRecentFiles[UBound($aRecentFiles) + 1][2] $aRecentFiles[0][0] = UBound($aRecentFiles) - 1 $aRecentFiles[$aRecentFiles[0][0]][0] = $idNewItem $aRecentFiles[$aRecentFiles[0][0]][1] = $sNewFile EndIf Case Else ; Find ID in array For $n = 1 To $aRecentFiles[0][0] If $aRecentFiles[$n][0] = @GUI_CtrlId Then $sText = $aRecentFiles[$n][1] MsgBox(64, "Item", "Item ID = " & @GUI_CtrlId & @CRLF & "Text = " & $sText) ExitLoop EndIf Next EndSwitch EndFunc ;==>_MenuHit Func _Quit() Exit EndFunc ;==>_Quit You can delete items too, just be sure to update the count at $aRecentFile[0][0] after you do. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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