private void setPreview(string fileLocation) { if (!string.IsNullOrEmpty(fileLocation)) { using (Image coverArt = Image.FromFile(fileLocation)) { Windows7Taskbar.SetIconicThumbnail((IntPtr)mcRef.GetWindowHandle(), (Bitmap)coverArt.GetThumbnailImage(120, 120, null, IntPtr.Zero)); } return; } }
/// <summary> /// Sets this form's iconic thumbnail to the specified bitmap. /// </summary> /// <param name="form">The form.</param> /// <param name="bitmap">The bitmap.</param> public static void SetIconicThumbnail(this Form form, Bitmap bitmap) { Windows7Taskbar.SetIconicThumbnail(form.Handle, bitmap); }
/// <summary> /// Sets this Window's iconic thumbnail to the specified bitmap. /// </summary> /// <param name="form">The form.</param> /// <param name="bitmap">The bitmap.</param> public static void SetIconicThumbnail(this Window form, Bitmap bitmap) { Windows7Taskbar.SetIconicThumbnail(GetWindowHandle(form), bitmap); }
public void DispatchMessage(ref Message m) { if (m.Msg == SafeNativeMethods.WM_ACTIVATE && _hwndParent != IntPtr.Zero) { if (((int)m.WParam) == SafeNativeMethods.WA_ACTIVE || ((int)m.WParam) == SafeNativeMethods.WA_CLICKACTIVE) { UnsafeNativeMethods.SendMessage( _hwnd, (uint)m.Msg, m.WParam, m.LParam); //TODO: Technically, we should also test if the child //isn't visible. If it is, no need to send the message. } } if (m.Msg == SafeNativeMethods.WM_SYSCOMMAND && _hwndParent != IntPtr.Zero) { if (((int)m.WParam) == SafeNativeMethods.SC_CLOSE) { UnsafeNativeMethods.SendMessage( _hwnd, SafeNativeMethods.WM_CLOSE, IntPtr.Zero, IntPtr.Zero); WindowClosed(); } } if (m.Msg == SafeNativeMethods.WM_DWMSENDICONICTHUMBNAIL) { int width = (int)(((long)m.LParam) >> 16); int height = (int)(((long)m.LParam) & (0xFFFF)); BitmapRequestedEventArgs b = new BitmapRequestedEventArgs(width, height, true); ThumbnailRequested(this, b); if (b.UseWindowScreenshot) { Size clientSize; UnsafeNativeMethods.GetClientSize(_hwnd, out clientSize); float thumbnailAspect = ((float)width) / height; float windowAspect = ((float)clientSize.Width) / clientSize.Height; if (windowAspect > thumbnailAspect) { //Wider than the thumbnail, make the thumbnail height smaller: height = (int)(height * (thumbnailAspect / windowAspect)); } if (windowAspect < thumbnailAspect) { //The thumbnail is wider, make the width smaller: width = (int)(width * (windowAspect / thumbnailAspect)); } b.Bitmap = ScreenCapture.GrabWindowBitmap(_hwnd, new Size(width, height)); } else if (!b.DoNotMirrorBitmap) { b.Bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); } Windows7Taskbar.SetIconicThumbnail(WindowToTellDwmAbout, b.Bitmap); b.Bitmap.Dispose(); //TODO: Is it our responsibility? } else if (m.Msg == SafeNativeMethods.WM_DWMSENDICONICLIVEPREVIEWBITMAP) { Size clientSize; if (!UnsafeNativeMethods.GetClientSize(_hwnd, out clientSize)) { clientSize = new Size(50, 50);//Best guess } BitmapRequestedEventArgs b = new BitmapRequestedEventArgs( clientSize.Width, clientSize.Height, _hwndParent == IntPtr.Zero); PeekRequested(this, b); if (b.UseWindowScreenshot) { b.Bitmap = ScreenCapture.GrabWindowBitmap(_hwnd, clientSize); } else if (!b.DoNotMirrorBitmap) { b.Bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); } if (_hwndParent != IntPtr.Zero) { Point offset = WindowUtilities.GetParentOffsetOfChild(_hwnd, _hwndParent); Windows7Taskbar.SetPeekBitmap(WindowToTellDwmAbout, b.Bitmap, offset, b.DisplayFrameAroundBitmap); } else { Windows7Taskbar.SetPeekBitmap(WindowToTellDwmAbout, b.Bitmap, b.DisplayFrameAroundBitmap); } b.Bitmap.Dispose(); } }