本意是随便写写的 最近无事做 谁想越写越复杂 就这样吧 算帮帮新人吧
#include <WinAPIEx.au3>
#include <GuiToolBar.au3>
#include <GuiMenu.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
Global $Title = "Example"
If WinExists($Title) Then Exit
Global Enum $Add = 1000, $Page, $Exit
Global Enum $AddFile = 1100, $AddFolder, $DelFile
Local $add_file[1]
Local $pagemode[1], $pageselect = 1, $pagenum = 1
#region
$Form1 = GUICreate($Title, 600, 390)
GUISetBkColor(0xABCDEF, $Form1)
GUISetOnEvent(-3, "GuiClick")
$ListView1 = GUICtrlCreateListView("", 30, 30, 540, 300)
_GUICtrlListView_InsertColumn($ListView1, 0, "文件名", 160, 2)
_GUICtrlListView_InsertColumn($ListView1, 1, "路径", 300, 2)
_GUICtrlListView_InsertColumn($ListView1, 2, "后缀名", 80, 2)
GUICtrlCreateLabel("无聊做反而越来越复杂了 By Coolk", 230, 335, 300, 25)
GUICtrlSetFont(-1, 12)
$ToolbarGui = GUICreate($Title, 180, 30, 30, 326, 0x80000000, 0x00080000 + 0x00000040, $Form1)
GUISetBkColor(0xABCDEF, $ToolbarGui)
_WinAPI_SetLayeredWindowAttributes($ToolbarGui, 0xABCDEF, 255)
$Toolbar = _GUICtrlToolbar_Create($ToolbarGui)
GUICtrlSetBkColor(-1, -2)
_GUICtrlToolbar_SetStyle($Toolbar, BitOR($TBSTYLE_LIST, $TBSTYLE_TRANSPARENT))
_GUICtrlToolbar_SetExtendedStyle($Toolbar, $TBSTYLE_EX_DOUBLEBUFFER)
_GUICtrlToolbar_AddButton($Toolbar, $Add, -2, _GUICtrlToolbar_AddString($Toolbar, "控制"), $BTNS_DROPDOWN + $BTNS_WHOLEDROPDOWN)
_GUICtrlToolbar_AddButton($Toolbar, $Page, -2, _GUICtrlToolbar_AddString($Toolbar, "页数"), $BTNS_DROPDOWN + $BTNS_WHOLEDROPDOWN)
_GUICtrlToolbar_AddButton($Toolbar, $Exit, -2, _GUICtrlToolbar_AddString($Toolbar, "退出"))
GUISetState(@SW_SHOWNOACTIVATE, $ToolbarGui)
GUISetState(@SW_SHOW, $Form1)
#endregion
GUIRegisterMsg(0x0111, "WM_COMMAND")
GUIRegisterMsg(0x004E, "WM_NOTIFY")
While 1
Sleep(100)
WEnd
Func GuiClick()
Switch @GUI_CtrlId
Case -3
Exit
EndSwitch
EndFunc ;==>GuiClick
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Switch $iwParam
Case $AddFile
$s_add_file = FileOpenDialog("请选择文件", "", "文件(*.*)", 7)
If Not @error Then
WinSetTitle($Form1, "", $Title & " 正在处理数据,请稍后……")
If StringInStr($s_add_file, "|") <> 0 Then
$s_add_file = StringSplit($s_add_file, "|")
If StringRight($s_add_file[1], 1) <> "\" Then $s_add_file[1] &= "\"
For $i = 2 To $s_add_file[0]
WinSetTitle($Form1, "", $Title & " 正在处理数据,请稍后…… 已完成" & Round($i * 100 / $s_add_file[0], 2) & "%")
_ArrayAdd($add_file, $s_add_file[1] & $s_add_file[$i])
Next
$pagenum = Floor((UBound($add_file) - 2) / 20) + 1
EndIf
_work()
WinSetTitle($Form1, "", $Title)
EndIf
Case $AddFolder
$add_dir = FileSelectFolder("请选择歌曲目录", "")
If Not @error Then
WinSetTitle($Form1, "", $Title & " 正在处理数据,请稍后……")
myFileListToArray($add_dir, "*")
_work()
WinSetTitle($Form1, "", $Title)
EndIf
WinActivate($Form1)
Case $DelFile
$Index = _GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($ListView1))
If Not StringLen($Index) Then Return
_ArrayDelete($add_file, 20 * ($pageselect - 1) + $Index + 1)
_work()
WinActivate($Form1)
Case $Exit
Exit
Case $pagemode[0] To $pagemode[UBound($pagemode) - 1]
$pageselect = Number(StringFormat("%g\n", String($iwParam - 1399)))
_work()
WinActivate($Form1)
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_COMMAND
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $Toolbar
If $iCode = $TBN_DROPDOWN Then
If _GUICtrlToolbar_IsButtonPressed($Toolbar, $Add) Then
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem($hMenu, "添加文件", $AddFile)
_GUICtrlMenu_AddMenuItem($hMenu, "添加目录", $AddFolder)
_GUICtrlMenu_AddMenuItem($hMenu, "删除文件", $DelFile)
_GUICtrlMenu_TrackPopupMenu($hMenu, $ToolbarGui, -1, -1, 1)
_GUICtrlMenu_DestroyMenu($hMenu)
ElseIf _GUICtrlToolbar_IsButtonPressed($Toolbar, $Page) Then
$hMenu = _GUICtrlMenu_CreatePopup()
ReDim $pagemode[$pagenum]
For $i = 1 To UBound($pagemode)
$pagemode[$i - 1] = 1399 + $i
_GUICtrlMenu_AddMenuItem($hMenu, "第" & $i & "页", $pagemode[$i - 1])
Next
_GUICtrlMenu_SetItemState($hMenu, $pageselect - 1, $MFS_CHECKED)
_GUICtrlMenu_TrackPopupMenu($hMenu, $ToolbarGui, -1, -1, 1)
_GUICtrlMenu_DestroyMenu($hMenu)
EndIf
EndIf
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_NOTIFY
Func myFileListToArray($s_dir, $s_file)
If StringRight($s_dir, 1) = "\" And StringRight($s_dir, 2) <> ":\" Then $s_dir = StringTrimRight($s_dir, 1)
Local $i_step = 999999
Local $s_add_file[$i_step + 1]
Local $i_count = 1
Local $a_dir[$i_step + 1]
$a_dir[0] = 1
$a_dir[1] = $s_dir
$i_dirCount = 1
Local $a_dir_temp, $isdir, $a_temp
Local $file, $search
While $a_dir[0] <= $i_dirCount
WinSetTitle($Form1, "", $Title & " 正在处理数据,请稍后…… 已完成" & Round($a_dir[0] * 100 / $i_dirCount, 2) & "%")
$s_dir = $a_dir[$a_dir[0]]
$a_dir_temp = __FileListToArray($s_dir, "*", 2)
If UBound($a_dir_temp) > 1 Then
If $i_dirCount + $a_dir_temp[0] > UBound($a_dir) - 1 Then ReDim $a_dir[UBound($a_dir) + $a_dir_temp[0] + $i_step]
For $i = 1 To UBound($a_dir_temp) - 1
$a_dir[$i_dirCount + $i] = $s_dir & "\" & $a_dir_temp[$i]
Next
$i_dirCount += $a_dir_temp[0]
EndIf
$a_dir_temp = __FileListToArray($s_dir, $s_file)
If UBound($a_dir_temp) > 1 Then
If $i_count + $a_dir_temp[0] > UBound($s_add_file) - 1 Then ReDim $s_add_file[UBound($s_add_file) + $a_dir_temp[0] + $i_step]
For $i = 1 To UBound($a_dir_temp) - 1
$s_add_file[$i_count] = $s_dir & "\" & $a_dir_temp[$i]
$i_count += 1
Next
EndIf
$a_dir[0] += 1
WEnd
WinSetTitle($Form1, "", $Title & " 正在生成数据,请稍后……")
For $i = 1 To $i_count - 1
WinSetTitle($Form1, "", $Title & " 正在生成数据,请稍后…… 已完成" & Round($i * 100 / ($i_count - 1), 2) & "%")
_ArrayAdd($add_file, $s_add_file[$i])
Next
ReDim $s_add_file[1]
$pagenum = Floor((UBound($add_file) - 2) / 20) + 1
EndFunc ;==>myFileListToArray
Func __FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
Local $hSearch, $sFile, $sFileList, $sDelim = "|"
$sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "\"
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
$hSearch = FileFindFirstFile($sPath & $sFilter)
If @error Then Return SetError(4, 4, "")
While 1
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
If ($iFlag + @extended = 2) Then ContinueLoop
$sFileList &= $sDelim & $sFile
WEnd
FileClose($hSearch)
If Not $sFileList Then Return SetError(4, 4, "")
Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc ;==>__FileListToArray
Func _work()
Local $endwork = 20 * $pageselect
If $endwork > UBound($add_file) - 1 Then $endwork = UBound($add_file) - 1
_GUICtrlListView_BeginUpdate($ListView1)
_GUICtrlListView_DeleteAllItems($ListView1)
For $i = 1 + 20 * ($pageselect - 1) To $endwork
GUICtrlCreateListViewItem(StringRegExpReplace(_WinAPI_PathFindFileName($add_file[$i]), "\.[^\.]+$", "") & "|" & StringRegExpReplace($add_file[$i], "\\[^\\]+$", "") & _
"|" & StringRegExpReplace(_WinAPI_PathFindFileName($add_file[$i]), ".+\.", ""), $ListView1)
Next
_GUICtrlListView_EndUpdate($ListView1)
EndFunc ;==>_work
|