Chrome Style C# Applications?

前端 未结 4 805
后悔当初
后悔当初 2020-12-12 21:27

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

相关标签:
4条回答
  • 2020-12-12 21:53

    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

    0 讨论(0)
  • 2020-12-12 21:54

    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

    0 讨论(0)
  • 2020-12-12 22:00

    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.

    0 讨论(0)
  • 2020-12-12 22:00

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

    0 讨论(0)
提交回复
热议问题