• 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

    • No word on how much of an ewaste apocalypse this will cause.
    • The list of Mac devices rumored to get macOS 26 by Hamid Ganji Apple will announce macOS 26 or macOS Tahoe at its Monday Worldwide Developers Conference. As has been reported multiple times over the past weeks, all Apple operating systems will receive a UI overhaul, a touch of AI, and new names at this year's WWDC. The logic behind the "26" in the new macOS version is that Apple aims to align its naming schedule with its 2025-2026 release cycle. The same version number will also appear across iOS, iPadOS, watchOS, and tvOS. While skipping multiple software versions raises many questions, it might help maintain consistency in the Apple ecosystem. With just two days away from the WWDC kick-off, many Mac owners might wonder if the upcoming macOS 26 is compatible with their devices. Here's the rumored list of compatible Mac devices with the macOS 26: MacBook Air (M1 and later) MacBook Pro (2019 and later) iMac (2020 and later) Mac Mini (M1 and later) Mac Studio (all models) Mac Pro (2019 and later) This report comes from MacRumors, which cites a private account on X as the source. However, the interesting thing about this list is that, according to the leaker, Apple might end software support for the MacBook Pro 13-inch (2020 model, two Thunderbolt 3 ports). For now, we should take this claim with a pinch of salt. The 2020 MacBook Pro 13-inch launched with both Intel and Apple Silicon M1 processors. It also comes with two port configurations. Apple is expected to end support for more Intel-based Mac devices this year, and this specific MacBook Pro variant might also be on Apple's kill list. WWDC 2025 kicks off on June 9, and Apple will unveil the latest version of its operating systems with an overhauled UI and a slew of AI-related features. So far, we know what Apple Watch models might get watchOS 26. Apple will announce the compatibility list of various devices at Monday's event.
    • It's a separate question to the thread, but I have VLC and qBitorrent working on W11 without any issue. Download->install->job done.
    • Currently I am using Display Port connection to monitor.   If I change the setting you show above it does make text larger, but ALL text larger not just icon text on desktop. Also is doesn't change the text weight at all. That setting leaves it very thing test. I want bold, or semibold.
    • Patch My PC - Home Updater 5.2.3.0 by Razvan Serea Patch My PC Free is a reliable tool which can quickly check your PC for outdated software. The supported third-party programs include a large number of widely-used applications, including Adobe Reader, Mozilla Firefox, Java, 7-Zip, BleachBit, Google Chrome and many more. Patch My PC Home updater features: Updates over 500 common apps check including portable apps Ability to cache updates for use on multiple machines No bloatware during installations Applications install/update silently by default no install wizard needed Optionally, disable silent install to perform a manual custom install Easy to use user interface Change updated and outdated apps color for color blindness Option to automatically kill programs before updating it Create a baseline of applications if installing on new PC’s Quickly uninstall multiple programs Scan time is usually less than 1 second Set updates to happen on a schedule Skip updates for any application you don’t want to update Suppresses restarts when performing application updates Patch My PC - Home Updater 5.2.3.0 changelog: Startup Manager New tab to manage which apps launch at startup. This helps speed up your boot time and gives you control over what runs in the background. Generate Diagnostic ZIP You can now create a diagnostic ZIP file from the About page. This helps if you need to send logs on our support forum for Home Updater. Remove Portable Apps Right-click any portable app in the App Catalog or Uninstaller page to remove it directly. Applications Added FFmpeg (Full Shared) – Portable Fing G-Helper – Portable IntelliJ IDEA Community Edition K-Lite Basic Codec Pack K-Lite Full Codec Pack K-Lite Standard Codec Pack KeePass Password Safe v1 LibreOffice Help Pack MemTest86 – Portable Nexus Vortex Nvidia Profile Inspector – Portable Pale Moon – Portable ViVeTool – Portable WinCDEmu Windows PC Health Check Wise Video Converter Applications Removed Driver Easy Download: Patch My PC 5.2.3.0 | 54.8 MB (Freeware) Download: Patch My PC Portable | 31.0 MB (Portable) View: Patch My PC Free Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      abortretryfail earned a badge
      Week One Done
    • First Post
      Mr bot earned a badge
      First Post
    • First Post
      Bkl211 earned a badge
      First Post
    • One Year In
      Mido gaber earned a badge
      One Year In
    • One Year In
      Vladimir Migunov earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      490
    2. 2
      +FloatingFatMan
      258
    3. 3
      snowy owl
      249
    4. 4
      ATLien_0
      223
    5. 5
      +Edouard
      190
  • Tell a friend

    Love Neowin? Tell a friend!