views:

2494

answers:

4

I'm not talking about the vista glass feature, I already know how to accomplish that. The feature that I'm talking about is add controls to the titlebar, like office 2007 does with the logo and toolbar.

+2  A: 

I've used the DotNetBar control suite with good success.

Andrew
I would but it cost, alot!
Lucas McCoy
+16  A: 

You need to do some Win32 interop to achieve that effect. Depending on whether you are using Winforms or WPF, the way you hook to the message processing differs (I don't remember Winforms, so I'll give all examples for WPF). But in both cases, you need to:

  1. Intercept the creation of the window and modify the window styles and extended styles. In WPF you need to inherit from HwndSource and modify the HwndSourceParameters in order to achieve this. You need WS_OVERLAPPEDWINDOW, WS_CLIPSIBLINGS and WS_VISIBLE for regular style and WS_EX_WINDOWEDGE and WS_EX_APPWINDOW extended styles.

  2. Add a message handler throught he HwndSource parameters HwndSourceHook.

  3. In the message proc added through the hook in step two, you need to process several messages:

    • WM_NCACTIVATE - to change the painting of the title when the app is activated or not
    • WM_NCCALCSIZE - to return to the OS that you don't have non-client areas
    • WM_NCPAINT - in general you need to invaldate the window rect only here, the WPF will take care of the actual painting)
    • WM_NCHITTEST - to process the moving of the window, minimizing and maximizing.
  4. Once you do the above, your client area where WPF is going to paint your visual tree is going to span the whole area of the window. You will need to add the "non-cliet" visuals so that your application looks like a regular application to the user.

  5. You might need several more messages:

    • WM_THEMECHANGED if you want to change your "non-client" area painting to be consistent with the OS theme
    • WM_DWMCOMPOSITIONCHANGED if you want to extend glass and get the standard OS NC-glass painting when glass is enabled and switch to your custom logic when glass is not.
  6. You might want to look at the Win32 Theme APIs if you want go get the standard Win32 assets for borders, caption, close, mininmize and maximize buttons to use in your 'non-client" area.

  7. If you want to extend Glass into your window, you can look at:

    • DwmExtendFrameIntoClientArea - to get the standard glass NC-area
    • DwmDefWindowProc - to get the desktop manager to paint Glass and the standard NC controls
    • DwmIsCompositionEnabled - to determine if Glass is enabled; you can use the above two APIs only when Glass is enabled. If Glass is not enabled, you need to do your own drawing of the NC area.

You can find the proper C# definitions of all messages, styles and corresponding Win32 APIs you need on P/Invoke.

You could also achieve similar effect by using standard WPF window with a WindowStyle=none. However, there will be some differences between the behavior of the desktop towards your app and other apps; most obvious of them is that you won't be able to stack or tile your window by right-clicking on the taskbar.

You can also look into some third-party components that enable some of this functionality. I have not used any (as you can see, I am not scared of Win32 interop :-)), so I can't recommend you any particular.

Franci Penov
Do you know of any tutorials on this general topic?
Lucas McCoy
Not really. I was planning on writing one, but I never got to it, what with the 5-month old baby in the house and whatnot... :-)
Franci Penov
I was going to give the +15 to you but Mystere Man found a tutorial. Your information really helped me though and I love P/Invoke. Thanks ;-)
Lucas McCoy
+6  A: 

As Franci mentions, what you want is DwmExtendFrameIntoClientArea. Here's an example from Codeproject that shows how to do it.

http://www.codeproject.com/KB/dialog/AeroNonClientAreaButtons.aspx

Mystere Man
Note that when Glass is turned off, for example under TS or when the user switches to Vista basic, DwmExtendFrameIntoClientAre is not going to work.
Franci Penov
+5  A: 

Joe Castro, a WPF product team developer, has an MSDN code gallery project called "WPF Chrome" that can be used to create an office 2007-like UI (ie: controls that span both the client, and non-client areas of a window).

Find it here: http://code.msdn.microsoft.com/chrome

Shuft
awesome~~~~~~~~~~~~~~!
Robert Fraser