【问题标题】:How to refresh taskbar preview even when the form is minimized即使表单最小化如何刷新任务栏预览
【发布时间】:2020-11-23 16:51:25
【问题描述】:
我遇到了问题,我注意到 90% 的 Windows(7,8,10) 应用程序不会更新任务栏预览(当您将鼠标悬停在任务栏中的应用程序图标上时的小窗口),因此当应用程序最小化时任务栏预览只是冻结并且不更新,除了一些应用程序即使在最小化时也会更新它(例如 Windows Media Player、Music Bee)。我尝试使用WindowsAPICodePack 自己解决此问题并裁剪任务栏预览,我还使用了第二种形式并将Opacity 设置为0,但它不起作用。我现在没有要显示的代码。
【问题讨论】:
-
-
@Jimi 已经一个小时了,我正在尝试使用 DWMAPI.dll 不走运,我在 SO(C# 但我确实转换了它)上的这篇文章中找到了代码link 它只是赢了'不工作,我尽一切努力让它工作,如果我错了,请纠正我 'dest' 是我的应用程序句柄,'src' 是我要显示的应用程序,'thumb' 一个整数来更新缩略图' DwmRegisterThumbnail' 返回 -2147024809,src 为 0,Thumb 也为 0,这是我的代码 pastebin.com/zGFjbQAu,Ref 的 pastebin.com/5KwEd1SE
标签:
.net
vb.net
taskbar
windows-media-player
windows-api-code-pack
【解决方案1】:
以编程方式刷新任务栏预览并使用自定义位图:
Imports System
Imports System.Drawing
Imports System.Threading
Imports System.Windows.Forms
Imports Microsoft.WindowsAPICodePack.Taskbar
Namespace CustomThumbnailImage
Public Partial Class Form1
Inherits Form
Private customThumbnail As TabbedThumbnail
Public Sub New()
InitializeComponent()
End Sub
Protected Overrides Sub OnShown(ByVal e As EventArgs)
MyBase.OnShown(e)
customThumbnail = New TabbedThumbnail(Me.Handle, Me.Handle)
TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(customThumbnail)
customThumbnail.TabbedThumbnailBitmapRequested += AddressOf customThumbnail_TabbedThumbnailBitmapRequested
End Sub
Private Function GenerateBitmap() As Bitmap
Dim bitmap As Bitmap = New Bitmap(150, 150)
Using g = Graphics.FromImage(bitmap)
Dim random = New Random(Environment.TickCount)
Using brush = New SolidBrush(Color.FromArgb(255, random.[Next](255), random.[Next](255), random.[Next](255)))
g.FillEllipse(brush, 10, 30, 130, 90)
End Using
End Using
Return bitmap
End Function
Private Sub customThumbnail_TabbedThumbnailBitmapRequested(ByVal sender As Object, ByVal e As TabbedThumbnailBitmapRequestedEventArgs)
Dim bitmap = GenerateBitmap()
customThumbnail.SetImage(bitmap)
ThreadPool.QueueUserWorkItem(Sub(c)
Thread.Sleep(2000)
Me.Invoke(New MethodInvoker(AddressOf InvalidateThumbnail))
End Sub)
End Sub
Private Sub InvalidateThumbnail()
customThumbnail.InvalidatePreview()
End Sub
End Class
End Namespace
Win7Api 示例的所有部分