Windows 7 任务栏上的 Delphi 表单图标模糊(启用 MainFormOnTaskbar)
我们有一个用 Delphi 编写的 Windows 桌面应用程序,它在 Windows 7 上运行良好,只是主窗体的图标在 Windows 新任务栏中看起来很模糊。只要应用程序尚未启动,图标看起来就很好(即,当它固定到任务栏时)。启动后,Windows 使用主窗体的图标(而不是 .exe 资源图标),并且它很模糊(看起来像是 16x16 版本的图标放大了)。
我们用于 .exe 和主窗体的图标完全相同,并且包含各种分辨率,包括带 alpha 混合的 48x48。
我的理论是,当我在 Delphi 中导入主窗体的 .ico 文件时,Delphi 会忽略/删除图标的额外分辨率。有没有办法防止/解决这个问题?确保用 Delphi 编写的应用程序在 Windows 7 任务栏中使用正确的图标分辨率的最佳方法是什么?
We have a Windows desktop application written in Delphi that works fine on Windows 7, except that the icon of the main form looks blurry in Windows' new taskbar. As long as the application has not been started the icon looks fine (i.e. when it's pinned to the taskbar). Once it has been started Windows uses the icon of the main form (instead of the .exe resource icon) and it's blurry (it looks like a 16x16 version of the icon is scaled up).
The icon that we use for the .exe and for the main form are exactly the same and it contains all kinds of resolutions, including 48x48 with alpha blending.
My theory is that Delphi ignores/deletes the extra resolutions of the icon when I import the .ico file for the main form in Delphi. Is there a way to prevent/fix this? What's the best way to ensure that an application written in Delphi uses the correct icon resolution in Windows 7's taskbar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于 VCL 内的惰性编程不适合操作系统的行为变化。或多或少是这样的;
TCustomForm.CreateWnd,窗口句柄创建后,调用;
注意“1”代替了 wParam,即 ICON_BIG。实际上VCL设置了窗体的大图标。但图标的请求大小 (TIcon.FRequestedSize) 是 16x16(默认情况下),因此窗体的 TIcon 返回小图标的句柄。这是系统小图标的大小,是在构造函数 CreateNew 中通过调用 GetSystemMetrics 确定的。
由于早期版本的 Windows 使用任务栏上的小图标,这没有问题。然而,Alt+Tab 对话框却有相反的问题;如果将图标分配给表单,则它在 Alt+Tab 对话框中显示为“模糊”。无论如何,Windows 7默认情况下仍然为小图标(SM_CXSMICON/SM_CYSMICON)返回16x16,为大图标(SM_CXICON/SM_CYICON)返回32x32,但是大任务栏显示大图标,如果有的话
..正确的方法是为大图标分配一张大图像(如果图标中有一个),为小图标分配一张小图像(如果有的话)。当然,由于尺寸不必完全匹配,因此这需要复杂的算法。相反,实施了一种更简单但破碎的设计。
作为解决方法,我没有为 OI 中的表单分配图标,而是使用它;
并在项目中包含一个“icons.res”,其中包含具有 16x16 和 32x32 图像的命名图标。 OnCreate 调用中的所有表单
The problem lies within lazy programming within the VCL not fitting with the behavioral change of the OS. More or less it is like this;
TCustomForm.CreateWnd, after the window handle is created, calls;
Notice the "1" in place of wParam, that's ICON_BIG. Actually the VCL sets the large icon of the form. But the icon's requested size (TIcon.FRequestedSize) is 16x16 (by default), and so the TIcon of the form returns a handle for the small icon. That's the size for the system small icon and is determined in the constructor CreateNew with calls to GetSystemMetrics.
Since earlier versions of Windows used the small icon on the taskbar this was no problem. Hovewer the Alt+Tab dialog had the problem other way around; if an icon was assigned to a form it showed "blurred" in the Alt+Tab dialog. Anyway, Windows 7, still, by default returns 16x16 for the small icon (SM_CXSMICON/SM_CYSMICON) and 32x32 for the large icon (SM_CXICON/SM_CYICON), but the large taskbar displays the large icon, if there is one that is..
The correct approach would be to assign a large image (if there is one in the icon) for the large icon and assign a small image (if there is one) to the small icon. Granted, since the sizes would not have to have exact matches, this would require a complex algorithm. Instead, a simpler but broken design is implemented.
For a workaround, I don't assign an icon to the forms in the OI and instead use this;
and include an "icons.res" with named icons having 16x16 and 32x32 images, in the project. All the forms in their OnCreate call
要做到这一点可能有点像一场噩梦。我发现最成功的策略是在主窗体和应用程序上放置一个非常简单的图标,然后将 ReplaceVistaIcon 程序合并到构建工作流程中,以便在构建完成后用多图标文件替换该图标(并且在签署 exe 之前)。这似乎正确放置了图标,以便 Windows 优先于任何其他图标资源选择它。必须这样做很麻烦,但是一旦设置(在我们的 FinalBuilder 项目中)它就对我们有用。
当您测试此功能时,令人烦恼的问题是您可能必须删除 Windows 图标缓存才能看到任何更改的效果。这涉及关闭资源管理器以允许您从命令会话中删除缓存文件。
It can be a bit of a nightmare getting this right. I have found that the most successful strategy is to place a very simple icon on the main form and application, and then to incorporate the ReplaceVistaIcon program into the build workflow to replace the icon with your multiple-icon file after the build is complete (and before signing the exe). This seems to place the icon correctly so that Windows picks it up in preference to any other icon resource. It's a nuisance to have to do this, but once set up (in our FinalBuilder project) it works for us.
The annoying problem, while you are testing this, is that you may have to delete the Windows icon cache to see the effect of any changes. This involves shutting down Explorer to allow you to delete the cache file from a command session.