Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

c# - Draw Custom Buttons on Windows Vista/7 Aero Titlebar

I found this question on StackOverflow. Basically, the user wanted to draw custom buttons on the titlebar.

I tried the code and realised it works in vista/7 only when Aero is disabled. My question is, is there any way to draw custom buttons on the titlebar while aero is enabled?

Also, is there any way of reading information from the current theme so I can style my buttons to match the already existing ones.


Update

Here is a screenshot from my computer demonstrating the above concept. I got the additional titlebar buttons after installing DisplayFusion.
Notepad2 showing additional buttons.

And I know DisplayFusion is a .NET program because it opens in .NET Reflector. The down side is that the program is obfuscated. Not like I wanted to decompile the program or anything; I just want to add a button to my titlebar to do something else (like minimise to the system tray for instance).
Below is the screenshot, proving the program is a .NET app.
.NET Reflector showing DisplayFusion

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As long as you're willing to redraw the entire title-bar contents, then you can use the DWM API's DwmExtendFrameIntoClientArea method, which involves setting your window to have no titlebar, allowing the DWM to draw its glass into your usable area to create a new space that looks like the titlebar but is in fact in your client area, so that you can draw buttons onto it.

The downside of this method is that you'll have to make the standard buttons if you want them. Minimize, Maximize and Close are no problem to recreate (though you'll find that the maximize button is a togglebutton with appearance based on the state), but you might find you have issue with recreating the top-left corner button. You'll also have to redraw your title, of course, but I can't imagine you'll have any issue with that.

As for reading the current theme's data back to restyle your buttons as theirs, I'm sorry but I don't know anything about that. My suggestion would be to use transparency when building your buttons onto the titlebar, and to use translucent glow-effects, etcetera. That way you'll be able to retain the glass background, and simply modify its appearance by overlaying a translucent colour. Also, if you do it this way, then the shifting specular highlights on the glass will move naturally, whereas if you simply got their theme colours you'd find either that you didn't get access to their reflections or that they recreated afresh within the space of your buttons. Just my two cents, of course - if you can find a way to do your theme colours etcetera, by all means.

There's one caveat to this though - there's another StackOverflow thread (http://stackoverflow.com/questions/2666979/net-framework-4-0-and-drawing-on-aero-glass-issue/4656182#4656182) which is describing an issue with the DWM API DwmExtendFrameIntoClientArea method, so if I were you, I'd read through that before trying this solution.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...