是否可以在标题栏中显示没有图标的wpf窗口? [英] Is it possible to display a wpf window without an icon in the title bar?

查看:628
本文介绍了是否可以在标题栏中显示没有图标的wpf窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,如果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屋!

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