Jul
2
Developing for the Windows 7 Taskbar – Jump into Jump Lists – Part 3
Category: Vista News |
Leave a Comment
So far, you have seen how you can opt into the Windows 7 Taskbar Jump List experience by creating a Jump List for your application (in the Developing for the Windows 7 Taskbar – Jump into Jump Lists – Part 2 post.) You have also seen the Windows 7 default support for listing “Recent” or “Frequent” destinations as well as how to create your own custom categories. In this post, we will explore more of the Jump List features and discover how easy it is to add Tasks to your application's Jump List.
User tasks are customized tasks that get their own Tasks category. As a developer, you can set the title of the displayed task, the icon on the left and, more important, and the “application” that is launched once you activate this task. You can view user’s tasks as shortcuts to the functionality our applications can provide. As you might remember, user tasks are the verbs in our vocabulary; for example, Windows Media Player provides a “Resume last playlist” task and Sticky Notes provides a “New note” task.
A user task is usually an IShellLink object that launches any given application (your application or any other one you choose) with specific command line parameters. While you cannot categorize tasks, you can separate them using a special separator object. Here’s an example of a Jump List that uses a separator to split three tasks into a group of two plus an additional task:
So what does it take to add tasks to a Jump List? Well, not that much. Basically it is a single call to the AddUserTasks function in an interface that we are already familiar with, the ICustomDestinationList (ICustomDestinationList::AddUserTasks(IObjectArray) Method). Looking at the code, you will see a single line of code, hr = pcdl->AddUserTasks(poa);. However, as always, someone needs to create and build that poa, IObjectArray, and parameter and fill it with relevant information. Let’s review that process now.
We are going to create a collection of IShellLinks. This collection will be later cast to the required IObjectArray parameter. The following code is the beginning of that process.
IObjectCollection *poc;
HRESULT hr = CoCreateInstance(
D_EnumerableObjectCollection, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc));
if (SUCCEEDED(hr))
{
IShellLink * psl;
hr = _CreateShellLink(L"/Task1", L"Task 1", &psl);
if (SUCCEEDED(hr))
{
hr = poc->AddObject(psl);
psl->Release();
}
}
Here you can see that we used COM (again) and CoCreate and IObjectCollection, poc. Next, we call to a helper function called CreateShellLink that receives three parameters:
- The first parameter is the command line argument to the task
- The second parameter is the title that will be displayed
- The last parameter is a pointer to IShellLink
The object is then filed according to the relevant information.
Last, we add the recently created IShellLink to the object collection. You may ask yourself where the parameter that provides the path to the executable that we plan to launch is. Well that is a good question. For simplicity, we have hard-coded that information as shown in the following code snippet:
if (SUCCEEDED(hr))
{
hr = _CreateShellLink2(
L"C:\\Users\\<my user>\\Documents\\new text file.txt",
L"NotePad",
&psl);
if (SUCCEEDED(hr))
{
hr = poc->AddObject(psl);
psl->Release();
}
}
Here you can see we call to a hard-coded _CreateShellLink2 function. This receives a path to a text file as one of its parameters and, as you can see, we are launching Notepad.
Here is the code for the CreateShellLink2 function:
HRESULT _CreateShellLink2(
PCWSTR pszArguments, PCWSTR pszTitle,
IShellLink **ppsl)
{
IShellLink *psl;
HRESULT hr = CoCreateInstance(
CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&psl));
if (SUCCEEDED(hr))
{
hr = psl->SetPath(c_szNotePadExecPath);
if (SUCCEEDED(hr))
{
hr = psl->SetArguments(pszArguments);
if (SUCCEEDED(hr))
{
// The title property is required on Jump List items
// provided as an IShellLink instance. This value is used
// as the display name in the Jump List.
IPropertyStore *pps;
hr = psl->QueryInterface(IID_PPV_ARGS(&pps));
if (SUCCEEDED(hr))
{
PROPVARIANT propvar;
hr = InitPropVariantFromString(pszTitle, &propvar);
if (SUCCEEDED(hr))
{
hr = pps->SetValue(PKEY_Title, propvar);
if (SUCCEEDED(hr))
{
hr = pps->Commit();
if (SUCCEEDED(hr))
{
hr = psl->QueryInterface
(IID_PPV_ARGS(ppsl));
}
}
PropVariantClear(&propvar);
}
pps->Release();
}
}
}
else
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
psl->Release();
}
return hr;
}
To start with, again we need to use COM and CoCreate to create an IShellLink COM object. A quick look at the SDK reveals that the IShellLink object has many functions. Here are few that we will use:
- GetPath Gets the path and file name of a Shell link object, that is the path to the executable
- GetShowCmd Gets the show command for a Shell link object, the executable name
- SetArguments Sets the command-line arguments for a Shell link object
- SetDescription Sets the description for a Shell link object; the description can be any application-defined string
- SetIconLocation Sets the location (path and index) of the icon for a Shell link object SetPath Sets the path and file name of a Shell link object
- SetWorkingDirectory Sets the name of the working directory for a Shell link object
As you can see, for each parameter we must get and set appropriate methods. There are additional parameters; take a look at the SDK - IShellLink if you want to learn more.
In the above example, we set the path to Notepad (by default in the Windows 7 installation, c:\windows\notepad.exe). We also passed a hard-coded (not a good practice) command line argument pointing to a text file in my private document folder (C:\Users\<my user>\Documents\new text file.txt.) The rest of the code sets the title property that is required on Jump List items.
We call the CreateShellLink2 and CreateShellLink a few more times to add all three shortcuts as shown in the above screen capture.
Now let’s add a separator.
To add a separator to our Task List, we need to create an IShellLink, and set the PKEY_AppUserModel_IsDestListSeparator property using the COM property variant as shown in the following code snippet:
// The Tasks category of Jump Lists supports separator items.
// These are simply IShellLink instances that have the
// PKEY_AppUserModel_IsDestListSeparator property set to TRUE.
// All other values are ignored when this property is set.
HRESULT _CreateSeparatorLink(IShellLink **ppsl)
{
IPropertyStore *pps;
HRESULT hr = CoCreateInstance(
CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pps));
if (SUCCEEDED(hr))
{
PROPVARIANT propvar;
hr = InitPropVariantFromBoolean(TRUE, &propvar);
if (SUCCEEDED(hr))
{
hr = pps->SetValue(PKEY_AppUserModel_IsDestListSeparator, propvar);
if (SUCCEEDED(hr))
{
hr = pps->Commit();
if (SUCCEEDED(hr))
{
hr = pps->QueryInterface(IID_PPV_ARGS(ppsl));
}
}
PropVariantClear(&propvar);
}
pps->Release();
}
return hr;
}
Here you can see that we used CoCreate to create an IShellLink object. Next, we set a PROPVARIANT, propvar, to true and set the IShellLink object PKEY_AppUserModel_IsDestListSeparator property to true. This will instruct the OS to render this IShellLink as a separator and not just as regular IShellLink.
OK, that was long. Now let’s look at the short version, using .NET. For that we are going to use the Windows API Code pack for the .NET Framework.
As we can expect from .NET, we get abstraction from most of the “COM code behind” that is required. The Microsoft.WindowsAPICodePack.Shell.Taskbar namespace includes a JumpListLink object that extends the ShellLink object and implements IJumpListTasks.
The JumpList class contains the UserTasks collection of IJumpListTasks to which you can simple add new JumpListLink objects as shown in the following code snippet:
// Path to Windows system folder
string systemFolder =
Environment.GetFolderPath(Environment.SpecialFolder.System);
jumpList.UserTasks.Add(new JumpListLink
{
Title = "Open Notepad",
Path = Path.Combine(systemFolder, "notepad.exe"),
IconReference = new IconReference(
(systemFolder, "notepad.exe"), 0)
});
Using the C# 3.0 syntax, we initialize a new JumpListLink object and add it to the UserTasks collection. As you can see, the managed code JumpListLink has very similar properties to the native one (which makes perfect sense). We also added an icon to the Notepad shortcut to the above code, but didn't provide any command line parameters.
You want to add a separator? Well, that is also very easy: just add a JumpListSeperator object to the UserTasks collection.
jumpList.UserTasks.Add(new JumpListSeparator());
Taskbar.JumpList.RefreshTaskbarList();
After the refresh, the Jump List looks as follows:
I’ve compiled a version of a native example from the Windows 7 SDK. You can get a copy of that code from here
You can download the Windows API Code Pack that includes the manage code example we used in this post.
This concludes our Jump List discussion. Our next Taskbar topic is Icon Overlay.
Jul
2
If you haven visited Talking About Windows.com in a while, your missing a lot!
You missed Microsoft Engineers like Ian Burgess talking about the engineering design of DirectAccess and BitLocker. Hear Mario Garzia discussing application compatibility and how Windows 7 works with legacy applications.
Interact with IT pros like Darren Baker, the National Director of Infrastructure Solutions for Sogeti USA talk about how virtualization and imaging has made implementing Windows 7 in his organization easier.
Talking About Windows.com is your chance to hear what Microsoft Engineers and IT pros like your have to say and gives you a chance to interact with them.
Hear what they have to say and get heard. Join the conversation.
Jul
1
Today I am featuring guest Blogger Jeremy Chapman from the Windows Product Team. To see more of Jeremy, view our latest VRT on Application Compatibility. To learn more, click here. Below is his interview with Jeff Wettlaufer from the System Center Team.
I recently interviewed fellow product manager, long-time friend and fellow “automator” of operating system deployment tasks, Jeff Wettlaufer, from the System Center team. He explained the new features in the recently released System Center Configuration Manager 2007 Service Pack 2 Beta (let’s just call it “ConfigMgr07 SP2” for short), and how that will help with Windows 7 deployment and management.
Jeremy: What is ConfigMgr07 SP2 and where do people get it?
Jeff: Thanks for having me and thanks for saying configmgr and not sccm for once… SP2 adds support for new operating systems – Windows 7 and Server 2008 R2 and Windows Vista SP2 – along with exciting enhancements around Intel AMT integration. If you have the Intel vPro hardware, there are many things we can do. Out of Box Wired/Wireless Management: Wireless Profile Management, End Point Access Control: 802.1x support, Access Monitor: Audit Log, Remote Power Management: Power State Configuration. You were at Microsoft Management Summit in May and already saw this, but we demoed waking Windows XP PCs up wirelessly and kicking off the deployment to Windows 7 using USMT and hard-link migration. Those machines were mid range Dell latitude laptops, and we migrated to Windows 7 with 4GB user data and apps in 18 minutes.
Jeremy: I saw that, it was amazing. There is a video of that on Microsoft PressPass. And I thought I was fast with 23-minute migrations from Windows XP on my computers. Let’s take a step back for a second. From the 10,000 ft level, how does ConfigMgr07 help with client management?
Jeff: A lot of people probably know about how ConfigMgr can help with their inventory, software update (patch) management, and application distribution - but you may not be aware of things like the ability to manage PCs over the Internet, in the ‘serverless’ branch, at home, on the road and wherever people work these days. In addition, ConfigMgr can now deploy virtual applications in the same way as SMS and ConfigMgr have always delivered traditional physical formats. We can stream apps to desktops, or deliver the apps locally in what’s called download and execute, so even mobile laptop users can use virtual apps. There is a lot there and I’d encourage everyone to check out http://technet.microsoft.com/en-us/configmgr/default.aspx
Jeremy: Explain Internet-based client management.
Jeff: A lot of people say that mobile workforce management is a key challenge they face today on the client. Laptops are outselling desktops and people are taking these on the road, home or otherwise not connecting to the corporate network very often. So with ConfigMgr, we can manage ConfigMgr clients when they are not connected to your company network but have a standard Internet connections. This feature has a number of advantages, including the reduced costs of not having to run virtual private networks (VPNs) and being able to deploy software updates to remote users while they are traveling or at home.
Jeremy: Explain the new client hardware compatibility reports in HW inventory.
Jeff: We’ve updated the hardware compatibility reports in ConfigMgr to include the minimum bars for Windows 7 hardware compatibility, so you can see which machines in your environment are capable of running Windows 7 in a single view. We did this for Vista, and we found it really helped organizations understand where they were at the hardware level. We are taking that work forward to also help customers understand from their existing inventory of managed systems, which ones meet the minimum requirements before they start for Windows 7. As well as helping understand the hardware side of readiness, we also are providing support for applications. In the past we have provided support for the Application Compatibility Toolkit through a connector, that brings the app knowledge right into the Admin console. As ACT moves to version 6 for Windows 7, we will update the connector to support that effort. The ACT data is a real hidden gem, in 1 view you can see your apps – and organize your testing to compare it in that 1 view to the vendor, the community, and even Microsoft. This information can really help make the right decisions moving forward, and ConfigMgr can help migrate apps by supporting Application virtualization where needed.
Jeremy: How about the operating system deployment support.
Jeff: With any operating system deployment, you have to migrate user files off the old system, lay down a new OS, configure it with updates, packages and apps, then restore the user files and settings you migrated off in the first step. ConfigMgr can automate the whole process and do it without you having to visit the targeted PCs. I know you’ve got a lot of videos walking through the Lite Touch Installation process on the web, but ConfigMgr can even target the PCs for installation and kick off the process for you. Along the way we encrypt your user state, passwords and product keys, so it is more automated and enterprise-class. ConfigMgr has built on the great work in deployment technology from the Windows gang, by embracing and integrating the tools usage like WinPE, USMT, BitLocker and more. Our Task Sequencer helps to truly separate the hardware from the OS and application layers, by using the boot.wim and install.wim formats from Windows, and then providing a console UI experience to chain user data migration, applications and other settings.
Jeremy: Are all the Windows 7 deployment enhancements like the image servicing in DISM (Deployment Image Servicing and Management), hard-link migration, and Multicast included in the ConfigMgr SP2’s OS deployment?
Jeff: Like you saw at MMS, we do support USMT in ConfigMgr07, including hard-link migration. The Microsoft Deployment Toolkit 2010 Beta 2 extensions for SP2 enable hard-link migration without additional customization, or you can call the User State Migration Tool in a custom task to use the hard-link commands. Multicast is also supported and since we use the Windows 7 deployment tools, dism.exe is leveraged as well.
Jeremy: When can we expect RTM release of SP2?
Jeff: We recently made the Beta available and the final version should be ready within 90 days of Windows 7 RTM. Everything depends on the customer feedback we get from the Beta though – quality is the priority.
Jeremy: Thanks Jeff. If you have ConfigMgr and want try to SP2 Beta, visit connect.microsoft.com, join the System Center Configuration Manager 2007 Service Pack 2 Connection and download SP2.











