2013-08-01 60 views
0

我有被設置爲最近的文件的用戶的選擇:AutoIt的最近的文件菜單

$loc = FileSelectFolder("Choose file location...", "\") 
$file = FileOpenDialog("Choose file...", $loc, "Jar Files (*.jar*)") 
GUICtrlCreateMenuItem($file, $recentfilesmenu) 

我試圖通過從它那裏得到的信息:

IniWrite("C:\Config.ini", "Recent", "Recent", GUICtrlRead($recentfilesmenu)) 

但只給了我號碼68.我的錯誤在哪裏?

回答

2

數字68是菜單的controlID。

您需要使用_GUICtrlMenu_GetItemText閱讀菜單項的文本:

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

$hGui = GUICreate('Read Menu Item', 400, 300) 
$mnuFile = GUICtrlCreateMenu('&File') 
$mnuFileExit = GUICtrlCreateMenuItem('Exit', $mnuFile) 
GUISetState() 

; read the text of the menu item 
$hMenu = _GUICtrlMenu_GetMenu($hGui) 
$sText = _GUICtrlMenu_GetItemText($hMenu, $mnuFileExit, False) 
MsgBox(0, 'Menu item text', $sText) 

While 1 
    $msg = GUIGetMsg() 
    If $msg = $GUI_EVENT_CLOSE Or $msg = $mnuFileExit Then ExitLoop 
WEnd 

此輸出:退出


更新

要拿起馬特的你建議也可以利用GUICtrlRead的高級參數[叔:

IniWrite("C:\Config.ini", "Recent", "Recent", GUICtrlRead($recentfilesmenu, 1)) 
+1

另外,您可以使用'GUICtrlRead'與先進的標誌設置,而無需包括獲取文本'GUIMenu.au3' – Matt

+0

感謝馬特的提示,我更新了答案。 – mrt

+0

@mrt謝謝。我得到它的工作。我只是好奇。我應該怎樣才能將過去的項目添加到列表中。如何獲得我之前選擇的項目,而不是顯示列表中的當前項目。也許添加,所以它可以顯示幾個項目,而不是覆蓋,如果該項目已經存在? – EpicKnarvik97