As developers, we often shriek a little whenever a new operating system is released. Our most common question is “will my application run?” Enhancements in compatibility have made this question a mute point. Now that we don’t have to spend as much time fixing our applications, we can concentrate on improving them.
As .NET developers, we have often been left behind on major operating system integrations, unless we were willing to dive into unmanaged code. Windows 7 brings new salvation for .NET developers, and it comes in the form of the Windows 7 API Code Pack for the.NET Framework.
The Code Pack provides .NET developers a library exposing some of the new functionality in Windows 7, as well as features available in previous versions of Windows.
In this article, we’ll explore some of the functionality provided to you in the Code Pack, as well as offer suggestions as to how these features can help you enhance your Windows 7 applications. Every feature discussed is easily programmable using the Code Pack. This article will not provide any source code about any particular feature, but the Code Pack comes with fantastic documentation and several full source examples for each feature.
One of the many immediately recognizable new features of Windows 7 is the enhanced Taskbar. This is a major step since we haven’t seen a radical change in the taskbar since its introduction in Windows 95. The redesigned taskbar gives us several new features that are easily programmable through the Windows API Code pack.
Jump Lists give you the ability to provide your users with a list of common tasks and commonly accessed files. For example, Internet Explorer will provide you with a list of frequently accessed web pages. Additionally, it’ll allow you to quickly open a new tab or start an InPrivate browsing session.
Taskbar Thumbnail Tabbed Preview
Thumbnail Tabbed Previews expand the existing functionality you get by running your application on Windows 7. By default, the operating system will display a thumbnail of your application running whenever you mouse over it on the taskbar. This provides the user with instant feedback on what your application currently looks like. It might be nice to provide additional previews to your customers. For example, in Internet Explorer, you are provided a preview for each tab you currently have open within the browser. This allows users to quickly navigate to the tab of choice instead of restoring Internet Explorer and selecting a tab.
Taskbar Thumbnail Toolbar
In addition to displaying a preview for your application, it might be beneficial to give the user tasks that can be performed from the preview itself. This functionality is separate from jump lists, since thumbnail previews are available only when the application is running. For example, Windows Media Player gives Windows 7 users the ability to pause and skip tracks from within the thumbnail.
The new progress bar functionality for the Taskbar gives you the ability to show progress from within your application’s icon on the taskbar. Easily sync any progress bar within your application to the progress bar on the taskbar, and provide your users instant feedback. This functionality gives your users the information they care about without having to bring your application into focus.
Windows 7 provides you with one additional taskbar feature in order to give you feedback without having to open the application. Icon Overlays allow you to add an icon to the bottom right hand corner of your application’s taskbar icon.
A great example of this feature is Windows Live Messenger. When you log into Messenger, it’ll provide you with an icon reflecting your present status. If you are online and available, Messenger will display a green “online” icon.
Libraries and Known Folders
Libraries are a new feature to Windows 7 that allows you to have virtual folders containing certain file types. These libraries allow you to browse common file types, such as documents, music, videos, and pictures in one folder instead of having to browse to several folders. These file types are presented in a virtual view (or a Library).
Known folders are not a new concept to Windows. I’ve heard the term “special folders” used in previous versions of Windows. Consider a case where you want to write to the user’s Start menu, but are not sure where the folder for the Start menu is located. For standard users, the path can be inferred. However, we never want to trust Windows to create all user paths equal. A best practice is to ask the operating system where the path resides. The Code Pack gives you easy access to all these types of folders, including Libraries.
Search has become a large part of our operating system experience. From our Start menu, we can quickly search our programs, documents, music, photos, and emails. Why shouldn’t we be able to take that power and implement it in our applications? The Search API gives us the ability to: search any folder on the hard drive; add conditions such as date range and keywords; get deeper into the files and search meta tags, such as author, title, and comments.
Common File Dialogs
The idea of common file dialogs is nothing new. If you’ve used an OpenFileDialog before, you’ve used the older version of a common file dialog. In Windows 7, we can take advantage of its new common file dialogs. The code pack can help you take advantage of these dialogs with little hassle.
The new common file dialogs will allow you to easily set the dialog to known folders, libraries, and various saved searches. You can even direct the user to search connectors, such as Microsoft Outlook. A search connector is a component that allows you to search applications and services within Windows. Examples of search connectors include Outlook, Amazon, PriceGrabber, and YouTube. Applications can use these connectors to search the services. Take advantage of the new power, while keeping the common look and feel of Windows 7.
Message boxes are a wonderful tool that many of us use all time. The main problem with message boxes is that they are difficult to customize for various situations.
Task dialogs were introduced in Vista, and they perform similarly to message boxes, except that they provide additional parameters that are controlled by the developer. These parameters can include progress bars, radio buttons, custom buttons, expandable sections, footers, and even options such as “Don’t show this dialog again” prompts. Use task dialogs to provide additional message box functionality without having to build your own.
DirectX has been around for a long time. Debuting with Windows 95, DirectX took care of multimedia tasks that normally had to be custom written. The downside, especially for .NET developers, was that DirectX libraries were entirely unmanaged. The Windows 7 API Code Pack provides managed support for DirectX. As of this writing, the code pack supports DirectX 10.0, 10.1, 11.0, Direct2D, DirectWrite, DirectX Graphics Infrastructure (DXGI), and Windows Imaging Components (WIC). If you’ve ever been interested in looking at DirectX, but the lack of managed APIs have stopped you, then you should give the code pack a look.
Sensors Platform API
Sensors are an amazing addition to Windows 7. They give you the ability to change your application depending on your current environment. This means that your application can react to changes in light or acceleration. Imagine building an application with two color schemes, one for low light and another for higher ambient light. Using a light sensor, you can automatically switch between the two, thus making your application usable in any situation. If you’ve used a GPS, you’ve seen this type of feature in action.
Location sensors can detect your location via GPS. This is an opt-in technology, meaning that your users have to turn the feature on before your application can support it. After it’s turned on, your application can easily identify your location.
Extended Linguistic Services API
In a perfect world, our applications would only have to work in one language. However, in the expanding technological world, we need to be able take our applications into other cultures.
Windows 7 introduces Extended Linguistic Services APIs to assist you in this task. You can adapt your application based on the user’s location and culture preferences. Give users all over the world a natural user experience without a lot of additional overhead.
Power Management API
Tracking the power source of the host machine might be important in the application you’re developing, and the Code Pack gives you a framework for managing and polling several aspects of the machine’s power supply. The Power Management APIs provide you information about the power source being used. If you are using a laptop or tablet, you can get feedback such as battery health, current charge, and charge rate.
The API also allows you to track power events easily. Subscribe to a variety of events, such as: system busy, battery life change, power source change, and monitor on or off.
Application Restart and Recovery API
Our applications aren’t perfect, and our users are prone to finding even the smallest bugs in our code. How many times have you been working in Word only to have it crash right before you were about to save? If you restart Word, it automatically detected that there was a crash, and offers to open a cached copy of the document for you. The Application Restart and Recovery API gives your application the same functionality. You can save the user’s state on a regular period, and gracefully recover from application crashes.
Network List Manager API
It might be necessary in your application to have knowledge about the machine’s internet connection. Basic questions, such as “Is my machine connected to the internet” and “What connection is my machine using to connect to the network?” can easily be answered with the Network List Manager API.
I hope this overview has given you enough insight into the power and flexibly available to you in the Windows 7 API Code Pack. I encourage every developer to go and download it today. Start taking advantage of the features, and enhance your application!