Captura:
Código: Seleccionar todo
#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GuiStatusBar.au3>
#include <WinAPIShellEx.au3>
#RequireAdmin
Opt("MustDeclareVars",1)
Global $oListView, $hListView, $State, $oStatus, $hGUI, $oCheck[3], $sPart = "S|H|R|", $oLabel
Global $sRuta = @ScriptDir & "\"
Main()
Func Main()
$hGUI = GUICreate("File Attributes", 420, 420)
$oListView = GUICtrlCreateListView("Archive/Directory|Attributes", 2, 2, 414, 268, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
$hListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetExtendedListViewStyle($oListView, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth($oListView, 0, 320)
_GUICtrlListView_SetColumnWidth($oListView, 1, 90)
$oStatus = _GUICtrlStatusBar_Create($hGUI)
_GUICtrlStatusBar_SetSimple($oStatus, True)
Local $oGroup = GUICtrlCreateGroup("Check/UnCheck", 20, 295, 220, 90)
$oCheck[0] = GUICtrlCreateCheckbox("System", 30, 310)
GUICtrlSetState(-1, $GUI_CHECKED)
$oCheck[1] = GUICtrlCreateCheckbox("Hidden", 30, 330)
GUICtrlSetState(-1, $GUI_CHECKED)
$oCheck[2] = GUICtrlCreateCheckbox("Read-only", 30, 350)
GUICtrlSetState(-1, $GUI_CHECKED)
Local $oContextmenu = GUICtrlCreateContextMenu($oListView)
Local $idMenuCheck = GUICtrlCreateMenuItem("Check", $oContextmenu)
Local $idMenuUnCheck = GUICtrlCreateMenuItem("UnCheck", $oContextmenu)
Local $idMenuOpen = GUICtrlCreateMenuItem("Open in Folder", $oContextmenu)
Local $idMenuUnSet = GUICtrlCreateMenuItem("Set -HSR", $oContextmenu)
Local $idMenuSet = GUICtrlCreateMenuItem("Set +HSR", $oContextmenu)
Local $obCheck = GUICtrlCreateButton("Check", 150, 305, 80, 30)
Local $obUnCheck = GUICtrlCreateButton("UnCheck", 150, 345, 80, 30)
Local $oSet = GUICtrlCreateButton("Reset Attributes", 290, 305, 90, 70)
$oLabel = GUICtrlCreateLabel("Current Path:", 6, 275, 400, 20)
GUICtrlSetColor(-1, 0xC0C0C3)
GUICtrlSetTip(-1, "Click to Change Current Path")
GUICtrlSetData($oLabel, "Current Path: " & $sRuta)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)
List()
Local $aPart[] = ["S|", "H|", "R|"]
Local $iIndex = 0
Local $nMsg=0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $obCheck
Check()
Case $oCheck[0] To $oCheck[2]
$iIndex = $nMsg - 5
If StringInStr($sPart, $aPart[$iIndex]) Then
$sPart = StringReplace($sPart, $aPart[$iIndex], "")
Else
$sPart &= $aPart[$iIndex]
EndIf
;~ ConsoleWrite($sPart & @CRLF)
Case $obUnCheck
UnCheck()
Case $oSet
_GUICtrlStatusBar_SetText($oStatus, "Please Wait...")
ResetAt()
List()
_GUICtrlStatusBar_SetText($oStatus, "Already.")
Case $idMenuCheck
CheckSlection()
Case $idMenuUnCheck
UnCheckSlection()
Case $idMenuOpen
OpeninFolder($sRuta & _GUICtrlListView_GetItemText($hListView, _GUICtrlListView_GetSelectionMark($oListView)))
Case $idMenuSet
SetHSR()
Case $idMenuUnSet
UnSetHSR()
Case $oLabel
ChangePath()
EndSwitch
WEnd
GUIDelete()
EndFunc ;==>Main
Func ChangePath()
Local $sFileSelectFolder = FileSelectFolder("Select a Path", "")
If $sFileSelectFolder <> "" and FileExists($sFileSelectFolder) Then
$sRuta = $sFileSelectFolder & "\"
GUICtrlSetData($oLabel, "Current Path: " & $sRuta)
List()
EndIf
EndFunc ;==>ChangePath
Func OpeninFolder($Path)
_WinAPI_ShellOpenFolderAndSelectItems($Path)
EndFunc ;==>OpeninFolder
Func UnSetHSR()
Local $aSelection = _GUICtrlListView_GetSelectedIndices($oListView, True)
For $i = 1 To $aSelection[0]
FileSetAttrib($sRuta & _GUICtrlListView_GetItemText($hListView, $aSelection[$i]), "-HSR", 1)
Next
List()
EndFunc ;==>UnSetHSR
Func SetHSR()
Local $aSelection = _GUICtrlListView_GetSelectedIndices($oListView, True)
For $i = 1 To $aSelection[0]
FileSetAttrib($sRuta & _GUICtrlListView_GetItemText($hListView, $aSelection[$i]), "+HSR", 1)
Next
List()
EndFunc ;==>SetHSR
Func CheckSlection()
Local $aSelection = _GUICtrlListView_GetSelectedIndices($oListView, True)
;~ _ArrayDisplay($aSelection)
For $i = 1 To $aSelection[0]
_GUICtrlListView_SetItemChecked($oListView, $aSelection[$i])
Next
EndFunc ;==>CheckSlection
Func UnCheckSlection()
Local $aSelection = _GUICtrlListView_GetSelectedIndices($oListView, True)
;~ _ArrayDisplay($aSelection)
For $i = 1 To $aSelection[0]
_GUICtrlListView_SetItemChecked($oListView, $aSelection[$i], False)
Next
EndFunc ;==>UnCheckSlection
Func Check()
If $sPart <> "" Then
For $i = 0 To _GUICtrlListView_GetItemCount($oListView)
If StringRegExp(_GUICtrlListView_GetItemText($oListView, $i, 1), StringLeft($sPart, StringLen($sPart) - 1)) Then
ConsoleWrite(_GUICtrlListView_GetItemText($oListView, $i, 1) & @CRLF)
_GUICtrlListView_SetItemChecked($oListView, $i, True)
EndIf
Next
EndIf
EndFunc ;==>Check
Func UnCheck()
If $sPart <> "" Then
For $i = 0 To _GUICtrlListView_GetItemCount($oListView)
If StringRegExp(_GUICtrlListView_GetItemText($oListView, $i, 1), StringLeft($sPart, StringLen($sPart) - 1)) Then
ConsoleWrite(_GUICtrlListView_GetItemText($oListView, $i, 1) & @CRLF)
_GUICtrlListView_SetItemChecked($oListView, $i, False)
EndIf
Next
EndIf
EndFunc ;==>UnCheck
Func ResetAt()
Local $sFilePath = ""
If $sPart <> "" Then
For $i = 0 To _GUICtrlListView_GetItemCount($oListView)
If _GUICtrlListView_GetItemChecked($oListView, $i) Then
$sFilePath = $sRuta & _GUICtrlListView_GetItemText($oListView, $i, 0)
FileSetAttrib($sFilePath, "-HSR", 1)
ConsoleWrite($sFilePath & @CRLF)
EndIf
Next
EndIf
EndFunc ;==>ResetAt
Func List()
Local $aFiles = _FileListToArray($sRuta)
_GUICtrlStatusBar_SetText($oStatus, "Loading...")
_GUICtrlListView_DeleteAllItems($oListView)
_GUICtrlListView_BeginUpdate($oListView)
For $i = 1 To $aFiles[0]
_GUICtrlListView_AddItem($oListView, $aFiles[$i])
_GUICtrlListView_AddSubItem($oListView, $i - 1, FileGetAttrib($sRuta & $aFiles[$i]), 1)
Next
_GUICtrlListView_EndUpdate($oListView)
_GUICtrlStatusBar_SetText($oStatus, "Already...")
EndFunc ;==>List
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $tNMHDR, $hWndFrom, $IDFrom, $Code, $tNMLISTVIEW, $iItem, $sItem
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$Code = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListView
Switch $Code
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iColor, $hDC
$sItem = _GUICtrlListView_GetItemText($oListView, $iItem, 1)
If $sItem Then
If StringInStr($sItem, "S") Or StringInStr($sItem, "H") Then
$iColor = RGB2BGR(0xFF8282)
DllStructSetData($tCustDraw, "clrTextBk", $iColor)
Return $CDRF_NEWFONT
Else
$iColor = RGB2BGR(0x35FF9A)
DllStructSetData($tCustDraw, "clrTextBk", $iColor)
Return $CDRF_NEWFONT
EndIf
EndIf
Case $LVN_HOTTRACK
Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
Local $iItem = DllStructGetData($tInfo, "Item"), $iSubItem = DllStructGetData($tInfo, "SubItem")
If Not ($iItem = -1 Or $iSubItem = -1) Then
_GUICtrlStatusBar_SetText($oStatus, AttributeToString(_GUICtrlListView_GetItemText($oListView, $iItem, 1)))
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR
Func AttributeToString($sAttribute)
; Create a 1d array of the file attribute letters by splitting the string at the comma (,).
Local $aInput = StringSplit("R,A,S,H,N,D,O,C,T", ",")
; Create a 1d array using the friendlier file attribute names by splitting the string at the comma (,).
Local $aOutput = StringSplit("Read-only /, Archive /, System /, Hidden /" & _
", Normal /, Directory /, Offline /, Compressed /, Temporary /", ",")
; Loop through the attribute letters array to replace with the friendlier value e.g. A becomes Archive or S becomes System.
For $i = 1 To $aInput[0]
$sAttribute = StringReplace($sAttribute, $aInput[$i], $aOutput[$i], 0, $STR_CASESENSE)
Next
; Remove the single space and trailing forward slash.
$sAttribute = StringTrimRight($sAttribute, 2)
; Return the attribute string.
Return $sAttribute
EndFunc ;==>AttributeToString