找回密码
 加入
搜索
查看: 3994|回复: 11

_FileListToArray后能双击打开文件吗

[复制链接]
发表于 2009-11-4 21:36:04 | 显示全部楼层 |阅读模式
本帖最后由 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[0];
$File = FileOpen (@ScriptDir&"\"&$FileList[$i], 0);
Next
; 检查打开的文件是否可读
If $file = -1 Then
    MsgBox(0, "错误", "不能打开文件.")
    Exit
EndIf

FileClose($file)

我想是FileOpen用错了,我就是想双击列表中的项目,能打开。
 楼主| 发表于 2009-11-4 21:37:39 | 显示全部楼层
类似与QQ菜单的东西 列出文件 双击打开 不知道是不是要创建菜单而不是_FileListToArray。
发表于 2009-11-4 23:27:54 | 显示全部楼层
数组只能用_ArrayDisplay显示!不存在单、双击操作。。。。。。。
发表于 2009-11-4 23:41:48 | 显示全部楼层
试下看吧!
#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[0]
        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[0])
                                        EndIf
                        EndSwitch
                EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc  
[/code]
发表于 2009-11-5 08:46:15 | 显示全部楼层
本帖最后由 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[0]
        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[0])
                                                        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
稍微改了下楼上的代码!
 楼主| 发表于 2009-11-7 22:58:29 | 显示全部楼层
4楼的代码有非数组变量错误提示
5楼的改进了
感谢jxpxfeiw maxkingmax 两位的大力帮助,再次感谢。
 楼主| 发表于 2009-11-7 22:58:54 | 显示全部楼层
4楼的代码有非数组变量错误提示
5楼的改进了
感谢jxpxfeiw maxkingmax 两位的大力帮助,再次感谢。
发表于 2009-11-8 08:39:17 | 显示全部楼层
不错。学习一下。。
 楼主| 发表于 2009-11-8 11:34:20 | 显示全部楼层
提交了2次?请版主删掉一个重复的楼层。
发表于 2013-1-9 17:07:03 | 显示全部楼层
学习学习或许有用
发表于 2014-2-17 21:56:54 | 显示全部楼层
回复 11# 单毛线

多谢!学习了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 13:25 , Processed in 0.074007 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表