Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GUIConstantsEx.au3>
- #include <GuiTreeView.au3>
- #include <WindowsConstants.au3>
- #include <GuiImageList.au3>
- #Include <File.au3>
- #include <GuiListView.au3>
- #Include <Array.au3> ; тест
- Opt("GUIOnEventMode", 1)
- Global $PathCur
- $Gui=GUICreate('Файловый менеджер', 640, 560)
- GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
- $StatusBar = GUICtrlCreateLabel('', 5, 560-18, 640-10, 17)
- $restart = GUICtrlCreateButton("R", 640-20, 2, 18, 20)
- ; GUICtrlSetResizing(-1, 512 + 256 + 32 + 4)
- GUICtrlSetOnEvent(-1, "_restart")
- $Address = GUICtrlCreateInput('', 5, 6, 570, 24)
- $restart = GUICtrlCreateButton(">", 577, 6, 24, 24)
- GUICtrlSetOnEvent(-1, "_Jump")
- $TreeView = GUICtrlCreateTreeView(0, 35, 216, 500)
- ; GUICtrlSetResizing(-1, 2 + 4 + 32 + 64)
- $hTreeView = GUICtrlGetHandle($TreeView)
- $hImage = _GUIImageList_Create(16, 16, 5)
- _GUIImageList_AddIcon($hImage, @SystemDir&'\shell32.dll', -4)
- _GUIImageList_AddIcon($hImage, @SystemDir&'\shell32.dll', -5)
- _GUIImageList_AddIcon($hImage, @SystemDir&'\shell32.dll', 0)
- _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImage)
- $E=''
- $i=1
- While 1
- $i+=1
- $sExt = RegEnumKey("HKCR", $i)
- If @error Or StringLeft($sExt, 1)<>'.' then ExitLoop
- $ico1=_FileDefaultIcon($sExt)
- If Not @error Then
- Switch UBound($ico1)
- Case 2
- If StringInStr(';.exe;.scr;.ico;.ani;.cur;', ';'&$sExt&';') Then
- ContinueLoop
- Else
- _GUIImageList_AddIcon($hImage, $ico1[1], 0)
- If @error Then ContinueLoop
- EndIf
- Case 3
- _GUIImageList_AddIcon($hImage, $ico1[1], $ico1[2])
- If @error Then ContinueLoop
- EndSwitch
- $E&='|'&$sExt
- EndIf
- WEnd
- $E=StringTrimLeft($E, 1)
- $aE=StringSplit($E, '|')
- ; $hImage = _GUIImageList_Create(16, 16, 5, 3)
- ; _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -4)
- ; _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 0)
- ; _GUICtrlListView_SetImageList($hListView, $hImage, 1)
- $DrivesArr = DriveGetDrive( "all" )
- For $i = 1 to $DrivesArr[0]
- If $DrivesArr[$i]='a:' Or DriveGetType( $DrivesArr[$i]&'\' )='CDROM' Then ContinueLoop
- $hTmp = _GUICtrlTreeView_Add($hTreeView, 0, StringUpper($DrivesArr[$i]), 0, 0)
- ; $tmp=_FolderSearch($DrivesArr[$i], '*', 0, 0)
- $tmp=_FileListToArray($DrivesArr[$i], "*", 2)
- For $j = 1 to $tmp[0]
- _GUICtrlTreeView_AddChild($hTreeView, $hTmp, $tmp[$j], 0, 0)
- Next
- Next
- ; перейти к нужной папке
- ; $StartPath='C:\AutoIt3\Notepad++'
- ; $aStartPath=StringSplit($StartPath, '\')
- ; For $i = 2 to $aStartPath[0]
- ; _GUICtrlTreeView_FindItem($hTreeView, $sText)
- ; Next
- ; $StartPath='C:\AutoIt3\Notepad++'
- ; $aStartPath=StringSplit($StartPath, '\')
- ; For $i = 2 to $aStartPath[0]
- ; $aStartPath[1]&='\'&$aStartPath[$i]
- ; $hTmp = _GUICtrlTreeView_AddChild($hTreeView, $aStartPath[$i], $aStartPath[$i], 0, 0)
- ; $tmp=_FolderSearch($aStartPath[1], '*', 0, 0)
- ; For $j = 1 to $tmp[0]
- ; _GUICtrlTreeView_AddChild($hTreeView, $hTmp, $tmp[$j], 0, 0)
- ; Next
- ; Next
- ; $FolderList=_FolderSearch($StartPath, '*', 0, 0)
- ; For $i = 1 to $FolderList[0]
- ; $hTmp = _GUICtrlTreeView_AddChild($hTreeView, $disk, $FolderList[$i], 0, 0)
- ; $tmp=_FolderSearch($StartPath&'\'&$FolderList[$i], '*', 0, 0)
- ; For $j = 1 to $tmp[0]
- ; _GUICtrlTreeView_AddChild($hTreeView, $hTmp, $tmp[$j], 0, 0)
- ; Next
- ; Next
- $ListView = GUICtrlCreateListView(' ', 220, 35, 420, 500, $LVS_NOCOLUMNHEADER +$LVS_SHOWSELALWAYS, $LVS_OWNERDRAWFIXED)
- GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
- GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_TRACKSELECT, $LVS_EX_TRACKSELECT)
- GUICtrlSetBkColor(-1, 0xf0f0f0) ; 0xE0DFE3
- ; GUICtrlSetResizing(-1, 6 + 32 + 64)
- $hListView = GUICtrlGetHandle($ListView)
- _GUICtrlListView_SetColumnWidth($ListView, 0, 390)
- _GUICtrlListView_SetImageList($hListView, $hImage, 1)
- ; GUICtrlSetOnEvent(-1, "_OpenExplorer")
- ; $Label1=GUICtrlCreateLabel('StatusBar', 5, 260-20, 150, 17)
- GUISetState ()
- GUIRegisterMsg(0x004E, 'WM_NOTIFY')
- While 1
- Sleep(100000)
- WEnd
- Func _Exit()
- Exit
- EndFunc
- Func _Jump()
- $Address0=GUICtrlRead($Address)
- If FileExists($Address0) Then
- ; $Address0=StringReplace($Address0, '\', '|')
- $aAdrs=StringSplit($Address0, '\')
- $tmp=_GUICtrlTreeView_GetFirstItem($hTreeView)
- If _GUICtrlTreeView_GetText($hTreeView, $tmp)=$aAdrs[1] Then
- ; _GUICtrlTreeView_ExpandedOnce($hTreeView, $tmp)
- ; ControlTreeView ($Gui, "", $hTreeView, "Expand", $aAdrs[1])
- _GUICtrlTreeView_SetSelected($hTreeView, $tmp)
- _GUICtrlTreeView_ClickItem($hTreeView, $tmp, 'left', False, 2)
- MsgBox(0, '1 - '&$tmp, $aAdrs[1])
- Else
- While 1
- $tmp=_GUICtrlTreeView_GetNext($hTreeView, $tmp)
- If _GUICtrlTreeView_GetText($hTreeView, $tmp)=$aAdrs[1] Then
- ; _GUICtrlTreeView_ExpandedOnce($hTreeView, $tmp)
- ; ControlTreeView ($Gui, "", $hTreeView, "Expand", $aAdrs[1])
- _GUICtrlTreeView_SetSelected($hTreeView, $tmp)
- _GUICtrlTreeView_ClickItem($hTreeView, $tmp, 'left', False, 2)
- MsgBox(0, '2 - '&$tmp, $aAdrs[1])
- ExitLoop
- EndIf
- WEnd
- EndIf
- If $aAdrs[0]>1 Then
- For $i = 2 to $aAdrs[0]
- _GUICtrlTreeView_GetFirstChild($hTreeView, $tmp)
- MsgBox(0, '11 - '&$tmp&' - '&$i, _GUICtrlTreeView_GetText($hTreeView, $tmp))
- If _GUICtrlTreeView_GetText($hTreeView, $tmp)=$aAdrs[$i] Then
- ; _GUICtrlTreeView_ExpandedOnce($hTreeView, $tmp)
- ; ControlTreeView ($Gui, "", $hTreeView, "Expand", $aAdrs[$i])
- _GUICtrlTreeView_SetSelected($hTreeView, $tmp)
- _GUICtrlTreeView_ClickItem($hTreeView, $tmp, 'left', False, 2)
- MsgBox(0, '3 - '&$tmp&' - '&$i, $aAdrs[$i])
- Else
- While 1
- $tmp=_GUICtrlTreeView_GetNextChild($hTreeView, $tmp)
- MsgBox(0, '22 - '&$tmp&' - '&$i, _GUICtrlTreeView_GetText($hTreeView, $tmp))
- If _GUICtrlTreeView_GetText($hTreeView, $tmp)=$aAdrs[$i] Then
- ; _GUICtrlTreeView_ExpandedOnce($hTreeView, $tmp)
- ; ControlTreeView ($Gui, "", $hTreeView, "Expand", $aAdrs[$i])
- _GUICtrlTreeView_SetSelected($hTreeView, $tmp)
- _GUICtrlTreeView_ClickItem($hTreeView, $tmp, 'left', False, 2)
- MsgBox(0, '4 - '&$tmp&' - '&$i, $aAdrs[$i])
- ExitLoop
- EndIf
- WEnd
- EndIf
- Next
- EndIf
- EndIf
- EndFunc
- Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
- Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tmp
- $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
- $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
- $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
- $iCode = DllStructGetData($tNMHDR, "Code")
- Switch $hWndFrom
- Case $hTreeView
- Switch $iCode
- Case $NM_CLICK
- ; получение хэндла кликнутого пункта и поиск его в массиве
- Local $tMPos = _WinAPI_GetMousePos(True, $hWndFrom), $tHit = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
- Local $hItem = DllStructGetData($tHit, "Item")
- If $hItem <> -1 And $hItem<>0x0 Then
- ; _GetPathItem($hWndFrom, $hItem)
- $tmp=_GetPathItem($hWndFrom, $hItem)
- If $PathCur=$tmp Then
- Return
- Else
- $PathCur=$tmp
- EndIf
- GUICtrlSetData($StatusBar, $PathCur)
- GUICtrlSetData($Address, $PathCur)
- _GUICtrlListView_BeginUpdate($hListView)
- _GUICtrlListView_DeleteAllItems($hListView)
- $tmp=_FileListToArray($PathCur, "*", 2)
- If Not @error Then
- For $i = 1 to $tmp[0]
- ; GUICtrlCreateListViewItem($tmp[$i],$ListView)
- _GUICtrlListView_AddItem($hListView, $tmp[$i], 0)
- Next
- EndIf
- $tmp=_FileListToArray($PathCur, "*", 1)
- If Not @error Then
- For $i = 1 to $tmp[0]
- ; GUICtrlCreateListViewItem($tmp[$i],$ListView)
- $tmp3=StringRegExpReplace($tmp[$i], '.*(\.\S+)', '\1')
- $ind=_ArraySearch($aE, $tmp3)
- If @error Then $ind=0
- _GUICtrlListView_AddItem($hListView, $tmp[$i], $ind+2)
- Next
- EndIf
- _GUICtrlListView_EndUpdate($hListView)
- ; _GUICtrlTreeView_BeginUpdate($hWndFrom)
- $KolChild=_GUICtrlTreeView_GetChildCount($hWndFrom, $hItem)
- If $KolChild<=0 Then Return
- ; $Expan=_GUICtrlTreeView_GetExpanded($hWndFrom, $hItem) ; иконка закрытия и открытия папки
- ; $Expan=_GUICtrlTreeView_GetImageIndex($hWndFrom, $hItem)
- ; If $Expan=1 Then
- ; _GUICtrlTreeView_SetImageIndex($hWndFrom, $hItem, 0)
- ; Else
- ; _GUICtrlTreeView_SetImageIndex($hWndFrom, $hItem, 1)
- ; EndIf
- $h=_GUICtrlTreeView_GetFirstChild($hWndFrom, $hItem)
- $KolH=_GUICtrlTreeView_GetChildCount($hWndFrom, $h)
- If $KolH>0 Then Return
- _CreateItem($hWndFrom, $h, $PathCur)
- ; $text=_GUICtrlTreeView_GetText($hWndFrom, $h)
- For $i = 1 to $KolChild-1
- $h=_GUICtrlTreeView_GetNextChild($hWndFrom, $h)
- $KolH=_GUICtrlTreeView_GetChildCount($hWndFrom, $h)
- If $KolH>0 Then Return
- _CreateItem($hWndFrom, $h, $PathCur)
- Next
- Else
- Return
- EndIf
- ; _GUICtrlTreeView_EndUpdate($hWndFrom)
- ; GUICtrlListView_SetColumnWidth($ListView, 0, $LVSCW_AUTOSIZE)
- ; Case $TVN_SINGLEEXPAND
- ; MsgBox(0, 'Message', '---')
- Case $NM_RCLICK
- Local $tMPos = _WinAPI_GetMousePos(True, $hWndFrom), $tHit = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
- Local $hItem = DllStructGetData($tHit, "Item")
- If $hItem <> -1 And $hItem<>0x0 Then
- ; MsgBox(0, 'Message', '---')
- ; $x = MouseGetPos(0)
- ; $y = MouseGetPos(1)
- ; DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $Gui, "ptr", 0)
- Else
- Return
- EndIf
- EndSwitch
- Case $hListView
- Switch $iCode
- Case $NM_DBLCLK
- $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
- $iItem = DllStructGetData($tInfo, 'Index')
- If $iItem > -1 Then
- $tmp = $PathCur&'\'&_GUICtrlListView_GetItemText($hListView, $iItem)
- If FileExists($tmp) Then ShellExecute('"'&$tmp&'"')
- EndIf
- EndSwitch
- EndSwitch
- Return $GUI_RUNDEFMSG
- EndFunc
- Func _CreateItem($hWndFrom, $h, $Path)
- $text=_GUICtrlTreeView_GetText($hWndFrom, $h)
- $tmp=_FileListToArray($Path&'\'&$text, "*", 2)
- If @error Then Return
- For $i = 1 to $tmp[0]
- _GUICtrlTreeView_AddChild($hTreeView, $h, $tmp[$i], 0, 0)
- Next
- EndFunc
- Func _GetPathItem($hWndFrom, $hItem)
- Local $Path=_GUICtrlTreeView_GetText($hWndFrom, $hItem), $text, $Path
- While 1
- $hItem=_GUICtrlTreeView_GetParentHandle($hWndFrom, $hItem)
- If $hItem = 0 Then ExitLoop
- $text=_GUICtrlTreeView_GetText($hWndFrom, $hItem)
- $Path=$text&'\'&$Path
- WEnd
- Return $Path
- EndFunc
- Func _restart()
- Local $sAutoIt_File = @TempDir & "\~Au3_ScriptRestart_TempFile.au3"
- Local $sRunLine, $sScript_Content, $hFile
- $sRunLine = @ScriptFullPath
- If Not @Compiled Then $sRunLine = @AutoItExe & ' /AutoIt3ExecuteScript ""' & $sRunLine & '""'
- If $CmdLine[0] > 0 Then $sRunLine &= ' ' & $CmdLineRaw
- $sScript_Content &= '#NoTrayIcon' & @CRLF & _
- 'While ProcessExists(' & @AutoItPID & ')' & @CRLF & _
- ' Sleep(10)' & @CRLF & _
- 'WEnd' & @CRLF & _
- 'Run("' & $sRunLine & '")' & @CRLF & _
- 'FileDelete(@ScriptFullPath)' & @CRLF
- $hFile = FileOpen($sAutoIt_File, 2)
- FileWrite($hFile, $sScript_Content)
- FileClose($hFile)
- Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sAutoIt_File & '"', @ScriptDir, @SW_HIDE)
- Sleep(1000)
- Exit
- EndFunc ;==>_restart
- Func _FileDefaultIcon($sExt)
- If $sExt = '' Or StringInStr($sExt, ':') Then Return SetError(1)
- Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _
- "dword", 0x00000040, _ ;$ASSOCF_VERIFY
- "dword", 15, _ ;$ASSOCSTR_DEFAULTICON
- "wstr", $sExt, _
- "ptr", 0, _
- "wstr", "", _
- "dword*", 65536)
- If @error Then Return SetError(1, 0, "")
- If Not $aCall[0] Then
- $sExt=StringReplace($aCall[5], '"', '')
- $sExt=StringSplit($sExt, ',')
- Opt('ExpandEnvStrings', 1)
- $sExt[1]=$sExt[1]
- Opt('ExpandEnvStrings', 0)
- Return SetError(0, 0, $sExt)
- ElseIf $aCall[0] = 0x80070002 Then
- Return SetError(1, 0, "{unknown}")
- ElseIf $aCall[0] = 0x80004005 Then
- Return SetError(1, 0, "{fail}")
- Else
- Return SetError(2, $aCall[0], "")
- EndIf
- EndFunc ;==>_FileAssociation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement