VERSION 5.00
Object = "{6B7Ee'92-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX" Begin VB.Form fmDelRecent BorderStyle =1 'Fixed Single Caption ="Selektives Löschen der ""Recently Used"" Dateien" ClientHeight=3045 ClientLeft =45 ClientTop=330 ClientWidth =7680 LinkTopic="Form1" MaxButton=0'False MinButton=0'False ScaleHeight =3045 ScaleWidth =7680 StartUpPosition =1 'CenterOwner Begin VB.PictureBox picLarge Height =495 Left=6000 ScaleHeight =435 ScaleWidth =435 TabIndex=6 Top =4080 Width=495 End Begin VB.PictureBox picSmall Height =495 Left=5280 ScaleHeight =435 ScaleWidth =435 TabIndex=5 Top =4080 Width=495 End Begin ComctlLib.ListView lvFiles Height =2775 Left=120 TabIndex=4 Top =120 Width=4935 _ExtentX=8705 _ExtentY=4895 View=1 Arrange =1 LabelEdit=1 MultiSelect =-1 'True LabelWrap=0'False HideSelection=0'False HideColumnHeaders=-1 'True _Version=327682 ForeColor=-2147483640 BackColor=-2147483643 BorderStyle =1 Appearance =1 BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name="MS Sans Serif" Size=9.75 Charset =0 Weight =400 Underline=0'False Italic =0'False Strikethrough=0'False EndProperty NumItems=0 End Begin VB.CommandButton pbRefresh Caption ="Aktualisieren" Height =375 Left=5160 TabIndex=3 Top =2520 Width=2415 End Begin VB.CommandButton pbSel Caption ="Selektierte Dateien löschen" Enabled =0'False Height =375 Left=5160 TabIndex=2 Top =600 Width=2415 End Begin VB.CommandButton pbAll Caption ="Alle Dateien löschen" Height =375 Left=5160 TabIndex=1 Top =120 Width=2415 End Begin VB.FileListBox fiBox Height =870 Left=0 MultiSelect =2 'Extended TabIndex=0 Top =3360 Width=4935 End Begin ComctlLib.ImageList ilSmall Left=5880 Top =3360 _ExtentX=1005 _ExtentY=1005 BackColor=-2147483643 MaskColor=12e'2256 _Version=327682 End Begin ComctlLib.ImageList ilList Left=5160 Top =3360 _ExtentX=1005 _ExtentY=1005 BackColor=-2147483643 ImageWidth =32 ImageHeight =32 MaskColor=12e'2256 _Version=327682 End End Attribute VB_Name = "fmDelRecent" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Const S_OK = &H0 Private Const CSIDL_RECENT = &H8 Private Const LARGE_ICON As Integer = 32 Private Const SMALL_ICON As Integer = 16 Private Const DI_NORMAL = 3 Private Const MAX_PATH = 260 Private Const SHGFI_DISPLAYNAME = &H200 Private Const SHGFI_EXETYPE = &H2000 Private Const SHGFI_SYSICONINDEX = &H4000 ' System icon index Private Const SHGFI_LARGEICON = &H0' Large icon Private Const SHGFI_SMALLICON = &H1' Small icon Private Const ILD_TRANSPARENT = &H1' Display transparent Private Const SHGFI_SHELLICONSIZE = &H4 Private Const SHGFI_TYPENAME = &H400 Private Const BASIC_SHGFI_FLAGS = SHGFI_TYPENAME _ Or SHGFI_SHELLICONSIZE Or SHGFI_SYSICONINDEX _ Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE Private Type SHFILEINFO hIcon As Long iIcon As Long dwAttributes As Long szDisplayName As String * MAX_PATH szTypeName As String * 80 End Type Private Declare Sub SHAddToRecentDocs Lib "Shell32" _ (ByVal lFlags As Long, ByVal lPv As Any) Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" _ (ByVal hwndOwner As Long, ByVal nFolder As Long, _ lpMem As Long) As Long Private Declare Function SHGetFolderPath Lib "SHFolder" _ Alias "SHGetFolderPathA"(ByVal hwndOwner As Long, _ ByVal nFolder As Long,ByVal hToken As Long, _ ByVal dwFlags As Long,ByVal sPath As String) As Long Private Declare Function ExtractIcon Lib "shell32.dll" _ Alias "ExtractIconA" (ByVal hInst As Long, _ ByVal lpszExeFileName As String, _ ByVal nIconIndex As Long) As Long Private Declare Function FindExecutable Lib "shell32.dll" _ Alias "FindExecutableA" (ByVal lpFile As String, _ ByVal lpDirectory As String, _ ByVal lpResult As String) As Long Private Declare Function DrawIconEx Lib "user32" _ (ByVal hdc As Long, ByVal xLeft As Long, _ ByVal yTop As Long,ByVal hIcon As Long, _ ByVal cxWidth As Long, ByVal cyWidth As Long, _ ByVal istepIfAniCur As Long, _ ByVal hbrFlickerFreeDraw As Long, _ ByVal diFlags As Long) As Long Private Declare Function ExtractIconEx Lib "shell32.dll" _ Alias "ExtractIconExA" (ByVal lpszFile As String, _ ByVal nIconIndex As Long, phiconLarge As Long, _ phiconSmall As Long, ByVal nIcons As Long) As Long Private Declare Function ExtractAssociatedIcon Lib _ "shell32.dll" Alias "ExtractAssociatedIconA" _ (ByVal hInst As Long, ByVal lpIconPath As String, _ lpiIcon As Long) As Long Private Declare Function SHGetFileInfo Lib "shell32.dll" _ Alias "SHGetFileInfoA" (ByVal pszPath As String, _ ByVal dwFileAttributes As Long,psfi As SHFILEINFO, _ ByVal cbSizeFileInfo As Long, _ ByVal uFlags As Long) As Long Private Declare Function ImageList_Draw Lib "comctl32.dll" _ (ByVal himl&, ByVal i&, ByVal hDCDest&, _ ByVal x&, ByVal y&, ByVal flags&) As Long Private Declare Sub Sleep Lib "kernel32" _ (ByVal dwMilliseconds As Long) ' var used by this form Private shinfo As SHFILEINFO Private FileNames() As String Private FileTypes() As String Private Sub GetAllIcons() Dim Index As Integer On Local Error Resume Next With fiBox ReDim FileNames(1 To .ListCount) ReDim FileTypes(1 To .ListCount) For Index = 0 To .ListCount - 1 GetIcon .Path + "\" + .List(Index), Index + 1 Next End With End Sub Private Function GetIcon(theName As String, _ Index As Integer) As Integer Dim hLIcon As Long, hSIcon As Long Dim imgObj As ListImage, r As Long hSIcon = SHGetFileInfo(theName, 0&, shinfo, Len(shinfo), _ BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON) hLIcon = SHGetFileInfo(theName, 0&, shinfo, Len(shinfo), _ BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON) If hLIcon <> 0 Then picLarge.Picture = LoadPicture("") With picLarge Set .Picture = LoadPicture("") .AutoRedraw = True r = ImageList_Draw(hLIcon, shinfo.iIcon, _ picLarge.hdc, 0, 0, ILD_TRANSPARENT) .Refresh End With With picSmall Set .Picture = LoadPicture("") .AutoRedraw = True r = ImageList_Draw(hSIcon, shinfo.iIcon, _ picSmall.hdc, 0, 0, ILD_TRANSPARENT) .Refresh End With Set imgObj = ilList.ListImages.Add(Index, , picLarge.Image) Set imgObj = ilSmall.ListImages.Add(Index, , picSmall.Image) ' remember info FileNames(Index) = Trim0(shinfo.szDisplayName) FileTypes(Index) = Trim0(theName) End If End Function Private Function GetRecentPath() As String Dim sPath As String * 255, l As Long GetRecentPath = "" If SHGetFolderPath(Me.hWnd, CSIDL_RECENT, 0&, 0&, sPath) = S_OK Then l = InStr(sPath, Chr$(0)) If (l > 0) And (l <= 255) Then _ GetRecentPath = Left$(sPath, l - 1) End If End Function Private Sub Init() On Local Error Resume Next picSmall.Width = (SMALL_ICON + 2) * Screen.TwipsPerPixelX picSmall.Height = (SMALL_ICON + 2) * Screen.TwipsPerPixelY picLarge.Width = LARGE_ICON * Screen.TwipsPerPixelX picLarge.Height = LARGE_ICON * Screen.TwipsPerPixelY ilList.ListImages.Clear ilSmall.ListImages.Clear lvFiles.Icons = Nothing lvFiles.SmallIcons = Nothing End Sub Private Sub KillFile(theName As String) On Local Error Resume Next Kill theName End Sub Private Function OneSelected() As Boolean Dim i As Integer OneSelected = False With lvFiles For i = 1 To .ListItems.Count If .ListItems(i).Selected Then OneSelected = True Exit Function End If Next End With End Function Private Sub ShowList(Count As Integer) Dim i As Integer, s As Object With lvFiles .ListItems.Clear .Icons = ilList .SmallIcons = ilSmall For i = 1 To Count .ListItems.Add , , FileNames(i), i, i '.ListItems.Add , , "Test", , i Next End With End Sub Private Function Trim0(ByVal Einstr As String) As String Dim i As Integer i = InStr(Einstr, Chr$(0)) If i <> 0 Then Trim0 = Left$(Einstr, i - 1) Else Trim0 = Einstr End If End Function Private Sub Form_Load() Dim s As String Init s = GetRecentPath If s <> "" Then fiBox.Path = s fiBox.Refresh If fiBox.ListCount = 0 Then pbAll.Enabled = False lvFiles.ListItems.Clear lvFiles.Refresh Else GetAllIcons ShowList fiBox.ListCount pbAll.Enabled = True End If Else MsgBox "Path To Recent Folder Not found!" End End If End Sub Private Sub lvFiles_Click() pbSel.Enabled = OneSelected End Sub Private Sub pbAll_Click() SHAddToRecentDocs 0&, 0& Sleep 500 pbRefresh_Click End Sub Private Sub pbRefresh_Click() Form_Load End Sub Private Sub pbSel_Click() Dim i As Integer For i = 1 To lvFiles.ListItems.Count If lvFiles.ListItems(i).Selected Then KillFile FileTypes(i) Next Sleep 500 pbSel.Enabled = False pbRefresh_Click End Sub Assumes: Paste the code into Notepad and save it as fmDelRecent.frm. Open an new project, add existing form To it (remove the default Form1) and make sure the startup form is Set to fmDelRecent. |