_FileListToArray后能双击打开文件吗
本帖最后由 shw1395 于 2009-11-7 22:59 编辑#Include <File.au3>
#Include <Array.au3>
$FileList=_FileListToArray(@DesktopDir)
If @Error=1 Then
MsgBox (0,"","No Folders Found.")
Exit
EndIf
If @Error=4 Then
MsgBox (0,"","No Files Found.")
Exit
EndIf
_ArrayDisplay($FileList,"$FileList")
For $i = 1 to $FileList;
$File = FileOpen (@ScriptDir&"\"&$FileList[$i], 0);
Next
; 检查打开的文件是否可读
If $file = -1 Then
MsgBox(0, "错误", "不能打开文件.")
Exit
EndIf
FileClose($file)
我想是FileOpen用错了,我就是想双击列表中的项目,能打开。 类似与QQ菜单的东西 列出文件 双击打开 不知道是不是要创建菜单而不是_FileListToArray。 数组只能用_ArrayDisplay显示!不存在单、双击操作。。。。。。。 试下看吧!
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Include <Array.au3>
#Include <GuiListView.au3>
$FileList=_FileListToArray(@DesktopDir)
If @Error=1 Then
MsgBox (0,"","No Folders Found.")
EndIf
If @Error=4 Then
MsgBox (0,"","No Files Found.")
EndIf
$Form1 = GUICreate("Form1", 246, 293,-1,-1)
$ListView1 = GUICtrlCreateListView("11111111111111111111111111111", 8, 16, 218, 270,$LVS_SINGLESEL,$LVS_EX_GRIDLINES)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
For $i = 1 to $FileList
GUICtrlCreateListViewItem($FileList[$i],$ListView1)
Next
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ,$Menu
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK ; 响应 List1 范围内的双击
$Index = _GUICtrlListView_GetSelectedIndices($hWndListView)
If $Index <> "" Then
$L_Name = _GUICtrlListView_GetItemText($hWndListView,$Index)
$exe=FileGetShortcut(@DesktopDir&'\'&$L_Name)
RunWait($exe)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
本帖最后由 maxkingmax 于 2009-11-5 08:48 编辑
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>
$FileList = _FileListToArray(@DesktopDir)
if isarray($FileList)then
$Form1 = GUICreate("Form1", 246, 293, -1, -1)
$ListView1 = GUICtrlCreateListView("11111111111111111111111111111", 8, 16, 218, 270, $LVS_SINGLESEL, $LVS_EX_GRIDLINES)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
For $i = 1 To $FileList
GUICtrlCreateListViewItem($FileList[$i], $ListView1)
Next
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
endif
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $Menu
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK ; 响应 List1 范围内的双击
$Index = _GUICtrlListView_GetSelectedIndices($hWndListView)
If $Index <> "" Then
$L_Name = _GUICtrlListView_GetItemText($hWndListView, $Index)
Select
Case StringRight($L_Name, 4) = ".lnk"
$exe = FileGetShortcut(@DesktopDir & '\' & $L_Name)
RunWait($exe)
Case StringRight($L_Name, 4) = ".exe" Or StringRight($L_Name, 4) = ".com"
$exe = @DesktopDir & '\' & $L_Name
RunWait($exe)
Case Else
ShellExecuteWait(@DesktopDir & '\' & $L_Name)
EndSelect
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY稍微改了下楼上的代码! 4楼的代码有非数组变量错误提示
5楼的改进了
感谢jxpxfeiw maxkingmax 两位的大力帮助,再次感谢。 4楼的代码有非数组变量错误提示
5楼的改进了
感谢jxpxfeiw maxkingmax 两位的大力帮助,再次感谢。 不错。学习一下。。 提交了2次?请版主删掉一个重复的楼层。 学习学习或许有用 回复 11# 单毛线
多谢!学习了
页:
[1]