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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With