简体   繁体   English

更改最小化,关闭和最大化窗口的图标

[英]Change the icon of the window of the minimize, close and maximize

Simple question. 简单的问题。 How can I change the icons of the close, minimize, maximize buttons. 如何更改关闭,最小化,最大化按钮的图标。 Can I do this in Winforms and WPF? 我可以在Winforms和WPF中执行此操作吗?

These Icons, the caption, and the border on your window are all drawn while processing the WM_NCPAINT message. 处理WM_NCPAINT消息时,将绘制窗口上的这些图标,标题和边框。 So, the way you take over drawing this is by handling this message. 因此,您接管绘制此方法的方法是处理此消息。

But you don't have access to the state information about the icons (ie which button you should draw in it's pressed state because the user is currently clicking on it.). 但是您无法访问有关图标的状态信息(即,您应该在其按下状态下绘制哪个按钮,因为用户当前正在点击它)。 You dont even know where exactly the mouse handling code thinks these icons are. 你甚至不知道鼠标处理代码到底认为这些图标的确切位置。

So to take over non-client paint, you also need to take over non-client mouse handling, and the whole problem just snowballs until you've written thousands of lines of code and your window still doesn't behave quite right when the user tries to drag it, etc. 因此,要接管非客户端绘制,您还需要接管非客户端鼠标处理,并且整个问题只是滚雪球,直到您编写了数千行代码并且您的窗口在用户时仍然表现不正常试图拖动它等

And that's in unmanaged code, in managed code (C#/.Net) this is even harder because you also have to do interop to get to some of the APIs you need to use. 这是在非托管代码中,在托管代码(C#/ .Net)中,这甚至更难,因为您还必须进行互操作以获取您需要使用的某些API。

So the answer is: Yes its possible, but its harder in WinForms and WPF than it is in C++, and those that have attempted it are all bald now. 所以答案是:是的,它可能,但在WinForms和WPF中比在C ++中更难,而那些尝试过它的人现在都很秃顶。

The real answer is that you shouldn't do this. 真正的答案是你不应该这样做。 Users expect all applications to work and look the same. 用户希望所有应用程序都能正常工作。 Making them try an figure out what spiffy new icon you use means minimize is likely to make them unhappy. 让他们尝试弄清楚你使用什么漂亮的新图标意味着最小化可能会让他们不高兴。

Doing this isn't difficult but it is a lot of work - you have to basically replace the window frame and handle everything yourself, there is a lot of functionality in the default window frame you have to rewrite - you also have to write different code for Vista/7 with Aero enabled. 这样做并不困难,但需要做很多工作 - 你必须自己更换窗口框架并自己处理所有内容,默认窗口框架中有很多功能你必须重写 - 你还必须编写不同的代码适用于启用了Aero的Vista / 7。

In WPF you use the various techniques in http://blogs.msdn.com/wpfsdk/archive/2008/09/08/custom-window-chrome-in-wpf.aspx 在WPF中,您可以使用http://blogs.msdn.com/wpfsdk/archive/2008/09/08/custom-window-chrome-in-wpf.aspx中的各种技术。

In WinForms you use the same basic techniques but I don't know of a page that summarizes all the details like the link above. 在WinForms中,您使用相同的基本技术,但我不知道一个页面总结了所有细节,如上面的链接。

In wpf, you can set WindowStyle="None" for your Window and then set a custom TitleBar for that, with minimize, maximize and close button. 在wpf中,您可以为Window设置WindowStyle="None" ,然后为其设置自定义TitleBar,使用最小化,最大化和关闭按钮。 I have done this earlier. 我之前做过这个。 You need to do some event handling to perform minimize, maximize, close, drag etc. 您需要执行一些事件处理以执行最小化,最大化,关闭,拖动等操作。

If you want to control the look of those buttons, you'll have to create your own. 如果要控制这些按钮的外观,则必须创建自己的按钮。 This is one value of using Windows features to write windows applications (they come with a standard look and feel). 这是使用Windows功能编写Windows应用程序的一个价值(它们具有标准的外观和感觉)。

Yes, you have to create your own window style. 是的,你必须创建自己的窗口样式。 Refer to FluidKit , GlassWindows for example. 例如,请参阅FluidKit ,GlassWindows。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM