如果你對(duì)windows7庫(kù)的概念不了解,請(qǐng)先看這篇介紹:Windows 7新功能:庫(kù)(Library) 以下是一些常見的Windows 7庫(kù)功能的一個(gè)快速參考,,使用了Windows API Code Pack,。 這篇文章中的代碼來(lái)自Alon和Sela工作小組的成員,。 每個(gè)Windows 7庫(kù)用一個(gè)XML文件表示,,擴(kuò)展名為.library-ms,。 通用庫(kù)文件通常存儲(chǔ)在:C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Libraries\,。 例如,我們現(xiàn)在使用圖片庫(kù),,如以下代碼: 1 libraryName = Pictures 2 locationPath = C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Libraries\ 注意:您可以在任何地方創(chuàng)建庫(kù)文件,,不一定是在上述文件夾中。 功能: 創(chuàng)建一個(gè)新庫(kù): 1 ShellLibrary shellLibrary = 2 new ShellLibrary(libraryName, locationPath, overwriteExisting); 添加文件夾到現(xiàn)有庫(kù): 1 using (ShellLibrary shellLibrary = 2 ShellLibrary.Load(libraryName, folderPath, isReadOnly)) 3 { 4 shellLibrary.Add(folderToAdd); 5 } 從庫(kù)中刪除文件夾: 1 using (ShellLibrary shellLibrary = 2 ShellLibrary.Load(libraryName, folderPath, isReadOnly)) 3 { 4 shellLibrary.Remove(folderToRemove); 5 } 枚舉庫(kù)文件夾: 1 using (ShellLibrary shellLibrary = 2 ShellLibrary.Load(libraryName, folderPath, isReadOnly)) 3 { 4 foreach (ShellFileSystemFolder folder in shellLibrary) 5 { 6 Debug.WriteLine(folder.Path); 7 } 8 } 更改默認(rèn)保存位置: 1 using (ShellLibrary shellLibrary = 2 ShellLibrary.Load(libraryName, folderPath, isReadOnly)) 3 { 4 shellLibrary.DefaultSaveFolder = newSaveLocation; 5 } 更改庫(kù)圖標(biāo): 1 using (ShellLibrary shellLibrary = 2 ShellLibrary.Load(libraryName, folderPath, isReadOnly)) 3 { 4 shellLibrary.IconResourceId = new IconReference(moduleName, resourceId); 5 } 鎖住庫(kù)瀏覽導(dǎo)航窗格: 1 using (ShellLibrary shellLibrary = 2 ShellLibrary.Load(libraryName, folderPath, isReadOnly)) 3 { 4 shellLibrary.IsPinnedToNavigationPane = true; 5 } 設(shè)置庫(kù)的類型: 1 using (ShellLibrary shellLibrary = 2 ShellLibrary.Load(libraryName, folderPath, isReadOnly)) 3 { 4 shellLibrary.LibraryType = libraryType; 5 6 // libraryType can be: 7 // LibraryFolderType.Generic 8 // LibraryFolderType.Documents 9 // LibraryFolderType.Music 10 // LibraryFolderType.Pictures 11 // LibraryFolderType.Videos 12 } 打開庫(kù)管理界面: 1 ShellLibrary.ShowManageLibraryUI( 2 libraryName, folderPath, hOwnerWnd, title, instruction, allowNonIndexableLocations); 刪除庫(kù): 1 string FileExtension = ".library-ms"; 2 3 File.Delete(Path.Combine(folderPath,libraryName + FileExtension)); 獲取庫(kù)的更改通知: 1 string FileExtension = ".library-ms"; 2 3 FileSystemWatcher libraryWatcher = new FileSystemWatcher(folderPath); 4 libraryWatcher.NotifyFilter = NotifyFilters.LastWrite; 5 libraryWatcher.Filter = libraryName + FileExtension; 6 libraryWatcher.IncludeSubdirectories = false; 7 8 libraryWatcher.Changed += (s, e) => 9 { 10 //cross thread call 11 this.Dispatcher.Invoke(new Action(() => 12 { 13 using (ShellLibrary shellLibrary = 14 ShellLibrary.Load(libraryName, folderPath, isReadOnly)) 15 { 16 // get changed information 17 ... 18 } 19 })); 20 }; 21 libraryWatcher.EnableRaisingEvents = true; 原文:http://blogs./blogs/arik/archive/2010/03/15/windows-7-libraries-c-quick-reference.aspx 作者:朱祁林 出處:http://zhuqil.cnblogs.com 本文版權(quán)歸作者和博客園共有,,歡迎轉(zhuǎn)載,,但未經(jīng)作者同意必須保留此段聲明,且在文章頁(yè)面明顯位置給出原文連接,,否則保留追究法律責(zé)任的權(quán)利,。 |
|
來(lái)自: caodaoquan > 《地法》