• 0

Windows 7 Thumbnail/Peek Problem in C#


Question

I'm writing an application profile launcher (can launch multiple apps based on profiles) using the Windows 7 Taskbar and Libraries .NET Interop Sample Library. Each profile can have a designated image to identify that profile. The profile image is then used with the interactive thumbnail feature of Windows 7. I implemented forward/back buttons (ripped them from the sample library for now) to let you select your profile and a button to launch the profile. Here's a screen shot just so you get the idea:

win7ap-ss.jpg

Now, to get the thumbnail previews to update properly I used the wrapper API provided from the sample library (compiled into DLLs which I incorporated into my own project):

WindowsFormsExtensions.EnableCustomWindowPreview(this);
WindowsFormsExtensions.SetIconicThumbnail(this, new Bitmap(pbProfilePicture.Image.GetThumbnailImage(200,120,null,IntPtr.Zero)));

The problem is, for the SetIconicThumbnail function to work properly, the EnableCustomWindowPreview function must be invoked with the handle to the window. And using the EnableCustomWindowPreview function then requires me to set a peek thumbnail manually (from an image/bmp), otherwise I get this (minimized or not):

win7ap-ss2.jpg

The problem is, I tried several methods of manually setting the peek thumbnail, none of which worked properly. Here's some of the things I tried (Method 1 works halfway in that it doesn't create the bitmap properly (stretched/distorted) and also fails to grab a screenshot when minimized. Method 2 causes all kinds of problems which I'm too lazy to specify as well):

			_windowsManager = CustomWindowsManager.CreateWindowsManager(this.Handle, IntPtr.Zero);
			_windowsManager.PeekRequested += (o, e) =>
			{
				e.Bitmap = Windows7.DesktopIntegration.ScreenCapture.GrabWindowBitmap(this.Handle, this.Size); // method 1
				Windows7Taskbar.SetPeekBitmap(this.Handle, Windows7.DesktopIntegration.ScreenCapture.GrabWindowBitmap(this.Handle, this.Size), true); // method 2
			};*/

Now by default (with most applications), the peek feature works fine, but calling the EnableCustomWindowPreview function requires you to manually set the bitmap for the window preview. So my question is, is there anyway I can use SetIconicThumbnail to set the thumbnail icon while keeping the default aero peek functionality (without requiring to set my own bitmap previews)?

I suppose if I absolutely have to I could capture a screenshot of the app and set the peek bitmap to it and store it in case it's minimized (and update whenever tabs are switched). But since this functionality should work by itself it seems like a waste of extra code/memory resources. Though if anyone can point me to some code to easily do this I may consider it.

Anyway, thanks in advance. Hopefully someone can help me out =)

Link to comment
https://www.neowin.net/forum/topic/809044-windows-7-thumbnailpeek-problem-in-c/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hi,

I am not sure if you have seen this or not.. http://code.msdn.microsoft.com/WindowsAPICodePack ... The 1.0 release of this was just released and its recommended compared to other extension libraries out there.

This is something official from Microsoft and includes a more comprehensive version of the Taskbar (and other) features in .NET. The TabbedThumbnail feature specifically makes it much easier for apps to get started with tabbed thumbnails and aero peeks for their windows.

There is a Winforms based sample that might be of interest to you - Samples\Shell\TabbedThumbnailDemo\CS\Winforms

Its a tabbed application that can have a web browser (for showing a full & almost live thumbnail) or text files (for showing thumbnail clip feature). Check out the code and how it handles various webbrowser events to update the thumbnail. For basic support, you just need to create a TabbedThumbnail object for the given window handle. The library does the capturing when the thumbnail is requested by the user. You could call the Invalidate method on the tabbed thumbnail object to let DWM/system know that next time user asks for the thumbnail it requests an updated image (which the library will take care of). Or as the sample app does, you can also update the bitmap your self by using your own captur utility.

- Keeron

  dlegend said:
I'm writing an application profile launcher (can launch multiple apps based on profiles) using the Windows 7 Taskbar and Libraries .NET Interop Sample Library. Each profile can have a designated image to identify that profile. The profile image is then used with the interactive thumbnail feature of Windows 7. I implemented forward/back buttons (ripped them from the sample library for now) to let you select your profile and a button to launch the profile. Here's a screen shot just so you get the idea:

win7ap-ss.jpg

Now, to get the thumbnail previews to update properly I used the wrapper API provided from the sample library (compiled into DLLs which I incorporated into my own project):

WindowsFormsExtensions.EnableCustomWindowPreview(this);
WindowsFormsExtensions.SetIconicThumbnail(this, new Bitmap(pbProfilePicture.Image.GetThumbnailImage(200,120,null,IntPtr.Zero)));

The problem is, for the SetIconicThumbnail function to work properly, the EnableCustomWindowPreview function must be invoked with the handle to the window. And using the EnableCustomWindowPreview function then requires me to set a peek thumbnail manually (from an image/bmp), otherwise I get this (minimized or not):

win7ap-ss2.jpg

The problem is, I tried several methods of manually setting the peek thumbnail, none of which worked properly. Here's some of the things I tried (Method 1 works halfway in that it doesn't create the bitmap properly (stretched/distorted) and also fails to grab a screenshot when minimized. Method 2 causes all kinds of problems which I'm too lazy to specify as well):

			_windowsManager = CustomWindowsManager.CreateWindowsManager(this.Handle, IntPtr.Zero);
			_windowsManager.PeekRequested += (o, e) =>
			{
				e.Bitmap = Windows7.DesktopIntegration.ScreenCapture.GrabWindowBitmap(this.Handle, this.Size); // method 1
				Windows7Taskbar.SetPeekBitmap(this.Handle, Windows7.DesktopIntegration.ScreenCapture.GrabWindowBitmap(this.Handle, this.Size), true); // method 2
			};*/

Now by default (with most applications), the peek feature works fine, but calling the EnableCustomWindowPreview function requires you to manually set the bitmap for the window preview. So my question is, is there anyway I can use SetIconicThumbnail to set the thumbnail icon while keeping the default aero peek functionality (without requiring to set my own bitmap previews)?

I suppose if I absolutely have to I could capture a screenshot of the app and set the peek bitmap to it and store it in case it's minimized (and update whenever tabs are switched). But since this functionality should work by itself it seems like a waste of extra code/memory resources. Though if anyone can point me to some code to easily do this I may consider it.

Anyway, thanks in advance. Hopefully someone can help me out =)

  • 0

Thanks for your reply. I started using the new library and figured it out. What's weird is I found that library before but also found the other one and got kinda confused. I was in a hurry to learn the new APIs and eventually stumbled into the problem I had. Luckily this new API code pack seems well organized and is easy to use. Just took awhile to figure out how to work the thumbnails (was different than the other API library).

Here's some snippets of code for how I got it to work in case anyone is wondering:

 
// frmMain_Load function
ttPreview = new TabbedThumbnail(this.Handle,pbProfilePicture);

			TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(ttPreview);

			ttPreview.TabbedThumbnailActivated += delegate(object s, TabbedThumbnailEventArgs x)
			{
				this.WindowState = FormWindowState.Normal;
			};

 
// Capture window messages (WndProc)
		protected override void WndProc(ref Message m)
		{
			if (m.Msg == 49304)
			{
				allowPreview = true;
				tt = TaskbarManager.Instance.TabbedThumbnail.GetThumbnailPreview(pbProfilePicture.Handle);
				tt.SetImage(new Bitmap(pbProfilePicture.Image.GetThumbnailImage(200, 120, null, IntPtr.Zero)));
				tt.Title = "Profile: " + tcProfiles.TabPages[tcProfiles.SelectedIndex].Text;
			}
			base.WndProc(ref m);
		}

// tcProfiles_SelectedIndexChanged (whenever a new profile is selected through the interface/thumbnail)

				if (allowPreview)
				{
					tt.SetImage(new Bitmap(pbProfilePicture.Image.GetThumbnailImage(200, 120, null, IntPtr.Zero)));
					tt.Title = "Profile: " + tcProfiles.TabPages[tcProfiles.SelectedIndex].Text;
				}

And in case anyone wanted to know what some of the variables/objects are in my code:

ttPreview = TabbedThumbnail using the form as parent, and a picturebox as the control

tt = TabbedThumbnail which holds the current instance of the ThumbnailPreview (used to update the thumbnail)

allowPreview = A boolean used to determine when the taskbar button has been created. If not used, the program will error prematurely because it's trying to load thumbnails/etc when it has nowhere to put it.

pbProfilePicture - The picturebox which stores the image used as the thumbnail

  • 0

Wonderful! Glad that worked out for you.

Try the rest of the samples there as well. There a lot of functionality which wasn't available to managed developers before (easily; possibly going the interop route manually would've worked)

  dlegend said:
Thanks for your reply. I started using the new library and figured it out. What's weird is I found that library before but also found the other one and got kinda confused. I was in a hurry to learn the new APIs and eventually stumbled into the problem I had. Luckily this new API code pack seems well organized and is easy to use. Just took awhile to figure out how to work the thumbnails (was different than the other API library).

Here's some snippets of code for how I got it to work in case anyone is wondering:

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Ah so it's not in the .ISO it's self but it changes the definition in the OOBE update during setup?
    • They always have. This just updates what's included out of the box during the initial install.
    • So basically their prebuilding it into the ISOs?
    • Microsoft shares Defender anti-virus update for new Windows 11/10 ISOs by Sayan Sen Following the one for Lumma last month, Microsoft has also published a new Defender update for Windows 11/10/Server installation images this month. This update package is necessary as a Windows installation image may contain old, outdated anti-malware definitions and software binaries. Aside from better security, these updates can also provide improved performance benefits in some cases. When a new Windows installation is set up, there may be a temporary security risk due to outdated Microsoft Defender protection in the OS installation images. This happens because the antimalware software included in these images might not be up to date. Thus Microsoft says that these updated definitions essentially help close this protection gap. Microsoft delivered the latest security definitions for Windows images via security intelligence update version 1.431.54.0. The Defender package version is also the same. It applies to Windows 11, Windows 10 (Enterprise, Pro, and Home editions), Windows Server 2022, Windows Server 2019, and Windows Server 2016. Microsoft writes: From Microsoft's security bulletin, we learn that the security intelligence update version 1.431.54.0 was released this past week adds threat detections for various backdoor exploits, trojans, among others. For those wondering, the latest intelligence update is version 1.431.155.0 at the time of writing.
    • “In other news about OneDrive frustration, Microsoft recently locked out a user who was attempting to move a bunch of important data from old hard drives to OneDrive.” - It was probably CSMA..
  • Recent Achievements

    • One Month Later
      SekTheFirst earned a badge
      One Month Later
    • First Post
      zayanhani earned a badge
      First Post
    • First Post
      HarryTaylor earned a badge
      First Post
    • One Year In
      Eternal Tech earned a badge
      One Year In
    • One Month Later
      Eternal Tech earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      650
    2. 2
      ATLien_0
      231
    3. 3
      Michael Scrip
      224
    4. 4
      Steven P.
      141
    5. 5
      +FloatingFatMan
      139
  • Tell a friend

    Love Neowin? Tell a friend!