Jump Lists allows users to quickly and easily find the files they want to browse (documents, pictures, audio or video, etc.), as well as links or shortcuts to the application. Take the IE browser as an example to see what the jump Lists is capable of:
Taskbar tasks places some of the default tasks for the application: "Open IE Browser", "Unpin from taskbar", "Close Program". Whether or not the jump Lists has been developed, the taskbar Tasks list will appear in all applications.
User Tasks contains some of the features provided by the application itself that allow you to manipulate the application directly. For example, open a new IE tag.
"Known category" This list is the Windows 7 default category, which contains three modes: "Recent" (recent browsing), "frequent" (frequent browsing), "neither". Its function is to record frequently viewed Web pages so that they can be browsed again later, and as time goes by, the links to the pages in the list will change or disappear. In addition to the "known category" list, you also create a "Custom category" (which will be mentioned later).
"Pinned category" as the above-mentioned "frequent category" list of the page will change frequently, by right-clicking on the page "nail" in the list to make it permanent save.
Create a user Tasks list
Now you want to add a JL to your program, let's start by creating the user Tasks list.
1. Create a JL instance from the JumpList class.
2. Using the jumplistlink(String pathvalue, String Titlevalue) method (Pathvalue: Application path, Titlevalue: Link name), you can use Notepad, artboard Such Windows applications, as well as "site addresses", are created as user Tasks links.
3. Use the addusertasks(params ijumplisttask[] tasks) method to add these links to the JL. As shown in the following code:
Private JumpList _jumplist;
_jumplist = Jumplist.createjumplistforindividualwindow ("Windows.TaskBar.WinFormJumpList", this. Handle);
<summary>///Add user Tasks///</summary> private void Addusertasks () { String systempath = Environment.getfolderpath (Environment.SpecialFolder.System); Program link Jumplisttask notepadtask = new Jumplistlink (Path.Combine (Systempath, "notepad.exe"), "notepad") {iconreference = new Iconreference (Path.Combine (Systempath, "notepad.exe"), 0)}; Jumplisttask painttask = new Jumplistlink (Path.Combine (Systempath, "MSPaint.exe"), "Paint") { Iconreference = new Iconreference (Path.Combine (Systempath, "MSPaint.exe"), 0)}; Split Line Jumplisttask jlseparator = new Jumplistseparator (); Jumplisttask linktask = new Jumplistlink ("http://blog.csdn.net/aoshilang2249", "Langya ' s Blog") { Iconreference = new Iconreference ("C:\\Program files\\internet Explorer\\iexplore.exe", 0)}; Add User Tasks _jumplist.addusertasks (Notepadtask, Painttask, Jlseparator, Linktask); Refresh the jumpList _jumplist.refresh (); }
In the above program, "Program Link" (Jumplistlink, iconreference as link icon) and "Split Line" (Jumplistseparator) are created through the Jumplisttask interface; use Addusertasks method, note the location relationship of each link, and finally you must refresh the JL to display the latest JL content.
Create known Category list
Before using the known category feature, you need to register the file type for the program, which can then be preset by the Knowncategorytodisplay property to "recent", "frequent", " Neither, when a test program opens a file, the corresponding file link is displayed in the known Category list. As shown in the following code:
File association Registration helper classes:
Using system;using system.collections.generic;using system.text;using system.diagnostics;using System.IO;using System.windows.forms;using system.componentmodel;using microsoft.win32;namespace LangYa.Net.Utils.File{//< summary>///Registration file The auxiliary class for the application associated with////</summary> public class Fileassociationshelper {private stat IC RegistryKey classesroot; The root directory of the registry is private static void Process (string[] args) {if (args. Length < 6) {string error = ("Usage: <ProgId> <register in Hkcu:true|false> < ; appid> <OpenWithSwitch> <Unregister:true|false> <Ext1> [Ext2 [Ext3] ...]; throw new ArgumentException (error); } try {string progId = Args[0]; BOOL REGISTERINHKCU = bool. Parse (Args[1]); String appId = Args[2]; String openwith = Args[3]; BOOL Unregister = bool. Parse (Args[4]); list<string> argList = new list<string> (); for (int i = 5; i < args. Length; i++) {Arglist.add (args[i]); } string[] Associationstoregister = Arglist.toarray (); File list if (REGISTERINHKCU) {classesroot = Registry.CurrentUser.OpenSubK EY (@ "software\classes"); } else {classesroot = Registry.classesroot; }//Logoff Array.foreach (associationstoregister, assoc = unregisterfileassociation (ProgId, Assoc)); Unregisterprogid (PROGID); Register if (!unregister) {Registerprogid (progId, AppId, Openwith); Array.foreach (associationstoregister, assoc = registerfileassociation (progId, Assoc)); }} catch (Exception e) {}}/// <summary>///Registration class Identifier///</summary>//<param name= "ProgId" > class identifier </param> <param name= "AppId" > Application id</param>//<param name= "Openwith" > Open file Process full path </param> private static void Registerprogid (String progId, String appId, String openwith) {RegistryKey Pro Gidkey = Classesroot.createsubkey (progId); Progidkey.setvalue ("Friendlytypename", "@shell32. dll,-8975"); Progidkey.setvalue ("DefaultIcon", "@shell32. dll,-47"); Progidkey.setvalue ("Curver", progId); Progidkey.setvalue ("Appusermodelid", appId); RegistryKey shell = Progidkey.createsubkey ("Shell"); Shell. SetValue (String.Empty, "Open"); Shell = Shell. CreateSubKey ("Open"); Shell = Shell. CreateSubKey ("Command"); ShelL.setvalue (String.Empty, Openwith + "%1"); '%1 ' means that the path to the file being double-clicked is passed to the target application shell. Close (); Progidkey.close (); }///<summary>//Logoff class identifier///</summary>//<param name= "ProgId" > class identifier </ param> private static void Unregisterprogid (string progId) {try {C Lassesroot.deletesubkeytree (PROGID); } catch {}}//<summary>//Registration file association///</summary> Private St atic void Registerfileassociation (string progId, String extension) {RegistryKey Openwithkey = Classesro Ot. CreateSubKey (path.combine (extension, "openwithprogids")); Openwithkey.setvalue (ProgId, String.Empty); Openwithkey.close (); }///<summary>//Unregister file association///</summary> private static void Unregisterfileassoci ation (string progId, String extension) { try {RegistryKey Openwithkey = Classesroot.createsubkey (path.combine (extension, "Openw Ithprogids ")); Openwithkey.deletevalue (PROGID); Openwithkey.close (); } catch (Exception e) {}}//<summary>// Class identifier registration operation///</summary>//<param name= "unregister" > Registration or deregistration </param>//<param NA Me= "ProgId" > Class Identifiers </param>//<param name= "REGISTERINHKCU" > whether to register file associations in HKCU--false</param> <param name= "AppId" > Application id</param>//<param name= "Openwith" > Open file Process full path </param> <param name= "Extensions" > file association list </param> private static void Internalregisterfileassociations (bo OL unregister, String progId, bool registerinhkcu,string AppI D, String Openwith, String[] extensions) {string Arguments = string. Format ("{0} {1} {2} \" {3}\ "{4} {5}", ProgId,//0 REGISTERINHKCU,//1 appId,//2 Openwith, unregister, String. Join ("", extensions)); try {Process (Arguments.split (')); } catch (Win32Exception e) {if (E.nativeerrorcode = = 1223)//1223: User action is canceled. {//The operation has been canceled by the user}} }///<summary>///Determine if the class identifier is registered///</summary>//<param name= ' progId ' > class identifier & lt;/param>//<returns> registered for return true</returns> public static bool Isapplicationregistered (string progId) {return (Registry.ClassesRoot.OpenSubKey (pro GID) = null); }///<summary>///Registration Class Identifier file association///</summary>//<param name= "ProgId" > class identifier </param>//<param name= "REGISTERINHKCU" > whether to register file associations in HKCU-false///<param Name= "AppId" > Application id</param>//<param name= "Openwith" > Open file Process full path </param>//<param name= "extension S "> File association list </param> public static void Registerfileassociations (String progid,bool REGISTERINHKCU, string AP PId, String openwith, params string[] extensions) {I Nternalregisterfileassociations (False, ProgId, REGISTERINHKCU, appId, Openwith, extensions); }///<summary>//Unregister the file association for the class identifier///</summary>//<param name= "ProgId" > class identifier </param>///<param name= "REGISTERINHKCU" > whether to register file associations in HKCU-false///<param Name= "AppId" > Application id</param> <param name= "Openwith" > Open file Process full path </param>//<param name= "Extensions" > file association list </PARAM&G T public static void Unregisterfileassociations (string progId, bool REGISTERINHKCU, String appId, String Openwith, params string[] extensions) {Internalregisterfileassociatio NS (True, ProgId, REGISTERINHKCU, appId, Openwith, extensions); } }}
<summary>///add known tasks///</summary>private void Addknowntasks (Jumplistknowncategorytype Knowstype, int knowncategoryordinalposition) { _jumplist.knowncategorytodisplay = knowstype; _jumplist.knowncategoryordinalposition = knowncategoryordinalposition;//relative to the location of the custom if (! Fileassociationshelper.isapplicationregistered (TaskbarManager.Instance.ApplicationId)) { Fileassociationshelper.registerfileassociations (TaskbarManager.Instance.ApplicationId, false, TaskbarManager.Instance.ApplicationId, assembly.getexecutingassembly (). Location, ". jpg", ". png", ". gif", ". JPG ",". PNG ",". GIF "); _jumplist.refresh ();}
In order for the file to open normally, you also need to modify the main method so that the bridging path can be passed in to the application to open the file associated with the application:
<summary>///The main entry point of the application. </summary>[stathread]static void Main (string[] args) { string filePath = ""; if ((args! = null) && (args. Length > 0)) {for (int i = 0; i < args. Length; i++) { //for the path between the spaces will be automatically split into multiple parameters FilePath + = "" + args[i]; } Filepath.trim (); } Application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); Application.Run (New Main () {FilePath = FilePath});}
<summary>///application file ///</summary>public string filepath{get {return (_strfilepath);} Set { _strfilepath = value; if (!string. IsNullOrEmpty (_strfilepath)) { _picturebox.imagelocation = _strfilepath; }} }
Create a custom Category list
Like the way you created jumplist above:
1. Create a custom classification list instance from the Jumplistcustomcategory class.
2. Name the list by the Jumplistcustomcategory (string CategoryName) method.
3. Use the Addjumplistitems method to add links to the taxonomy. As shown in the following code:
<summary>///Add custom tasks///</summary>private void Addcustomtasks (String categoryname) { if ( Categoryname.length > 0) { jumplistcustomcategory customcategory = new Jumplistcustomcategory ( CategoryName); _jumplist.addcustomcategories (customcategory); Arguments the parameters of the file type that need to be opened (such as file path, etc.) jumplistlink jlitem = new Jumplistlink (assembly.getexecutingassembly (). Location, "chrysanthemum.jpg") { iconreference = new Iconreference (assembly.getentryassembly (). Location, 0), Arguments = @ "C:\Users\Public\Pictures\Sample pictures\chrysanthemum.jpg" }; Customcategory.addjumplistitems (Jlitem); _jumplist.refresh (); }}
C # Windows 7 Taskbar development Jump List (Lists)