;-------- saved at Montag, 3. November 2008 12:52:53 -------------- ;-------- http://www.autohotkey.com/forum/topic37274.html --- MODIFIED=20110725 /* -first start shows desktop-tree ( add your own favorite tree-roots ) -some programs for gwbasic -open ahk/basic/text files in editbox or start with doubleclick -open pictures and use keys UP/DOWN or SPACE */ #NoEnv #Persistent #NoTrayIcon #SingleInstance Force setworkingdir,%A_scriptdir% Sendmode,InputThenPlay SetBatchLines -1 SetWinDelay -1 SetControlDelay -1 Process Priority , , High transform,S,chr,32 PR=c:\gwbasic.exe EXT2 =txt,ahk,csv,bat,bak,bas,css,ba,ini,hta,log ;-- only show these extensions in EditBox EXT3 =png,jpg,bmp,tif,gif ;-- pictures ;-- allow to start without asking: EXT9 =pdf,mov,mp4,mp3,flv,txt,ahk,csv,ini,hta,png,jpg,bmp,tif,gif,txt,ahk,csv,bas,ini,hta RSSINI=%A_scriptdir%\LV_TreeviewINI.txt ifnotexist,%rssini% IniWrite,Desktop,%rssini%,Root1,KEY1 IniRead,RootX,%rssini%,Root1,KEY1 gosub,aax2 Menu,S1,add,MyTREE ,MH1 Menu,S1,add,DOCTXT ,MH1 Menu,S1,add,VIDEO ,MH1 Menu,S1,add,FOTO ,MH1 Menu,S1,add,MUSIC ,MH1 Menu,S1,add,Filme ,MH1 Menu,S1,add,csvtxt ,MH1 Menu,S1,add,Desktop ,MH1 ;---------------------------- Menu,S2,add,Volume ,MH2 Menu,S2,add,Charmap ,MH2 ;Menu,S2,add,MySaPrograms,MH2 ;Menu,S2,add,SaPrograms ,MH2 ;---------------------------- menu,myMenuBar,Add,ROOT ,:S1 menu,myMenuBar,Add,Programme ,:S2 ;---------------------------- gui,2:menu,MyMenuBar ;---------------------------- WA=%A_screenwidth% HA=%A_screenheight% SHOWW:=(WA*99)/100 ;-- GUI width SHOWH:=(HA*93)/100 ;-- GUI height TRH:=(HA*72)/100 LWH:=(HA*72)/100 EDH:=(HA*86)/100 PIH:=(HA*65)/100 ;-- picture height BT1:=(HA*83)/100 ;-- buttons BT2:=(HA*86)/100 ;-- buttons BT3:=(HA*88)/100 ;-- buttons X1:=(WA*1 )/100 W1:=(WA*11 )/100 X2:=(WA*12.5)/100 W2:=(WA*13 )/100 X3:=(WA*26.5)/100 W3:=(WA*72)/100 W9:=(WA*97)/100 Gui,2:default Gui,2: margin, 0, 0 Gui,2: Add, TreeView, vMyTree1 x%x1% y0 w%w1% h%trh% vMyTree1 gMyTree ImageList%ImageListID% Gui,2: Add, ListView, vMyList1 x%x2% y0 w%w2% h%lwh% vMyList1 gMyList -hdr -multi AltSubmit, Name Gui,2:Font,,FixedSys Gui,2:Add, Edit , x%x3% y0 w%w3% h%edh% vA2x , Gui,2: Add, Button , x10 y%bt1% w100 h22 gOpen1 ,Text-File Gui,2: Add, Button , x10 y%bt2% w100 h22 gSave1 ,Text-SAVE Gui,2: Add, Button , x120 y%bt1% w100 h22 gOpen2 ,Folder Gui,2: Add, Button , section x%x3% y%bt3% w130 h22 gGWBASIC1 ,GWBASIC-convert Gui,2: Add, Button , xp+140 y%bt3% w110 h22 gGWBASIC2 ,GWBASIC-RUN Gui,2: Add, Button , xp+120 y%bt3% w120 h22 gSystem1 ,GWBASIC-CLOSE ;Gui,2: Add, Button , xp+130 y%bt3% w90 h22 g80Chars ,80-Chars ;Gui,2: Add, Button , xp+100 y%bt3% w90 h22 gREMARKS ,Remarks Gui,2: Add, Button , xp+200 y%bt3% w90 h22 gReload1 ,Reload ImageListID1 := IL_Create(10) ImageListID2 := IL_Create(10, 10, true) LV_SetImageList(ImageListID1) LV_SetImageList(ImageListID2) Gui,2: Add, StatusBar, gMyStatusBar SB_SetParts(W1,W2,W3) SplashTextOn, 200, 25, Explorer, Loading... gosub,readtree SplashTextOff Gui,2: Show,x0 y0 w%showw% h%showh%,TREEVIEW Example return ;-------------------------------------------------------- Readtree: TV_Delete() LV_Delete() AddSubFoldersToTree(TreeRoot) GuiControl,2: -Redraw, MyTree1 AddSubFoldersToTree(folder, ID = 0) { if ID = 0 ID := TV_Add(truc, truc , "Icon10 select expand") Loop %folder%\*.*, 2 AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ID , "Icon4")) } GuiControl,2: +Redraw, MyTree1 return ;-------------------------------------------------- 3Guiclose: gui,3:destroy return ;-------------------------------------------------- 2GuiClose: gui,3:destroy ExitApp ;-------------------------------------------------- Reload1: reload return Open2: Gui,2:submit,nohide run,%SelectedFullPath% return ;-------------------------------------------------- ;---- textfile ----------- OPEN1: Gui,2: Submit,nohide ;msgbox, 262208,Message,File=%f1% SplitPath, F1, name, dir, ext, name_no_ext, drive If Ext Not In %ext2% return else run,notepad %f1% return ;-------------------------------------------------- save1: Gui,2: Submit,nohide GuiControlGet,C,,A2x if (F1="" or C="") return ;msgbox, 262208,Message,File=%f1%`n%c% ;return SplitPath, F1, name, dir, ext, name_no_ext, drive If Ext Not In %ext2% return else { msgbox, 262436, ,Want you overwrite`n%F1% ? ifmsgbox,NO return ifmsgbox,Cancel return } ;-- or use filedelete -- filerecycle,%f1% stringreplace,C,C,`n,`r`n,all Fileappend,%c%`r`n,%f1% ;msgbox, 262208,Message,File %F1% is saved ;run,%f1% run,%SelectedFullPath% ;-- open folder return ;-------------------------------------------------- ;------------------------------------------------------------------ MH1: IniRead,CC3,%rssini%,Root1,KEY1 if CC3<>%A_ThisMenuItem% { IniWrite,%A_ThisMenuItem%,%rssini%,Root1,KEY1 ;IniRead,RootX,%rssini%,Root1,KEY1 Rootx=%A_ThisMenuItem% gosub,AAX2 return } aax2: if RootX=doctxt Treeroot=c:\M_doctxt if RootX=csvtxt Treeroot=c:\M_csvtxt if RootX=music Treeroot=c:\M_music if RootX=Filme Treeroot=c:\M_Filme if RootX=Video Treeroot=c:\M_VIDEO if RootX=Foto Treeroot=c:\M_Foto if RootX=MyTree Treeroot=C:\1A\_00_MAIN_AHK\1A_MyTreeview if RootX=Desktop Treeroot=%A_desktop% gosub,readtree return ;------------------------------------------------------------------ ;------------------------------------------------------------------ MH2: if A_thisMenuItem=Volume { run,sndvol32 run,sndvol32 /rec CN=RunDLL32.EXE shell32.dll,Control_RunDLL mmsys.cpl,,1 run,%CN% } if A_thisMenuItem=Charmap run,charmap /* if A_thisMenuItem=MySaPrograms run,C:\1A\_00_MAIN_AHK\1A_MySaPrograms if A_thisMenuItem=SaPrograms run,C:\Programme_Standalone */ return ;------------------------------------------------------------------ ;------------------------------ MyTree: if A_GuiEvent <> S return GuiControl,2:,A2x, TV_GetText(SelectedItemText, A_EventInfo) ParentID := A_EventInfo Loop { ParentID := TV_GetParent(ParentID) if not ParentID break TV_GetText(ParentText, ParentID) SelectedItemText = %ParentText%\%SelectedItemText% } SelectedFullPath = %TreeRoot%\%SelectedItemText% StringReplace, SelectedFullPath, SelectedFullPath, \\ , \ StringRight, LastChar, SelectedFullPath, 1 if LastChar <> \ SelectedFullPath = %SelectedFullPath%\ FilenameforSB = Loading Files SB_SetText(SelectedFullPath . FilenameforSB, 1) LV_Delete() VarSetCapacity(Filename, 260) sfi_size = 352 VarSetCapacity(sfi, sfi_size) if (SelectedItemText = %ParentText%) rooticonlist= %treeroot%\ else rooticonlist= %SelectedFullPath% FileCount = 0 TotalSize = 0 GuiControl,2: -Redraw, MyList1 Loop %rooticonlist%*.* { FileName := A_LoopFileFullPath SplitPath, FileName,,, FileExt if FileExt in EXE,ICO,ANI,CUR,LNK { ExtID := FileExt IconNumber = 0 } else { ExtID = 0 Loop 7 { StringMid, ExtChar, FileExt, A_Index, 1 if not ExtChar break ExtID := ExtID | (Asc(ExtChar) << (8 * (A_Index - 1))) } IconNumber := IconArray%ExtID% } if not IconNumber { if not DllCall("Shell32\SHGetFileInfoA", "str", FileName, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101) IconNumber = 9999999 else { hIcon = 0 Loop 4 hIcon += *(&sfi + A_Index-1) << 8*(A_Index-1) IconNumber := DllCall("ImageList_ReplaceIcon", "uint", ImageListID1, "int", -1, "uint", hIcon) + 1 DllCall("ImageList_ReplaceIcon", "uint", ImageListID2, "int", -1, "uint", hIcon) DllCall("DestroyIcon", "uint", hIcon) IconArray%ExtID% := IconNumber } } FileCount += 1 TotalSize += A_LoopFileSize LV_Add("Icon" . IconNumber, A_LoopFileName) } GuiControl,2: +Redraw, MyList1 SB_SetText(FileCount . " files", 1) SB_SetText(Round(TotalSize / 1024, 1) . " KB", 2) FilenameforSB = SB_SetText(SelectedFullPath . FilenameforSB, 3) return ;------------------------------ MyList: Gui,2:submit,nohide Gui,2:default Gui,2:ListView,MyList1 RN:=LV_GetNext("C") RF:=LV_GetNext("F") GC:=LV_GetCount() if RN=0 return ;gui,3:destroy ;GuiControl,2:Enable,A2x if A_GuiEvent = Normal { GuiControl,2: ,A2x, LV_GetText(FileNameforSB, A_EventInfo, 1) StringRight, LastChar, SelectedFullPath, 1 if LastChar <> \ SelectedFullPath = %SelectedFullPath%\ ;SB_SetText(FileNameforSB, 3) F1=%SelectedFullPath%%FilenameforSB% SB_SetText(F1, 3) SplitPath, F1, name, dir, ext, name_no_ext, drive ;----- if text ----------- If Ext In %ext2% { GuiControl,2:Enable,A2x Fileread,a,%F1% GuiControl,2: ,A2x, %a% return } ;------ pictures ---------- If Ext In %ext3% gosub,showpict } if A_GuiEvent=K { LV_GetText(C1,RF,1) F1=%SelectedFullPath%%C1% SplitPath, F1, name, dir, ext, name_no_ext, drive ;- scroll Forward with SPACE-key or use UP/DOWN ---------- GetKeyState, State,space If (State = "D") { ;msgbox, 262208,SPACE,Pressed SPACE`n`nRow=%rn%`nC1=%c1%,2 RF:=(RF+1) LV_Modify(RF, "+Select +Focus") ;-- select focus LV_GetText(C1,RF,1) F1=%SelectedFullPath%%C1% SplitPath, F1, name, dir, ext, name_no_ext, drive if (RF=(GC)) msgbox, 262208, Forward, Row=%rn%`nReached END`n%C1% , 2 If Ext In %ext3% gosub, showpict } GetKeyState,state1,UP if (state1="D") { if RF=1 msgbox, 262208, Backward, Row=%rn%`nReached FirstRow`n%C1% , 2 If Ext In %ext3% gosub, showpict } GetKeyState,state2,DOWN if (state2="D") { if (RF=(GC)) msgbox, 262208, Forward, Row=%rn%`nReached END`n%C1% , 2 If Ext In %ext3% gosub, showpict } } ;------------ if A_GuiEvent = Doubleclick { LV_GetText(C1, A_EventInfo, 1) F1=%SelectedFullPath%%C1% SplitPath, F1, name, dir, ext, name_no_ext, drive If Ext In %Ext9% run,%f1% else { msgbox, 262180, , Want you RUN`n%f1% ? IfMsgBox,No return Else run,%f1% } } ;------------ if A_GuiEvent = Rightclick { LV_GetText(C1, A_EventInfo, 1) F1=%SelectedFullPath%%C1% SB_SetText(F1,3) If Ext In %Ext9% run,%f1% else { msgbox, 262180, , Want you RUN`n%f1% ? IfMsgBox,No return Else run,%f1% } } return ;------------------------------ ShowPict: gui,3:destroy GuiControl,2:Disable,A2x ;Gui,2:Add,Picture,x220 y420 w200 h150 +0x4000000,%f1% ;-- allow once a background behind GUI Gui,3: +Alwaysontop Gui,3:Add,Picture,x0 y0 w%w3% h%pih%,%f1% Gui,3:Show,x%x3% y30 w%w3% h%pih% Gui,2:Show WinActivate return MyStatusBar: if A_GuiEvent = normal { if a_eventinfo = 3 Msgbox, %f1% } return ;------------------------------ ;------ replace 13 with 13/10 ----------- gwbasic1: Gui,2:submit,nohide GuiControlGet,C,,A2x if (F1="" or C="") return SplitPath, F1, name, dir, ext, name_no_ext, drive if (ext="bas" or ext="ba") { msgbox, 262436, ,This converts 13 to 13/10`nOriginal file is in RecycleBin`n%F1% ? ifmsgbox,NO return ifmsgbox,Cancel return filerecycle,%f1% stringreplace,C,C,`r,`r`n,all ;F2=%dir%\%name_no_ext%_%A_now%.%ext% ;Fileappend,%c%`r`n,%f2% Fileappend,%c%`r`n,%f1% ;msgbox, 262208,Message,File %F1% is saved ;run,%f2% GuiControl,2:,A2x, ;Fileread,a,%F2% Fileread,a,%F1% GuiControl,2: ,A2x, %a% run,%SelectedFullPath% ;-- open folder } return ;------------------------------------------------------------- ;-- run gwbasic -------- GWBASIC2: Gui,2:submit,nohide GuiControlGet,C,,A2x if (F1="" or C="") return SplitPath, F1, name, dir, ext, name_no_ext, drive if (ext="bas") { SplitPath, F1, name, dir, ext, name_no_ext, drive Loop, %F1% ;-- create shortpath SP1= %A_loopFileShortPath% Run,%ComSpec% /k %PR% %SP1%,,,PID1 } return ;------------------------------------------------------------- 80CHARS: Gui,2:submit,nohide GuiControlGet,C,,A2x if (F1="" or C="") return SplitPath, F1, name, dir, ext, name_no_ext, drive F2=%dir%\%name_no_ext%_%A_now%.%ext% if (ext="txt") { L2:=(81) Loop,Read,%F1% { LR=%A_LoopReadLine% LR=%LR% ;remove leading spaces if LR= continue stringlen,L1,LR if (L1<L2) { Fileappend,%LR%`r`n,%F2% continue } E= StringSplit,A,LR,%S% loop,%A0% { D:=A%A_Index% E=%E%%S%%D% stringlen,L1,E if (L1<L2) continue else { Fileappend,%E%`r`n,%F2% E= continue } } ;Fileappend,%S%%E%`r`n,%F2% ;write rest Fileappend,%E%`r`n,%F2% ;write rest } GuiControl,2:,A2x, Fileread,a,%F2% GuiControl,2: ,A2x, %a% run,%SelectedFullPath% ;-- open folder ifexist,%f2% run,%f2% } return ;------------------------------------------------------------- ;-------------- move remarks in ahk-script ---------- remarks: Gui,2:submit,nohide GuiControlGet,C,,A2x if (F1="" or C="") return SplitPath, F1, name, dir, ext, name_no_ext, drive F2=%dir%\%name_no_ext%_%A_now%.%ext% Autotrim,off TAB1=81 if (ext="ahk") { Loop,Read,%F1% { LR= C1= C2= LR=%A_LoopReadLine% stringreplace,LR,LR,%s%;,?,all StringSplit,C,LR,?, C1 := LP(C1,TAB1,S,"L") if C2= e4=%e4%%c1%%s%%c2%`r`n else e4=%e4%%c1%%s%;-- %c2%`r`n } Fileappend,%e4%,%f2% e4= LR= C1= C2= GuiControl,2:,A2x, Fileread,a,%F2% GuiControl,2: ,A2x, %a% run,%SelectedFullPath% ;-- open folder ifexist,%f2% run, notepad %f2% } return ;------------------------------------------------------------- SYSTEM1: Settitlematchmode,2 SetKeyDelay,25,5 ;dd=C:\WINDOWS\system32\cmd.exe dd=cmd.exe ;IfWinExist, cmd.exe ; ifwinexist, %V2% ; winactivate, %V2% ;#IfWinActive ahk_class ConsoleWindowClass WinWait,%dd% IfWinNotActive ,%dd%,,WinActivate,%dd% WinWaitActive,%dd% { sleep,1300 ControlSend,,^{CtrlBreak}`r`n,ahk_pid %PID1% ;-- sleep,1100 ControlSend,,system`r`n,ahk_pid %PID1% ;-- quit GWBASIC sleep,1100 ControlSend,,exit`r`n,ahk_pid %PID1% ;-- quit DOS } return ;------------------------------------------------------------- ;----------- LinePadding BoBo -------------- LP(String,FieldLen,ToAppend,Justification) { StringLen, StringLen, String LCnt := FieldLen-StringLen Loop, % LCnt Appended := (Appended . ToAppend) If Justification = R Return (Appended . String) If Justification = L Return (String . Appended) } ;=========== END script LinePadding =============== ;======================== END PROGRAM ==================================================================
TreeVIEW控件实例:动态加载本地文件
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
还是Shell厉害
赞
好像很厉害。感谢大佬
学习