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

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

问题描述

众所周知,如果 wpf 窗口的图标未定义,则显示默认图标.我想在标题栏中显示一个没有任何图标的窗口.我意识到我可以使用空白图像,但这会导致标题栏中的文本向右偏移.

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天全站免登陆