是否可以在标题栏中显示没有图标的wpf窗口? [英] Is it possible to display a wpf window without an icon in the title bar?
本文介绍了是否可以在标题栏中显示没有图标的wpf窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道一个完全的方法删除图标?
(我尝试搜索类似的问题,但找不到任何东西。)
解决方案
简单的,将这段代码添加到你的窗口中:
[DllImport(user32.dll )]
static extern uint GetWindowLong(IntPtr hWnd,int nIndex);
[DllImport(user32.dll)]
static extern int SetWindowLong(IntPtr hWnd,int nIndex,uint dwNewLong);
private const int GWL_STYLE = -16;
private const uint WS_SYSMENU = 0x80000;
protected override void OnSourceInitialized(EventArgs e)
{
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
SetWindowLong(hwnd,GWL_STYLE,
GetWindowLong(hwnd,GWL_STYLE)&(0xFFFFFFFF ^ WS_SYSMENU));
base.OnSourceInitialized(e);
}
As we all know, if the icon for a wpf window is undefined then the default icon is displayed. I want to display a window without any icon in the title bar. I realise that I could use a blank image, however this would cause the text in the title bar to be offset to the right.
Does anyone know of a way to completely remove the icon?
(I tried searching for a similar question but couldn't find anything.)
解决方案
Simple, add this code to your window:
[DllImport("user32.dll")]
static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
private const int GWL_STYLE = -16;
private const uint WS_SYSMENU = 0x80000;
protected override void OnSourceInitialized(EventArgs e)
{
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE,
GetWindowLong(hwnd, GWL_STYLE) & (0xFFFFFFFF ^ WS_SYSMENU));
base.OnSourceInitialized(e);
}
这篇关于是否可以在标题栏中显示没有图标的wpf窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文