隐藏WPF窗口中的图标 [英] Hide the icon from a WPF window

查看:257
本文介绍了隐藏WPF窗口中的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于隐藏或删除WPF窗口左上角图标的问题,这是系统菜单所在的位置。我尝试了很多但没有效果。以下是我的要求:

I know that there are many questions about hiding or removing the icon from the upper left corner of a WPF window, the place where the system menu is. I've tried many of them but none works. Here are my requirements:


  • 图标消失,不占空位(即没有透明图标)

  • 窗口标题直接从窗口的左边缘开始

  • 右上角的关闭按钮仍然存在并且正常工作

  • 最小化/最大化按钮仍然存在(如果启用)(可选,未测试)

  • 没有自定义绘制整个窗口框架

  • 适用于启用了Aero Glass的Windows 7(Windows 8任何人?)

  • 适用于32位和64位Windows(x86和x64版本)

  • Works使用WPF .NET 4.0

  • 不在像Visual Studio这样的调试器中工作(如果在调试器中也可以使用,那就很好)

  • 还应该适用于Windows XP(可选)

  • The icon disappears and does not take any empty space (i. e. no transparent icon)
  • The window title starts directly at the left edge of the window
  • The close button in the upper right corner is still there and works
  • Minimise/maximise buttons are still there if enabled (optional, didn't test this)
  • No custom-drawing of the entire window frame
  • Works on Windows 7 with Aero Glass enabled (Windows 8 anybody?)
  • Works on 32 and 64 bit Windows (x86 and x64 build)
  • Works with WPF .NET 4.0
  • Works when not in a debugger like Visual Studio (would be nice if it also works in the debugger)
  • Should also work on Windows XP (optional)

可用答案基本上使用Windows API函数 GetWindowLong SetWindowLong ,有时还要 SetWindowPos 添加扩展窗口样式 WS_EX_DLGMODALFRAME 并调用 SWP_FRAMECHANGED 。有时,其他样式也会被设置或取消设置。

The available answers basically use the Windows API functions GetWindowLong, SetWindowLong and sometimes also SetWindowPos to add the extended window style WS_EX_DLGMODALFRAME and call SWP_FRAMECHANGED. Sometimes, other styles are also set or unset.

不幸的是,这一切都没有。我可以没有没有关闭按钮的图标,或者两者都在那里。但同样值得注意的是,所有这些内容都来自2010年或预告片。它似乎是针对早期的.NET或Windows版本而失败的。

Unfortunately, none of this works at all. I can either have no icon with no close button, or both are still there. But it's also noticeable that all of that content is from 2010 or eariler. It seems it's targeted at earlier .NET or Windows versions and fails since.

我已经比较了系统对话框(来自资源管理器)和我的WPF窗口的窗口样式Microsoft Spy ++(包含在Visual Studio中)。但我可以尝试设置所有标志相同,图标不会消失。这就像黑魔法一样否决了所有其他API函数或物理。

I've already compared the window styles of system dialogs (from Explorer) and my WPF windows with Microsoft Spy++ (included in Visual Studio). But I can try to set all flags the same, the icon won't go away. It's like black magic that overrules every other API function or physics.

有没有人能够在今天和指定的环境中使用仍然有效的解决方案?

Does anybody have a solution that still works today and in the indicated environment?

推荐答案

从具有图标的WPF应用程序创建对话框窗口时,上述操作无效。
但是,当添加以下两行时,图标会从对话框窗口中正确消失:

The above does not work, when creating a dialog window from a WPF application having an icon. However, when adding the following two lines, the icon correctly vanishes from the dialog window:

SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);

(sa https://connect.microsoft.com/VisualStudio/feedback/details/745230/wpf-window-cannot-be-displayed-without -titlebar-icon

这篇关于隐藏WPF窗口中的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆