Geeks With Blogs

Windows 7 +1

Earlier I wrote about possibility of the task panel of Windows 7 to change preview for a window. We said that in preview it is possible to display both a window part, and own image. At Windows 7 there is such pleasant feature, that if we will hover the mouse cursor on preview windows all other windows will disappear, and the selected window will be displayed. It looks as follows.


In this case the panel of problems Windows 7 allows us to set own behaviour too. In this case we have possibility to set contents of our form our own image. For example, we can write any useful text. In this case the work scenario can look as follows. The user in the panel of problems has an application which something does. It can observe its state on the basis of ProgressBar and OverlayIcon about which I wrote earlier. If this information has not enough, he can hover the mouse cursor at an icon of the application. In this case preview in which the additional information contains it will be displayed (about what I wrote too). The user can hover on window preview and in this case all windows will disappear and on the screen there will be only an selected window. In this window we can display even more information which is necessary for the user.

By default at such scenario at concealment of other windows window contents will be displayed. Such redefinition of the content of a window can be useful, if on the form the information is separated and at once is not clear that occurs in the application.

To implement the similar scenario in our application we will take advantage .NET Interop Sample Library. SetPeekBitmap method of a class-wrapper is intended for these purposes. When the user hovers on preview windows it is necessary to generate the image. For these purposes we will redefine method WndProc and we will catch event WM_DWMSENDICONICLIVEPREVIEWBITMAP. Just during this moment of time it is necessary to generate the image.

protected override void WndProc(ref Message m)
        WindowsFormsExtensions.SetPeekBitmap(this, GeneratePeekBitmap(this, Images._111), true);
    base.WndProc(ref m);

In this case we invoke a method which will generate necessary to us Bitmap. Generation of this image also does not represent any complexity. Generally we can copy in this Bitmap a picture of our window and over it to draw the information necessary to us. I will fill this area with a certain background and I will draw a icon of a state atop it.

private static Bitmap GeneratePeekBitmap(Form form, Image stateImage)
    var preview = new Bitmap(form.ClientSize.Width, form.ClientSize.Height);
    var g = Graphics.FromImage(preview);
    g.DrawImage(Images.background.GetThumbnailImage(form.ClientSize.Width, form.ClientSize.Height, null, IntPtr.Zero), 0, 0);
    if (stateImage != null)
        Size thumbSize = new Size(100, 100);
        g.DrawImage(stateImage.GetThumbnailImage(thumbSize.Width, thumbSize.Height, null, IntPtr.Zero), form.ClientSize.Width / 2 - thumbSize.Width / 2, form.ClientSize.Height / 2 - thumbSize.Height / 2);
    return preview;

Pay attention, that for correct display the sizes of this image should coincide with the size of the form. After that at us the application which looks as follows will turn out.


Actually, after that the image to is established whence it can be necessary. The main thing that this image also was generated at the moment of processing specified above event. For example, in the demonstration sample I also set this image in the timer. Thus I can hover the mouse cursor on preview and observe of that as the form changes at timer tick.

Besides, SetPeekBitmap method has a third parametre of logic type (boolean). Whether changing this parametre it is possible to specify it is necessary to remove a border of application. For example, if I set this parametre in false I will see the following result.

Sample application:

Posted on Friday, May 29, 2009 9:47 AM | Back to top

Comments on this post: Windows 7 programming: Taskbar. Part 9 – PeekBitmap.

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © | Powered by: