WPF实用指南二:移除窗体的图标

news/2024/7/4 23:07:55
原文:WPF实用指南二:移除窗体的图标

WPF没有提供任何功能来移除窗体上的icon图标。一般的做法是设置一个空白的图标,如下图1:

这种做法在窗体边框与标题之间仍然会保留一片空白。

比较好的做法是使用Win32API提供的函数来移除这个图标。使用如下的代码:

public static class IconHelper{[DllImport("user32.dll")]static extern int GetWindowLong(IntPtr hwnd, int index);[DllImport("user32.dll")]static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);[DllImport("user32.dll")]static extern bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,int x, int y, int width, int height, uint flags);[DllImport("user32.dll")]static extern IntPtr SendMessage(IntPtr hwnd, uint msg,IntPtr wParam, IntPtr lParam);const int GWL_EXSTYLE = -20;const int WS_EX_DLGMODALFRAME = 0x0001;const int SWP_NOSIZE = 0x0001;const int SWP_NOMOVE = 0x0002;const int SWP_NOZORDER = 0x0004;const int SWP_FRAMECHANGED = 0x0020;const uint WM_SETICON = 0x0080;public static void RemoveIcon(Window window){//获取窗体的句柄IntPtr hwnd = new WindowInteropHelper(window).Handle;//改变窗体的样式int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);//更新窗口的非客户区,以反映变化SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE |SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);}}
在窗体中只需重载OnSourceInitialized函数即可
protected override void OnSourceInitialized(EventArgs e){IconHelper.RemoveIcon(this);}
效果图:空白没有了。





http://lihuaxi.xjx100.cn/news/236346.html

相关文章

php 所有魔术方法,PHP常用的魔术方法及规则

转:https://www.cnblogs.com/wanglijun/p/10926303.html1. __construct 具有构造函数的类会在每次创建新对象时先调用此方法;初始化工作执行。2. __desstruct 对象的所有引用都被删除或者当对象被显式销毁时执行。3.__call()在对象中调用一个不可访问方法时&#xf…

Room Database完全使用手册

前言 Android数据持久层直接使用SQLite很麻烦,Google官方推出了Room, Google对Room的定义: The Room persistence library provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of …

软件工程技术基础-(软件复用技术)

软件可重用问题,包括源程序代码重用、静态库重用和组建重用。 源程序代码重用是直接将其他项目或系统开发完成的代码复制过来,直接使用。 限制源程序代码重用技术使用的关键因素是要考虑代码的语言实现,以及源代码 公开可能带来的知识产权问题…

php监听订单状态,ecshop数据库订单状态判断

order_info 表刚下完订单order_status 0shipping_status 0pay_status 0取消order_status 2shipping_status 0pay_status 0确认order_status 1shipping_status 0pay_status 0已付款order_status 1shipping_status 0pay_status 2配货中order_status 1shipping_status 3pay_status…

firefox下的调试工具

2019独角兽企业重金招聘Python工程师标准>>> vue-devtools https://addons.mozilla.org/en-US/firefox/user/13100848/ 转载于:https://my.oschina.net/u/3371661/blog/3003299

小编带你进入强如 Disruptor 也发生内存溢出?

前言OutOfMemoryError 问题相信很多朋友都遇到过,相对于常见的业务异常(数组越界、空指针等)来说这类问题是很难定位和解决的。 本文以最近碰到的一次线上内存溢出的定位、解决问题的方式展开;希望能对碰到类似问题的同学带来思路…

PHP上传文件函数move_upload,如何使用php中move_uploaded_file函数

我们平时上传的文件保存在临时文件夹中,例如/ tmp,但临时文件夹的内容在一段时间后会被删除,因此为了将来要使用上传文件,需要将内容保存在不太可能被任意删除的专用目录中,这时就需要使用move_uploaded_file函数&…

Dubbo2.6.5+Nacos注册中心(代替Zookeeper)

在上一节的小栗子的基础上&#xff0c;只需要更改两个地方 第一个&#xff1a;父工程的pom依赖增加 <!-- Dubbo Nacos registry dependency --><dependency><groupId>com.alibaba</groupId><artifactId>dubbo-registry-nacos</artifactId>…