by pureexe 20/11/11, 02:55 pm
code ของ admin ใช้ได้แล้วจะลองประยุกนะครับ ข้างล่างเป็นcodeผม
อันนี้code ผมตอนเป็น Listbox (คลิกได้แต่ไม่มีรูปจะเป็นคำว่า<--folder-->ข้างหน้าแทนรูป)
- Code:
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include<File.au3>
Opt('MustDeclareVars', 1)
Global $data,$ret,$file,$Folders,$retx,$Foldersx,$btchkx,$fileold[200],$dataview,$uvx=0,$hListBox,$aItems,$hImage,$iI,$ctopen=0,$ctopenstr="",$dirwrite="<---Folder---> ",$dirwritelen=StringLen($dirwrite),$filelen,$Label_1,$Combo_2,$Buttonback
Global $backword=">--กลับไปก่อนหน้า--<"
_Main()
Func _Main()
Local $Label_1, $Combo_2, $button1, $msg,$Button2
#Region ### START Koda GUI section ### Form=
$ret =""
if $CmdLine[0]=0 Then
$btchkx=MsgBox(4,"คำเตือน","ไม่พบการส่งค่าต้องการเลือกโฟลเดอร์เองหรือไม่")
if $btchkx<>7 Then
$file=FileSelectFolder("กรุณาเลือกfolderที่จะทำการดู","","","")
Else
Exit
EndIf
Else
$file=$CmdLine[1]
EndIf
$Folders =_FileListToArray($file,"*.")
for $i =1 to $Folders[0]
$ret &=$Folders[$i] &"|"
Next
GUICreate("Explorer[Safe Mode]::Flash Drive Safe Check", 403, 470, -1, -1)
$Label_1 = GUICtrlCreateLabel("Please select folder", -2, 0, 403, 21, $SS_SUNKEN)
$Combo_2 = GUICtrlCreateCombo("", 0, 20, 402, 25)
GUICtrlSetData($Combo_2, $ret)
$hListBox = GUICtrlCreateList("", 0, 42, 404, 396, BitOR($LBS_SORT,$LBS_STANDARD,$LBS_EXTENDEDSEL,$WS_VSCROLL,$WS_BORDER))
$Button2 = GUICtrlCreateButton("เปิดไฟล์", 72, 442, 122, 20, $WS_GROUP)
$Buttonback = GUICtrlCreateButton("Back", 200, 442, 122, 20, $WS_GROUP)
_readfileall()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Combo_2
$data = GUICtrlRead($Combo_2)
$dataview=$data
if $data = $backword And $uvx>0 then
$file = ""
$uvx=$uvx-1
$data =$fileold[$uvx]
$dataview=$fileold
endif
_readfileindir()
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
GUICtrlSetData($Label_1, $dataview)
Case $msg=$hListBox
$aItems = _GUICtrlListBox_GetSelItemsText($hListBox)
Local $stockaItems=""
if $aItems[0]<>0 Then
$filelen=StringLen($aItems[1])
If StringMid($aItems[1],1,1)=StringMid($dirwrite,1,1) And StringMid($aItems[1],1,2)=StringMid($dirwrite,1,2) And StringMid($aItems[1],1,3)=StringMid($dirwrite,1,3) Then
for $i=$dirwritelen+1 to $filelen
$stockaItems&=StringMid($aItems[1],$i,1)
Next
$data=$stockaItems
EndIf
if $ctopenstr<>$aItems[1] Then
$ctopen=0
Endif
$dataview=$data
if $aItems[1] = $backword And $uvx>0 then
$file = ""
$uvx=$uvx-1
$data =$fileold[$uvx]
$dataview=$fileold
_readfileindir()
GUICtrlSetData($Label_1, $dataview)
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
endif
if $aItems[0]=1 And $ctopenstr=$aItems[1] And $ctopen=1 And StringMid($aItems[1],1,1)=StringMid($dirwrite,1,1) And StringMid($aItems[1],1,2)=StringMid($dirwrite,1,2) And StringMid($aItems[1],1,3)=StringMid($dirwrite,1,3)Then
_readfileindir()
GUICtrlSetData($Label_1, $dataview)
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
ElseIf $aItems[0]=1 And $ctopenstr=$aItems[1] And $ctopen=1 And $aItems[1]=$backword Then
$ctopenstr=""
elseif $aItems[0]=1 And $ctopenstr=$aItems[1] And $ctopen=1 Then
ShellExecute($file&"\"&$aItems[1])
$ctopenstr=""
EndIf
if $aItems[0]=1 And $ctopenstr<>$aItems[1] And $ctopen=0 Then
$ctopenstr=$aItems[1]
$ctopen=1
EndIf
EndIf
Case $msg=$Buttonback
If $uvx>0 Then
$file = ""
$uvx=$uvx-1
$data =$fileold[$uvx]
$dataview=$fileold
_readfileindir()
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
GUICtrlSetData($Label_1, $dataview)
Else
MsgBox(64,"คำเตือน","ไม่สามารถกลับไปไกลได้มากกว่านี้อีกแล้ว")
EndIf
Case $msg=$Button2
if $aItems[0]=0 Then
MsgBox(64,"คำเตือน","คุณยังไม่ได้เลือกอะไรเลย")
ElseIf (StringMid($aItems[1],1,1)=StringMid($dirwrite,1,1) And StringMid($aItems[1],1,2)=StringMid($dirwrite,1,2) And StringMid($aItems[1],1,3)=StringMid($dirwrite,1,3)) Then
MsgBox(64,"คำเตือน","เพื่อความปลอดภัยจึงไม่สามารถเปิดfolderได้")
Else
For $iI = 1 To $aItems[0]
ShellExecute($file&"\"&$aItems[$iI])
Next
EndIf
EndSelect
WEnd
EndFunc
Func _readfile()
_GUICtrlListbox_BeginUpdate($hListBox)
_GUICtrlListBox_ResetContent($hListBox)
_GUICtrlListBox_InitStorage($hListBox, 100, 4096)
_GUICtrlListBox_Dir($hListBox, $file&"\*.*")
_GUICtrlListBox_EndUpdate($hListBox)
_GUICtrlListBox_Sort($hListBox)
EndFunc
Func _readfileall()
$ret =""
$Folders =_FileListToArray($file,"*.*")
$Foldersx =_FileListToArray($file,"*.")
if $Foldersx="" Or $Folders="" Then
Else
#cs
For $i=0 To $Folders[0]
For $j=0 To $Foldersx[0]
If $Folders[$i]=$Foldersx[$j] Then
$Folders[$i]=$dirwrite&$Folders[$i]
EndIf
Next
Next
#ce
For $i=1 To $Foldersx[0]
$Foldersx[$i]=$dirwrite&$Foldersx[$i]
Next
EndIf
_GUICtrlListBox_BeginUpdate($hListBox)
_GUICtrlListBox_ResetContent($hListBox)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUICtrlListBox_InitStorage($hListBox, 100, 4096)
if $Foldersx="" Then
_GUICtrlListBox_Dir($hListBox, $file&"\*.*")
Else
for $i =1 to $Foldersx[0]
_GUICtrlListBox_InsertString($hListBox,$Foldersx[$i])
Next
_GUICtrlListBox_Dir($hListBox, $file&"\*.*")
EndIf
if $uvx>0 Then
_GUICtrlListBox_InsertString($hListBox,$backword)
EndIf
_GUICtrlListBox_EndUpdate($hListBox)
_GUICtrlListBox_Sort($hListBox)
EndFunc
Func _readfileindir()
$retx=""
if $file ="" Then
$file =$data
$fileold[$uvx]=$data
else
$fileold[$uvx]=$file
$uvx=$uvx+1
$file &="/"&$data
EndIf
$dataview=$file
GUICtrlSetData($Label_1, $dataview)
$Foldersx=""
$Foldersx =_FileListToArray($file,"*.")
if $Foldersx="" Then
else
for $i =1 to $Foldersx[0]
$retx &=$Foldersx[$i] &"|"
Next
endif
$retx&=$backword
$retx &="|"
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
_readfileall()
EndFunc
อันนี้ตอนเป็นListviewแล้ว(มีรูปแต่คคลิกไม่ได้)(ยังแก้codeไม่เสร็จดี)
- Code:
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include<File.au3>
Opt('MustDeclareVars', 1)
Global $data,$ret,$file,$Folders,$retx,$Foldersx,$btchkx,$fileold[200],$dataview,$uvx=0,$hListBox,$aItems,$hImage,$iI,$ctopen=0,$ctopenstr="",$dirwrite="<---Folder---> ",$dirwritelen=StringLen($dirwrite),$filelen,$Label_1,$Combo_2,$Buttonback
Global $backword=">--กลับไปก่อนหน้า--<"
_Main()
Func _Main()
Local $Label_1, $Combo_2, $button1, $msg,$Button2
#Region ### START Koda GUI section ### Form=
$ret =""
if $CmdLine[0]=0 Then
$btchkx=MsgBox(4,"คำเตือน","ไม่พบการส่งค่าต้องการเลือกโฟลเดอร์เองหรือไม่")
if $btchkx<>7 Then
$file=FileSelectFolder("กรุณาเลือกfolderที่จะทำการดู","","","")
Else
Exit
EndIf
Else
$file=$CmdLine[1]
EndIf
$Folders =_FileListToArray($file,"*.")
for $i =1 to $Folders[0]
$ret &=$Folders[$i] &"|"
Next
GUICreate("Explorer[Safe Mode]::Flash Drive Safe Check", 403, 470, -1, -1)
$Label_1 = GUICtrlCreateLabel("Please select folder", -2, 0, 403, 21, $SS_SUNKEN)
$Combo_2 = GUICtrlCreateCombo("", 0, 20, 402, 25)
GUICtrlSetData($Combo_2, $ret)
$hListBox = GUICtrlCreateListView("", 0, 42, 404, 396, BitOR($LBS_SORT,$LBS_STANDARD,$LBS_EXTENDEDSEL,$WS_VSCROLL,$WS_BORDER))
$Button2 = GUICtrlCreateButton("เปิดไฟล์", 72, 442, 122, 20, $WS_GROUP)
$Buttonback = GUICtrlCreateButton("Back", 200, 442, 122, 20, $WS_GROUP)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4)
_GUICtrlListView_SetImageList($hListBox, $hImage, 1)
_GUICtrlListView_AddColumn($hListBox, "รายชื่อไฟล์", 350)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 1)
_readfileandfolderviewlist($file)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Combo_2
$data = GUICtrlRead($Combo_2)
$dataview=$data
if $data = $backword And $uvx>0 then
$file = ""
$uvx=$uvx-1
$data =$fileold[$uvx]
$dataview=$fileold
endif
_readfileindir()
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
GUICtrlSetData($Label_1, $dataview)
Case $msg=$hListBox
MsgBox(64,"","44444")
$aItems = _GUICtrlListView_GetItemText($hListBox,1)
Local $stockaItems=""
$filelen=StringLen($aItems[1])
If StringInStr(FileGetAttrib($file & "\" & $aItems), "D") And ($file <> "." Or $file <> "..") Then
for $i=$dirwritelen+1 to $filelen
$stockaItems&=StringMid($aItems[1],$i,1)
Next
$data=$stockaItems
EndIf
if $ctopenstr<>$aItems Then
$ctopen=0
Endif
$dataview=$data
if $aItems = $backword And $uvx>0 then
$file = ""
$uvx=$uvx-1
$data =$fileold[$uvx]
$dataview=$fileold
_readfileindir()
GUICtrlSetData($Label_1, $dataview)
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
endif
if If StringInStr(FileGetAttrib($listF & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
_readfileindir()
GUICtrlSetData($Label_1, $dataview)
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
ElseIf $aItems<>"" And $ctopenstr=$aItems[1] And $ctopen=1 And $aItems[1]=$backword Then
$ctopenstr=""
elseif $aItems<>"" And $ctopenstr=$aItems And $ctopen=1 Then
ShellExecute($file&"\"&$aItems)
$ctopenstr=""
EndIf
if $aItems<>"" And $ctopenstr<>$aItems And $ctopen=0 Then
$ctopenstr=$aItems
$ctopen=1
EndIf
Case $msg=$Buttonback
If $uvx>0 Then
$file = ""
$uvx=$uvx-1
$data =$fileold[$uvx]
$dataview=$fileold
_readfileindir()
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
GUICtrlSetData($Label_1, $dataview)
Else
MsgBox(64,"คำเตือน","ไม่สามารถกลับไปไกลได้มากกว่านี้อีกแล้ว")
EndIf
Case $msg=$Button2
if $aItems="" Then
MsgBox(64,"คำเตือน","คุณยังไม่ได้เลือกอะไรเลย")
ElseIf (StringMid($aItems[1],1,1)=StringMid($dirwrite,1,1) And StringMid($aItems[1],1,2)=StringMid($dirwrite,1,2) And StringMid($aItems[1],1,3)=StringMid($dirwrite,1,3)) Then
MsgBox(64,"คำเตือน","เพื่อความปลอดภัยจึงไม่สามารถเปิดfolderได้")
Else
ShellExecute($file&"\"&$aItems)
EndIf
EndSelect
WEnd
EndFunc
Func _readfile()
_GUICtrlListbox_BeginUpdate($hListBox)
_GUICtrlListBox_ResetContent($hListBox)
_GUICtrlListBox_InitStorage($hListBox, 100, 4096)
_GUICtrlListBox_Dir($hListBox, $file&"\*.*")
_GUICtrlListBox_EndUpdate($hListBox)
_GUICtrlListBox_Sort($hListBox)
EndFunc
Func _readfileall()
$ret =""
$Folders =_FileListToArray($file,"*.*")
$Foldersx =_FileListToArray($file,"*.")
if $Foldersx="" Or $Folders="" Then
Else
#cs
For $i=0 To $Folders[0]
For $j=0 To $Foldersx[0]
If $Folders[$i]=$Foldersx[$j] Then
$Folders[$i]=$dirwrite&$Folders[$i]
EndIf
Next
Next
#ce
For $i=1 To $Foldersx[0]
$Foldersx[$i]=$dirwrite&$Foldersx[$i]
Next
EndIf
_GUICtrlListBox_BeginUpdate($hListBox)
_GUICtrlListBox_ResetContent($hListBox)
_GUICtrlListBox_InitStorage($hListBox, 100, 4096)
if $Foldersx="" Then
_GUICtrlListBox_Dir($hListBox, $file&"\*.*")
Else
for $i =1 to $Foldersx[0]
_GUICtrlListBox_InsertString($hListBox,$Foldersx[$i])
Next
_GUICtrlListBox_Dir($hListBox, $file&"\*.*")
EndIf
if $uvx>0 Then
_GUICtrlListBox_InsertString($hListBox,$backword)
EndIf
_GUICtrlListBox_EndUpdate($hListBox)
_GUICtrlListBox_Sort($hListBox)
EndFunc
Func _readfileindir()
$retx=""
if $file ="" Then
$file =$data
$fileold[$uvx]=$data
else
$fileold[$uvx]=$file
$uvx=$uvx+1
$file &="/"&$data
EndIf
$dataview=$file
GUICtrlSetData($Label_1, $dataview)
$Foldersx=""
$Foldersx =_FileListToArray($file,"*.")
if $Foldersx="" Then
else
for $i =1 to $Foldersx[0]
$retx &=$Foldersx[$i] &"|"
Next
endif
$retx&=$backword
$retx &="|"
GUICtrlSetData($Combo_2, "")
GUICtrlSetData($Combo_2, $retx)
_readfileandfolderviewlist($file)
EndFunc
Func _readfileandfolderviewlist($listF)
Local $search = FileFindFirstFile($listF & "\*.*"),$filea
While 1
$filea = FileFindNextFile($search)
If @error Or StringLen($filea) < 1 Then ExitLoop
If StringInStr(FileGetAttrib($listF & "\" & $filea), "D") And ($filea <> "." Or $filea <> "..") Then
;~ _GUICtrlListView_AddItem($listview1, $listF & "\" & $file, 0)
_GUICtrlListView_AddItem($hListBox, $filea, 0)
;~ SrFolder($listF & "\" & $file)
ElseIf StringInStr(FileGetAttrib($listF & "\" & $filea), "A") And ($filea <> "." Or $filea <> "..") Then
_GUICtrlListView_AddItem($hListBox, $filea, 1)
EndIf
WEnd
EndFunc ;==>SrFolder
แก้ไขล่าสุดโดย pureexe เมื่อ 20/11/11, 03:32 pm, ทั้งหมด 1 ครั้ง