3

I am looking for a way to add buttons to a form's control box. I don't care in which language it is, but I'd love to have it in .NET (C#, VB.NET or C++).


Yes, I have seen this and none of the solutions in the answer work, at least for Windows 7. And yes, I know this one too, it works, but I am looking for a more natural/native way, if there is.

Community
  • 1
  • 1
Vercas
  • 8,931
  • 15
  • 66
  • 106
  • A more natural way? What does that mean? Customization of a Windows caption bar has always been fugly. This is likely intentional because Microsoft has always encouraged developers to create applications that work in a standard way. In other words, messing with the caption bar is not recommended. That doesn't mean you can't. It just means you have to do it the hard way. – Tergiver Dec 18 '10 at 14:17
  • I am just trying to make the boring "minimize to tray" button and I currently find it very difficult... – Vercas Dec 18 '10 at 15:13

2 Answers2

1

As Tergiver says in his comment, there's no nice way of doing this, and I'd recommend that in most circumstances it shouldn't be done at all since it'll be really non-standard and confusing to the users.

However, if you do really need to do it, then I think that the way to do it would be to listen for the WM_NCPAINT message (inside WndProc) and when you get one of those you paint your own button manually. Then you'll have to listen out for mouse events in the area where your button has been drawn and handle those clicks manually also.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
  • Thanks for the tip, but can I paint in the non-client area with a normal graphics object? – Vercas Dec 18 '10 at 15:04
  • @Vercas: I think so, but I'm not sure if you need to do anything special, it's been a while since I did anything advanced graphical. – Hans Olsson Dec 18 '10 at 15:24
  • I already know how to track the mouse so I can build my events, but all I need is to draw an image on a specified point on the control box. – Vercas Dec 18 '10 at 15:28
  • Check the docs: http://msdn.microsoft.com/en-us/library/dd145212.aspx. It shows how to obtain a DC to paint with. – Tergiver Dec 19 '10 at 15:59
  • Thanks, @Tergiver, but do you have any C# version? :( – Vercas Dec 21 '10 at 17:51
1

An alternate way could be having a border less form and put your own TitleBar. Like shown here :

gTitleBar on CodeProject

Omie
  • 190
  • 3
  • 12
  • You can extend Aero glass into the client area of a window. http://www.codeproject.com/KB/vista/AeroGlassForms.aspx?display=Print. Not personally familier with that article, I googled it. – Tergiver Dec 18 '10 at 18:57