New Post on Windows 7 for Developers
31 March 09 02:04 AM | yochayk | 2 Comments   

Remember – we Moved to a new location.

There is a new post on Windows 7 for Developers - Windows 7 .NET Interop Sample Libraries

Windows 7 Blog for Developer Is Moving!
30 March 09 11:50 PM | yochayk | 0 Comments   
moving-trolley

That's right folks, we are moving to a new location, becoming part of  The Windows Blog. As part of The Windows Blog, we will join the greater Windows messaging community and will be better able to ensure developers are up to date with both the latest news on the Windows 7 Development story and the Windows 7 User Experience story. The Windows Blog hosts several “satellite” blogs, including:

· Windows Vista Team Blog – to stay updated with news about Windows Vista

· Windows Experience Blog –to read about the amazing user experiences you can have with Windows 7

· Windows 7 Team Blog – to learn about all the important Windows 7 news and announcements

· Windows Security Blog –to become aware of all the things that go into having a secure Windows environment

· Windows for your Business – to discover ways Windows 7 benefits commercial customers

And, of course, the new Windows 7 for Developer Blog, which is our Windows 7 developer-focused blog. Our focus here will remain on topics of special interest to the Windows 7 developer community and we will continue to provide both native and managed code examples and insights.

I will still post to this blog, but about more general topics and ideas.

See you all at the new blog location - http://windowsteamblog.com/blogs/developers/default.aspx

Make sure you update your RSS feeds to the new blog RSS feed.

It used to be “write once - deploy anywhere”
20 March 09 08:54 PM | yochayk | 1 Comments   

Not so long ago, there was a catchy phrase we used in regards to developing, “write once – deploy anywhere.” Regardless of your programming preferences - .NET, Java, C/C++, this statement continues to be challenged as it is not really that easy to write once and deploy anywhere, it is more like, “write once – test everywhere…” But now, instead of targeting a specific OS such as Windows, Mac, or Linux, when  people says “write once - deploy anywhere,” what they superpreviewforiereally mean is write once and deploy on every available browser. As announced at the Mix 09 Day 1 Keynote, with the new Expression Web SuperPreview (one of the coolest features announced for Web Developers), this statement seems to be true for both standard html as well as Silverlight applications. Code your markup, and compare it to Firefox, Safari, IE6, and even to your PhotoShop comps to make sure that your design is pixel-perfect! Indeed, these are truly exciting times. You can download the SuperPreview trial here and can find a more detailed session on from Mix 09 here: Microsoft Expression Web: No Platform Left Behind.

superpreview2

New Windows 7 Content on Channel 9
08 January 09 08:33 AM | yochayk | 1 Comments   

With the Windows 7 Beta announcement today at CES, we are win7_ch9_homepagetransforming the Channel 9 theme into the Windows 7 theme. To  facilitate this, we are introducing new set of videos exploring key Windows 7 features and topics. Our goal is to provide a series of videos on key topics starting with overview videos but quickly diving into the guts of the technical details. We are coupling these videos with technical blog posts and code samples for you to download.

There is a lot of ground to cover and many topics to explore. We will start with a series of videos and blogs on the new Windows 7 Taskbar:

Windows 7 New Taskbar – An Overview is an introductory video to the new Windows 7 Taskbar. It provides a very good starting point for learning about all the cool new Windows 7 Taskbar features and it sets the context for the following videos.

Designing the Windows 7 Taskbar is a “personal” view of the User Interface and User Experience design process and an insider’s view of some of the reasons underlying Windows 7 Taskbar behaviors.

Windows 7 Taskbar – Behind the Scenes provides a technical overview of the Taskbar architecture, programming model, and API.

Jump into the Windows 7 Jump Lists is a technical deep dive into the Windows 7 Jump Lists programming model and APIs. It also provides an insight into the importance of providing Application ID for applications.

 

Windows 7 Taskbar – Part 1, The Basics is the first post in a series on code posts on Windows 7 Taskbar API and programming model.

 

More content comming soon.

Windows 7 Beta – Go Get It!
08 January 09 05:24 AM | yochayk | 1 Comments   

Today during CES, Steve Ballmer announced and presented Windows 7 Beta and by this Friday it will be publicly available for download from Windows 7 homepage. If you are MSDN Subscriber, you can download Windows 7 Beta right now! Here are the instructions on how to download and install Windows 7 Beta.

By making Windows 7 Beta publicly available we are hoping developers and enthusiasts will download it and the SDK, and will start testing this new Microsoft OS – Windows 7. Now that the beta is out and available, we can start engaging developers and can provide them with technical content so they can test and experiment with Windows 7.

You already found this blog, the Windows 7 Blog for Developers, so you are on the right track. Another awesome place to get great content is Channel 9, and specifically, Windows 7 on Channel 9. Obviously, Windows Development Center on MSDN is also a good place for Windows 7 technical content. You can also go to DevReadiness - a developer community site dedicated to assisting the Windows ISV ecosystem develop high quality applications for new versions of the platform.

We are also starting a series of Channel 9 videos, and posts on specific topics such as the Windows 7 Taskbar, Windows 7 Ribbon, Sensors, and Location Platform, but this will have to wait for another day.

Windows 7 Taskbar – Part 1, The Basics
06 January 09 01:37 AM | yochayk | 14 Comments   

This post is one of a series of Windows 7 Taskbar posts and webcasts. You can watch Jump into the Windows 7 Taskbar Jump Lists webcast on Channel 9 for further technical information, or the entire Windows 7 Taskbar webcasts series. You can also download the code sample.

One of the first Windows 7 changes that developers should pay attention to is the new Windows Taskbar. This new feature introduces a functionality that developers need to understand so they can take full advantage of it in their own applications to better enhance their end users’ experiences.

The new Taskbar is the most noticeable change to Windows 7 when you first log on. The Windows 7 Taskbar is an application-launching and window-switching mechanism that consolidates the functionalities from previous Windows Desktop mechanisms such as Quick Launch, Recent Documents, Notification area icons, desktop shortcuts, and running application windows.

If you are unfamiliar with and haven’t seen any demonstrations of the Windows 7 Taskbar, please watch Chitnya’s online Windows 7 Taskbar in Action demo during his Welcome to the New Desktop PDC session. This will give you some context for the technical material we are going to cover here. Additional information about the Windows 7 Taskbar can be found in The Windows 7 Taskbar E7 blog and in Channel 9 Windows Taskbar Webcast series.

In this article, we address Windows 7 Taskbar functionality and provide a high-level overview of its programming model to help developers to better prepare for Windows 7. Obviously, this will not be a comprehensive step-by-step developer guide to the Windows 7 Taskbar, but rather a broad overview. Please look for additional content about the Windows 7 taskbar in future posts.

The Windows 7 Taskbar is designed to provide users with quick and easy access to those “things” they use all the time. “Things” can be any type of content such as pictures, music, word documents or links and shortcuts to applications or folders. By quick and easy access, we mean accessing commonly used programs with a single mouse click or significantly reducing the number of clicks per operation. Quick and easy access also means users should be able to “jump” directly to those things they want to work with and start working with them in a single mouse click. To provide this functionality, Windows 7 Taskbar introduces the concept of “Jump Lists.”

As a developer, think of Jump Lists as your own mini Start Menu for imageyour application. Jump Lists surface commonly used nouns (destinations) and verbs (tasks) of a program, enabling easy user access to destinations by eliminating the need to launch the application and then load the relevant content, or by performing common tasks without launching the application in advance. The following diagram illustrates how Jump Lists work with Microsoft Office Word. You can see that under the “Recent” category, there is a list of recent documents that I’ve used with Office Word. Clicking on one of the items in the “Recent” list will launch Office Word with the relevant document already loaded.

 

 

 

The out-of-the-box experience of the Jump Lists includes only the default Taskbar Tasks. These provide the means to launch a new instance of the application, to pin or unpin an application to the taskbar, and to close the application. You can access the Jump List by right clicking on an application icon in the Taskbar. However, as the following diagram illustrates, you can opt into the Taskbar experience by customizing the context of the Jump Lists for your application.

image

Image from Robert Jarrett’s slide deck from his PDC session

Definitions from the Windows 7 SDK:

”… Destinations are items that appear in the Recent, Frequent or custom categories (the “Important” category in the diagram above), based on the user’s items usage. Destination can be files, folders, Web sites or other content-based items, but are not necessarily file-backed. Destinations can be pinned to or removed from the Jump List by the user. They are generally represented by IShellItem objects, but they can also be IShellLink objects…”

”…Tasks are common actions performed in applications that apply to all users of the application regardless of the individual usage patterns. Task can’t be pinned or removed. Tasks are represented by IShellLInk objects because they are actually links (with parameters – optional) to commands – “Actions”…”

As developers, we can:

  1. Control Application Destinations (that is control the items we want users to be able to “Jump” directly into and start working on)
    • Destinations can be any one of the known categories such as Recent or Frequent.
    • The Custom category is just like any other Destination category, except that it allows developers to create a new name for that category as well as populate it with items.
    • The Pinned category is provided for pinned items that users want to keep permanently in their Jump Lists.

2. Define common user Tasks

    • The Taskbar surfaces its own out-of-the-box tasks such as launching, pinning/unpinning, or closing the application. As developers we have no control over the Taskbar Tasks. However, we do control the User Tasks.
    • User Tasks are common tasks the application developer wants to surface at the Jump List level that will enable users to perform a task directly from the Jump List (e.g. Play all music in media player without switching to media player). Usually, this will result in launching an instance of the application and performing the task. Again, this saves time and reduces the number of clicks needed to achieve the same end goal without the Jump List functionality.

It is time we address the Taskbar programming model. The Taskbar exposes its set of APIs like any other Windows Shell component, through a set of COM interfaces. However, there are a few actions we developers can do even before starting to use the Windows Taskbar COM APIs.

Step 1 – Use the Out-of-the-Box Windows Experience and Default Behavior

By default, a Jump List contains a Recent category that is populated automatically for file-based applications through the SHAddToRecentDocs function. This function adds the used “item” (document) to the Shell's list of recently used documents. In addition to updating its list of recent documents, the Shell adds a shortcut to the user's Recent directory. The Windows 7 Taskbar uses that list and Recent directory to populate the list of recent items in the Jump Lists.

Windows can also do the work for you if your application's file type has a registered handler (this does not have to be the default handler). Anytime you double click on a file type with a registered handler, before Windows launches your application it automatically calls SHAddToRecentDocs on your application's behalf. This inserts the item in the Windows Recent list and eventually into the Jump List Recent Category. The same automatic behavior occurs when using the Windows common file dialog to open files through our applications.

Both of the above cases exploit default Windows behavior in case you have a registered handler and an Application ID by which the files are assoctiated with Recent and Frequent lists. In both cases, Windows automatically inserts the items into the Jump Lists unless you specifically remove this functionality by using the COM API. Obviously, users also have the option to remove any items from their Jump Lists. By explicitly removing an item from the Jump List, you insert it into the Removed item list, which we will discuss below.

Step 2 – Create Your Own Category

If the default Recent or Frequent categories do not meet your application's needs, it is time to create your own custom category. You need to use the ICustomDestinationList interface to create a custom Destination List.

The ICustomDestinationList exposes methods that allow an application to provide a custom Jump List, including destinations and tasks, for display in the taskbar. Here are the methods that we are using for the example below:

AppendCategory

Defines a custom category and the destinations that it contains, for inclusion in a custom Jump List

AppendKnownCategory

Specifies that the Frequent or Recent category should be included in the Jump List

BeginList

Initiates a building session for a custom Jump List

CommitList

Declares that the Jump List initiated by a call to BeginList is complete and ready for display

Here is a code snippet for a function that creates a new custom list called “Custom Lists” and appends 4 items to it:

   1:  void CreateJumpList()
   2:  {    
   3:      ICustomDestinationList *pcdl;
   4:      HRESULT hr = CoCreateInstance
   5:                     (CLSID_DestinationList, 
   6:                      NULL, CLSCTX_INPROC_SERVER, 
   7:     IID_PPV_ARGS(&pcdl));
   8:   
   9:      if (SUCCEEDED(hr))
  10:      {
  11:          hr = pcdl->SetAppID(c_szAppID);
  12:          if (SUCCEEDED(hr))
  13:          {
  14:              UINT uMaxSlots;
  15:              IObjectArray *poaRemoved;
  16:              hr = pcdl->BeginList
  17:                  (&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
  18:              if (SUCCEEDED(hr))
  19:              {
  20:                  hr = _AddCategoryToList(pcdl, poaRemoved);
  21:                  if (SUCCEEDED(hr))
  22:                  {
  23:                      pcdl->CommitList();
  24:                  }
  25:                  poaRemoved->Release();
  26:              }
  27:          }
  28:      }
  29:  }
// This is the helper function that actually 
//appends the items to a collection object HRESULT 
 
_AddCategoryToList(ICustomDestinationList *pcdl,
                       IObjectArray *poaRemoved)
{
    IObjectCollection *poc;
    HRESULT hr = CoCreateInstance
(CLSID_EnumerableObjectCollection, 
NULL, 
CLSCTX_INPROC_SERVER, 
IID_PPV_ARGS(&poc));
    if (SUCCEEDED(hr))
    {
        for (UINT i = 0; i < ARRAYSIZE(c_rgpszFiles); i++)
        {
            IShellItem *psi;
            if (SUCCEEDED(SHCreateItemInKnownFolder(
FOLDERID_Documents, 
KF_FLAG_DEFAULT, 
c_rgpszFiles[i], 
IID_PPV_ARGS(&psi))))
            {
                if(!_IsItemInArray(psi, poaRemoved))
                {
                    poc->AddObject(psi);
                }
 
                psi->Release();
            }
        }
 
        IObjectArray *poa;
        hr = poc->QueryInterface(IID_PPV_ARGS(&poa));
        if (SUCCEEDED(hr))
        {
            pcdl->AppendCategory(L"Custom category", poa);
            poa->Release();
        }
        poc->Release();
    }
    return hr;
}

 

We started with a call to CoCreateInstance to initialize the ICustomDestinationList object (this is the joy of working with COM….). Next, we set the Application ID, so we could start populating items to the list. The Application ID is a string the uniquely identifies your application and make sure all the different windows are clustered under the same glom as well as all the files in the Recent category, however, Application ID is important enough to get its own full blog in the near future.

Using the BeginList function initiated the build session for the custom Jump List. Note the Remove item parameter, IObjectArray *poaRemoved, that the BeginList() returned as an out parameter. We will handle the removed items list below.

Next we called a helper function, _AddCategoryToList(), to do the actual work of adding items to the custom category.

Another new interface, the IObjectCollection, represents a collection of objects that support IUnKnown, to which we will add the IShellItems. Each item we added is of an IShellItem type and we created each item in the documents known folder. However, before we actually added the new item to the collection, we needed to check if the user already removed it. If the user explicitly removed an item from the Jump List, that item will be in the Removed Item List (again associated with the App ID), and, as developers, we need to respect the user's requests and avoid adding that item to the Jump List. We already have the list of removed items, IObjectArray *poaRemoved, that we got when we called the BeginList(…) function when we initiated the process of creating a new list.

At this stage, we have a collection if IShellItems that the user expects to see in his Jump List. Next we added that collection to the ICustomDestinationList object and created a new category named “Custom category”, pcdl->AppendCategory (L"Custom category", poa);.

We have successful created a new category in the Taskbar called “Custom category” and populated it with four items. However, our work is not done yet. The final step is to call the CommitList() function that ends the "transaction" that began with calling the BeginList() function. Only after our call to CommitList() are the new category and new items displayed. Calling CommitList() causes the stored list of removed items to be cleared and a new removed items list to begin. The ICustomDestinationist interface provides a "transactional base" API. In order to ensure a positive end user experience, make sure that a safe copy of the new repopulated list is complete and ready for use, and that the only operation the Taskbar must perform is to switch the pointer to the new list.

As you can see, it is easy to opt in to the Windows 7 Taskbar functionality. Most of the work is performed automatically by Windows for you, and if you do need to create your own category, that is also very easy.

There are many more features the new Windows 7 Taskbar that further enhance the user experience, including cool visual and informative notifications using Overlay icons, a Progress Bar indicator, and Thumbnail icons. We will address these features in future posts.

Laptop Power Conservation with Windows Bridge
02 December 08 07:48 PM | yochayk | 2 Comments   

In these days of ever-increasing mobile computing, laptop power consumption is ever more important. With laptops making up more than 50% of the computer sold last year, it is critical that users have all-day computing power when they're on the move. But paying attention to laptop power consumption is not important just for the user; increased use of battery-powered laptops results in lower IT power consumption costs. Computer usage is responsible for 7% to 18% of the electricity bill for a medium-sized company. While hardware providers are increasing battery life, It is critical that software developers don't inadvertently undercut those gains through their application's power draining practices.

A very good PDC session by Pat Stemen, Extending Battery Life with Energy Efficient Applications, includes a detailed explanation of the technological improvements in Windows 7 and the tools that come with it. Power management in Windows 7 will be a topic for future blog posts. In this blog post we will look at Vista’s power management APIs and focus on the managed power wrapper in the new release of the Windows Vista Bridge Library.

There are a few steps that developers can take to reduce their applications’ power consumption. First, try to keep the application’s CPU usage as close to idle as possible at all times. (CPU idle state = CPU usage of less than 2%) When the CPU is in idle or close to idle state, the CPU enters a low-power state that reduces its clock frequency, resulting in significant battery power conservation. As developers, we can help maintain a low clock ratio by using events and asynchronous notifications rather than a timer to poll (query) a value. When an application polls at a high rate (high frequency), it increases CPU usage and power consumption.

The following chart illustrates how increasing timer resolutionCPU_Power_Timer_Resolution increases the power consumption. Changing the Windows default timer resolution from 15.6 milliseconds to 1 millisecond can result in an up to 20% impact on battery life, because the frequent timer interrupts will prevent the processor from entering low-power states. With the default timer resolution, the CPU power consumption can be low as 0.1 watts which is a fraction of the overall computer’s 11 watts power consumption. But when increasing the timer resolution to 1 millisecond, the CPU power consumption raises to 1.5 watts affecting the overall computer power consumption by 2 watts.

Second, if an application launches a service that must wait for some event to happen, such as when a USB thumb drive is inserted, don’t launch the service until after the event occurs. It will be easy to implement this recommendation with the new Windows 7 Service Control Manager, which Vikram Singh presented during PDC in a session called Designing Efficient Background Processes.

Last, but by no means least, applications should be power aware. The power state of the computer can either be AC power, battery power, or UPS. To be power aware means that an application takes into account the current power state of the computer and acts upon that state in a way that minimizes power consumption. For example, an application should not start any non-critical operations while running on battery if it can postpone those operations to a later time without degrading the overall user experience.

Clearly, power awareness is a critical step in optimizing application power demands. How do we ensure that our applications are power aware?

To do this, we will use the Windows Vista Bridge Library. This library includes a whole section dedicated to bridging between the native power API and .NET. But there is one class within the library that is especially important for power aware managed code application. The PowerManager enables applications to register for power events and query the current power state. The PowerManager is a static class that the application can use at any given time simply by accessing its properties. The PowerManager keeps its power state accurate at all times by running a thread in the background that listens to OS power events. This thread has minimum to no affect on the application power consumption.

Here are some of the properties / functions that the PowerManager exposes regarding the power state:

Property or Function

Description

PowerManager.PowerPersonality

Specifies the the current power scheme

PowerManager.PowerSource

Specifies the power source currently supplying power to the system

PowerManager.IsBatteryPresent;

True if battery is present (just if a laptop has one)

PowerManager.IsUpsPresent;

Specifies whether power UPS is present

PowerManager.IsMonitorOn;

Specifies whether the monitor is on

PowerManager.MonitorRequired;

Specifies whether the monitor is set to remain active

PowerManager.IsBatteryShortTerm;

Specifies whether the battery is a short term battery

PowerManager.BatteryLifePercent;

Specifies the remaining battery life

PowerManager.GetCurrentBatteryState()

Gets a snapshot of the current battery state, nand updates the PowerManager

The PowerManager also exposes set of events that an application can register in order to receive notifications when there is a change in the power status:

Event

Description

PowerManager. IsMonitorOnChanged;

Raised when the monitor status changes

PowerManager.BatteryLifePercentChanged

Raised when the remaining battery life percentage changes

PowerManager.PowerPersonalityChanged

Raised each time the active power scheme changes

PowerManager. PowerSourceChanged

Raised when the power source changes

PowerManager.SystemBusyChanged

Raised when the system will not be moving into an idle state in the near future; applications should be designed to take advantage of this time to run their tasks, rather than running them during otherwise idle CPU periods

Note that Windows Vista and Windows 7 will always try to reach idle state; however, sometimes the system acknowledges that an idle state will not be reached anytime soon due to an IO or other operation. The OS can notify any interested applications that the system is “busy” and will not switch to an idle state anytime soon. This would allow the application to start running some tasks using the high utilization CPU as is.

The Vista Bridge Library has an example showing how to use the PowerManager . It is a simple WPF application that uses the PowerManager to display the current power status and update the status upon power status change. When running the application you’ll see a simple window listing the PowerManager properties and the current power status. When switching from AC power to battery while running on a laptop you will notice the change to the Windows theme but also that the application has captured the power changes.

 

VB_Power

 

 

Here is the code snippet for capturing current power status:

   1:  private void GetPowerSettings()
   2:  {
   3:      settings.PowerPersonality = 
   4:          PowerManager.PowerPersonality.ToString();
   5:      settings.PowerSource = 
   6:          PowerManager.PowerSource.ToString();
   7:      settings.BatteryPresent = 
   8:          PowerManager.IsBatteryPresent;
   9:      settings.UpsPresent = 
  10:          PowerManager.IsUpsPresent;
  11:      settings.MonitorOn = 
  12:          PowerManager.IsMonitorOn;
  13:      settings.MonitorRequired = 
  14:          PowerManager.MonitorRequired;
  15:      
  16:      if (PowerManager.IsBatteryPresent)
  17:      {
  18:          settings.BatteryShortTerm = 
  19:          PowerManager.IsBatteryShortTerm;
  20:          settings.BatteryLifePercent = 
  21:          PowerManager.BatteryLifePercent;
  22:          settings.BatteryState = 
  23:          PowerManager.GetCurrentBatteryState().ToString();
  24:      }
  25:  }

 

Here is the code snippet for registering to the events:

   1:  // Adds event handlers for PowerManager events.
   2:  private void CapturePowerManagementEvents()
   3:  {
   4:      PowerManager.IsMonitorOnChanged += 
   5:          new EventHandler(MonitorOnChanged);
   6:      PowerManager.PowerPersonalityChanged += 
   7:          new EventHandler(PowerPersonalityChanged);
   8:      PowerManager.PowerSourceChanged += 
   9:          new EventHandler(PowerSourceChanged);
  10:      if (PowerManager.IsBatteryPresent)
  11:              PowerManager.BatteryLifePercentChanged += 
  12:                  new EventHandler(BatteryLifePercentChanged);
  13:   
  14:      PowerManager.SystemBusyChanged += 
  15:          new EventHandler(SystemBusyChanged);
  16:  }

 

Now it is up to you. Go ahead and download the Windows Vista Bridge Sample Library, and start using Vista Power APIs - they all work just as well on a Windows 7 machine.

(This blog and the application sample were written and tested on a Windows 7 machine)

J

Windows Vista Bridge Sample Library = A Managed API for Windows
14 November 08 12:41 AM | yochayk | 5 Comments   

I am sure some of you are asking right now, “Why are we writing and talking about Windows Vista in the Windows 7® Blog for Developers?” The answer is simple. We are talking about Windows Vista because Windows 7 is based on the solid foundation of Windows Vista, and provides backward compatibility to the Windows Vista programming model. With that said, we are listening to customer feedback and making great improvements in regard to performance including better resource utilization, reliability, compatibility, and security, thereby perfecting the overall user experience while at the same time providing great value for developers. The Windows Engineering (E7) blog has a great post about this topic.

It is no secret that the Windows Operating System (OS) is based on C / C++ and therefore uses a native programming model, most commonly known by its informal name WinAPI or Win32 API. The Windows API is a native C style or COM-based API. This makes using the API very easy and natural for native C /C++ developers. But what can we offer managed code developers? Are there any managed code APIs for Windows Vista or Windows 7?

The .NET Framework offers an easy and intuitive programming model targeting Windows clients (Web, servers, mobile, etc.) And, together with a set of tools and libraries, it provides a productive and effective framework for writing Windows client applications. One of the strengths of the .NET Framework is that it is a library-based framework, and anyone can add libraries to enhance the framework’s functionality. In fact, the out-of-the-box .NET experience offers a large number of libraries that abstracts the native Windows API, making development for a given Windows client (regardless of the OS version – XP, Vista, or 7) a much easier task than using the native Windows API.
A good example is the .NET WinForms assembly (assembly is .NET’s name for libraries), which contains a set of wrapper classes that wrap a traditional Win 32 API for creating and handling windows in the Windows OS. By abstracting the native API, .NET WinForms ensures that we don’t need to directly work with pointers (HWND) or handles (HINSTANCE) or other Windows native API constructs that could result in code that looks like this:


image

Rest assured, WinForms is HWND based. A .NET developer can easily access a given Windows form Handle or (HWND) by using the MSG.hwnd property that can be found in the System.Windows.Interop class in the WindowsBase assembly (WindowsBase.dll).

But as comprehensive as the .NET Framework is, it does not offer managed APIs to all Windows’ native APIs. For example, a managed code developer doesn’t have any managed APIs to work with Windows Vista User Account Control (UAC) API, Restart Manager API, or the new Windows Vista Search API. These are just few examples of key native Windows APIs that .NET Framework doesn’t provide interfaces to and yet are crucial for a given application to successfully deploy on Windows while bringing excitement and innovations to end users.

The Windows Vista Bridge Sample Library (VBSL) is an ongoing effort by the Microsoft SDK team to bridge between the .NET framework and the native Windows API. The VBSL is a class library that makes it much easier for managed developers to access light-up Windows Vista features with no need to worry about the Interop layer. Vista Bridge 1.3 provides managed developers with a set of classes, libraries, and samples written in .NET that allows developers to take advantage of Vista features including UAC, Power Management, Restart & Recovery, Restart Manager, Network, Aero Glass, among many others. It is important to say that all the Vista Bridge managed libraries work well with Windows 7 APIs and will continue to work in future release as the SDK team will continue to support this project.

The Vista Bridge Sample Library (download Vista Bridge Sample Library) is part of the Windows SDK. However, this project is important enough to be placed front center in the Code Gallery.

In future posts, we will drill into a few of the features mentioned above, mainly to show how you can take advantage of Windows Vista today in order to make the migration path to Windows 7 much easier in the future.

One area where the VBSL can make a big difference is in dialogs.

Windows Vista offers a wide variety of dialog boxes for different purposes. For examples, if you are using Windows Vista I am sure you are familiar this UI format:

image

Or with this one:

image

Both of the above screenshots are fancy dialog boxes based on command links. With command links, users select a single response to a main instruction and by doing so, move on to the next step in a task. Command links have a clean, lightweight appearance that allows for descriptive labels, and are displayed with either a standard arrow or custom icon, and an optional supplemental explanation.

Here is an example of a typical set of command links.

image

Command links are similar to radio buttons in that they are used to select from a set of mutually exclusive, related choices. Like radio buttons, command links are always presented in sets, never individually. Command links have a lightweight appearance similar to regular links, without a frame or other strong click affordance. Command links are also similar to command buttons, in that they can be the default "command button" and they can have an access key assigned. Like commit buttons, when clicked they either close the window (for dialog boxes) or advance to the next page (for wizards and pages flows).

Using the Windows Vista Bridge Sample Library, you can now create fancy Task Dialogs that look like this:

image

The Task Dialog is an object in the Vista Bridge Sample Library, Microsoft.SDK.Samples.VistaBridge.Library.TaskDialog and has no design time properties; therefore, you must program the Dialog. But this is easy, as shown in the next examples.

First, create a task dialog: TaskDialog td = new TaskDialog();

Then start setting its attributes, for example, caption, instructions, main content area, and the main icon:

//main content section
td.Caption = "Fancy \"Vista\" Task Dialog on Win 7";
td.Instruction = "Your instructions go here";
td.Content = "Download Windows Vista Bridge Library";
td.MainIcon = TaskDialogStandardIcon.Information;

Now add the optional footer text and footer icon:

td.FooterText = "Footer text goes here";
td.FooterIcon = TaskDialogStandardIcon.Shield;

But the fun starts when you start playing with the TaskDialog.Controls, a collection of (you guessed it) TaskDialog controls DialogControlCollection<TaskDialogControl>.

To which you can add TaskDialogControl objects:

td.Controls.Add(new TaskDialogCommandLink("new tdcl", "main text here", "instruction"));

In addition to adding Command Links, the Task Dialog also exposes a set of events that lets you manipulate and interact with users as they operate the dialog. The Task Dialog object exposes the Tick event to work with the progress bar, Open, and Closing events, as well as HelpInvoked and HyperLinkClick to manage user requests for more information and help.

//events that you can catch
td.Tick += new EventHandler<TaskDialogTickEventArgs>(OnMyTick);
td.Opened += new EventHandler(OnOpenInvoked);
td.HelpInvoked += new EventHandler(OnHelpInvoked);

You can also add Progress Bar, CheckBox, or Radio Button. Basically, the Windows Vista Task Dialogs API is a mini Dialog framework that saves you a lot of time dealing with wizards and fancy dialog screens.

Now it is up to you. Go ahead and download the Windows Vista Bridge Sample Library, and start using Vista styles dialog—they all work just as well on a Windows 7 machine.

(This blog was written on a Windows 7 machine)

J

The code for the examples above

   1:  td = new TaskDialog();
   2:   
   3:  //
   4:  td.StartupLocation = TaskDialogStartupLocation.CenterOwner;
   5:  td.Cancelable = true;
   6:   
   7:  //main content section
   8:  td.Caption = "Fancy \"Vista\" Task Dialog on Win 7";
   9:  td.Instruction = "Your instructions go here";
  10:  td.Content = "Download Windows Vista Bridge Library Sample";
  11:  td.MainIcon = TaskDialogStandardIcon.Information;
  12:   
  13:  //setting footer content
  14:  td.FooterText = "Footer text goes here";
  15:  td.FooterIcon = TaskDialogStandardIcon.Shield;
  16:   
  17:  //Command Links
  18:  td.Controls.Add(new TaskDialogCommandLink("new tdcl", "Main text here", "Instruction"));
  19:  td.Controls.Add(new TaskDialogCommandLink
          ("Another new tdcl", " Another main text here", "More instruction"));
  20:   
  21:  //Expanding 
  22:  td.ExpansionMode = TaskDialogExpandedInformationLocation.ExpandContent;
  23:  td.ExpandedControlText = "Expanded Control Text";
  24:  td.ExpandedText = "This is some expanded text, only visible when expanded"; 
  25:  td.CollapsedControlText = "Collapsed Control Text";
  26:  td.HyperlinksEnabled = true;
  27:   
  28:  //Prograss Bar
  29:  TaskDialogProgressBar tdpb = new TaskDialogProgressBar();
  30:  tdpb.Name = "myPrograssBar1";
  31:  tdpb.Minimum = 0;
  32:  tdpb.Maximum = 100;
  33:  td.ProgressBar = tdpb; //adding to main Task Dialog
  34:   
  35:  // Check Box
  36:  td.CheckBoxChecked = true;
  37:  td.CheckBoxText = "This is a checkbox, we can register to listen for its events";
  38:   
  39:  //events that you can catch
  40:  td.Tick += new EventHandler<TaskDialogTickEventArgs>(OnMyTick);
  41:  td.Opened += new EventHandler(OnOpenInvoked);
  42:  td.HelpInvoked += new EventHandler(OnHelpInvoked);
  43:  td.Closing += new EventHandler<TaskDialogClosingEventArgs>(OnDialogClosing);
  44:  td.HyperlinkClick += new EventHandler<TaskDialogHyperlinkClickedEventArgs>(td_HyperlinkClick);
  45:   
  46:  td.Show(); 
Windows 7 at PDC – Part 2 (post Windows 7 announcement)
28 October 08 08:10 PM | yochayk | 0 Comments   

With Windows 7 unveiled during PDC Day 2 keynote we update few of Windows 7 sessions that had a TBD abstract as well adding two new sessions. Hereunder is the list of updated sessions and the new session.

PDC full session list can be found here

PC16 Windows 7: Empower users to find, visualize and organize their data with Libraries and the Explorer (updated session)

Presenter: David Washington

Learn how you can enable a familiar experience for users and light up your application by using the Windows Search API and Library API and File Dialog. Also learn how you can integrate your web service with Windows search by using the OpenSearch standard without writing any client code. Master how to provide a rich experience for your data type in the Windows 7 Explorer with metadata, thumbnails, verbs and previews.

ES20 Developing Applications for More Than 64 Logical Processors in Windows Server 2008 R2 (new session)

Presenter: Arie van der Hoeven

Windows 7 will support more than 64 logical processors with improved kernel scheduler mechanisms that enable efficient scaling. Learn how to use new system software affinity APIs to aid application scalability beyond 64 logical processors through the use of "Kernel Groups." Kernel Groups allow for legacy processor affinity aware applications to perform well while applications and drivers using new APIs can take advantage of all processors on the system.

PC25 Windows 7: The Sensor and Location Platform: Building Context-Aware Applications (updated session)

Presenter: Dan Polivy

Windows 7 introduces a platform for using sensor devices, such as light sensors or GPS sensors, to create environmental or location awareness in programs. In this session, you will learn how to use sensors to make your programs more functional, easier to use, and more aware of the surrounding environment

PC14 Windows 7: New Shell User Experience APIs (Updated session)

Presenter: Nicolas Brun

This session dives into new APIs that enable integration with the latest Windows desktop features. Learn about new extensibility methods to surface your application's key tasks. Discover how enhancements to the taskbar, Start Menu, thumbnails and their desktop elements provide new ways for you to delight your users. This talk is a must for application developers who want to provide the best user experience for their applications on Windows 7.

PC13 Windows 7: Building Great Audio Communications Applications (Updated session)

Presenter: Larry Osterman

Using the PC as a phone is central to the future of communications, and this session will provide you with the essentials to build the end to end experience. Windows 7 provides APIs for integrating communications capabilities into your applications. This session covers attenuating and muting sounds during a phone call, receiving a phone call using a Bluetooth headset, improving the latency of a phone call, and selecting the appropriate communications device.

ES26 Windows Server 2008 R2: Using Classification for File Lifecycle Management (New session)

Presenters: Nir Ben Zvi, Matthias Wollnik

Windows File Server 2008 R2 provides a new extensible infrastructure to manage files based on classification. These capabilities can be leveraged by backup products, archival and workflow management software, and tools that help prevent information leakage. See how both on-premises software and software plus services developers can take advantage of these new capabilities to deliver end-to-end solutions with integrated classification capabilities.

J

Windows 7 Developer Guide Is Now Available
28 October 08 07:38 PM | yochayk | 3 Comments   

With Windows 7 unveiled during PDC Day 2 keynote, we also released Windows 7 Developer Guide. This is relatively a short guide outlining some of Windows 7’s main features as well highlighting the solid foundations Windows 7 is build upon. The goal of this document is to help developers plan for the near future by providing developers a clear picture of Windows 7’s new capabilities, and the scenarios developers can target in order to enhance their end users experiences for Windows 7 applications. For example, Scenic Ribbon (view at PDC ), Multi-Touch (view at PDC ), Libraries (view at PDC ), and Sensors and Locations (view at PDC ) are just few of Windows 7’s features developers can use to enhance their end users experiences. Please note, this document is not a full blown detailed description of the new APIs in Windows 7. In fact, this document does not contain any API references or code examples. All that good stuff will arrive sometime in the near future in future posts.

As you read through the developer guide you’ll notice three main parts: Solid Foundation, Richer Application Experiences, and The Best of Windows and the Web. Following that path while developing applications for Windows 7 is a very good practice, as Windows 7 leverages Windows Vista’s features and concepts. Next you can enhance your end user experiences with Ribbon, Multi-Touch, or integrating with Windows 7 new Taskbar (or any of other Windows 7 features). Finally, providing new services or leveraging exciting services that interact with your application add a whole new set of experiences for your end users.

Solid Foundation

Windows 7 provides a highly productive developer platform and tools that deliver on core operating system fundamentals. Windows 7 builds upon the Windows Vista platform, giving developers the power to build applications that are compatible with both platforms while limiting application compatibility issues. Windows 7 dramatically improves performance and power management so that you can create applications that optimize the mobile experience. As a result, your applications will be more visually appealing, easier to create, and support a wider range of international standards. Advances have also been made in global support, accessibility, and application deployment…. (Read more in the Windows 7 Developer Guide)

Richer Application Experiences

Windows 7 enables developers to create distinctive and intuitive applications that significantly enhance discoverability, usability, and sheer enjoyment. New methods of desktop integration put application functionality right at the user’s fingertips, and Windows Explorer and Libraries provide easy access to high-value information. The Scenic Ribbon control and animation framework make it easier to build interactive and appealing user interfaces. New touch APIs enable natural interactions through multi-touch and finger-panning, and manipulation and inertia APIs enable impressive visual effects… (Read more in the Windows 7 Developer Guide)

The Best of Windows and the Web

With Windows 7, it’s easy to get connected and stay connected. Windows networking offers developers options for better caching and sharing of data to improve network performance. Network diagnostics in Windows 7 give developers relevant information for monitoring network issues. Whether the goal is to connect devices, connect to a network, or simply understand the status of your connection, Windows 7 provides an enhanced platform… (Read more in the Windows 7 Developer Guide)

J

Windows 7 at PDC – Part 1 (pre-PDC)
27 October 08 09:54 AM | yochayk | 0 Comments   

PDC is just few hours away, and in case you are still trying to figure out which sessions you want to go to, here is a little tip regarding Windows 7 sessions.

As of today, few of Windows 7 sessions have a very short (in length) abstract. For example, in Day 2, there is a session named “Windows 7: New APIs to Find, Visualize, and Organize” that has an amazingly short but still very informative abstract that summaries in to TBD

 

TBD Session

For some, TBD means To Be Determined, while others may think it means To Be Defined. For someone who is trying to figure out which sessions to go and needs to choose one session over the other, a session with a “TBD” for its abstract may not look that attractive session. Since some of Windows 7 new features are kept under the hood until PDC, TBD can be considered as To Be Disclosed…

So don’t worry, about that TBD, it is not as the speakers has forget to write an abstract for his session, it is only because we want to surprise you!

J

The Windows 7 Blog for Developers
23 October 08 09:58 AM | yochayk | 11 Comments   

Welcome to the first post of a new Windows 7 blog. This blog will mainly focus on the development aspects of Windows 7 by providing valuable content for developers. We shall call this blog “The Windows 7 Blog for Developers”. By valuable content we mean that this blog will be a “one stop shop” on the road to get yourself familiar with what Windows 7 has to offer for developers and how you can “Light-Up” using Windows 7 features in your application.

With your help, this blog should evolve to become some sort of Windows 7 developer content index. If you are looking to write some code using one of Windows 7 new features, you should find some reference to that topic in this blog. If you don’t find it, please feel free to comment and we’ll try to pick the subject as quick as possible. In case you have content you want to share, ping us so we can write a post and reference your content.

You can also expect this blog to have lots of code samples, and cool demo showcasing some Windows 7’s new features. You can also expect this blog to have web cast with different people from different parts of the windows organization. With that in mind, some Windows folks have their own blogs which we will try to keep track and listing all the important Windows 7 content posted on these blogs.

Finally, this blog is part of an effort to highlight Windows 7 development story, a story that for some reason got lost with Windows Vista. As part of the Windows 7 Evangelism team and as developers, we hope, together with you and the rest of the community will be able to create an open and direct dialog about developing for Windows 7.

This new release of Windows has a lot of new features that will give developers a chance to differentiate their applications, as well as solid foundations to build upon.

Join us on this trip through Windows 7 development features and help us share some of that joy and happiness.

One last thing, we will post some non pure technical content but we promise that it will be Windows 7 related.

J

Search

This Blog

Syndication

Page view tracker