none
How to make WPF Borderless with WindowsFormHost object visible?

    Question

  • Hello eveyone,

    My requiremnt is to make WPF application as totally borderless, so to make this, I made WindoStyle=None, and AllowsTransperancy=True, Due to which my application is running as borderless.

    But my application has one object WindowsFormHost with hosting WindowsMediaPlayer. My problem is, when I sets the property AllowsTransperancy=True, Hosted object WindowsMediaPlayer is also going to transparant mode. When I double clicks , it showing the video what i want, but in normal mode of window, its getting transparant.

    So, can someone tell me, How to make WPF application as Borderless, with Hosted object visible.

    Note: I am using Visual Studio 2008 and VB.net language

    Thanks in Advance,
    Datta
    Thursday, April 02, 2009 1:15 PM

Answers

  • This is an old issue that Shetty had a detailed discussion in another thread:
    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6f9dd3b5-af92-4076-9b4e-1a770dd52f70/

    Per-pixel opacity is an entirely different painting model than the standard Win32 mechanism.  There is no WM_PAINT anymore.  Instead, the top-level window composes a bitmap and sends it to the OS to use as the visual representation of the window on screen.  Child windows are not drawn into this bitmap, and so they are not shown on the screen.  This is a general limitation of a WS_EX_LAYERED window when used via UpdateLayeredWindow().
    You may have some luck by using a top-level window with the WS_EX_LAYERED style (instead of child windows), and then positioning the window over its location in the WPF application.  Keeping the app window and this “fake” top-level aligned on the screen may be difficult.

    I confirmed this with our expert, Dwayne Need and here's what he had to say:
    This is a limitation of using WS_EX_LAYERED and UpdateLayeredWindow().  This form of layered windows does not support child windows.  This is a Win32 limitation, not a WPF limitation.  Child windows could be used with constant opacity (WS_EX_LAYERED and SetLayeredWindowAttributes) but WPF does not support that mode, as it is more restrictive (constant versus per-pixel opacity).
    Anyways, there are various ways to try and work around the limitation.  None are great.  Limitations like these are part of the motivation for a new generation of presentation APIs such as WPF.

    Possible solutions (various degrees of hackery):
    1)     Don’t host legacy child HWND controls.  Try to find a WPF equivalent.
    2)     Write a WPF equivalent of the HWND control (HTML content seems to be a popular request)
    3)     Don’t use per-pixel alpha.  Consider applying a HREGION instead.
    4)     Place your HWND control in a regular top-level window that has the app window as its owner.  Position the control window where you want it.
    5)     Use a timer and call Win32’s PrintWindow (or send a WM_PRINT) to capture the HWND control to a bitmap, and display that bitmap in WPF.
    6)     Try to wrap the containing window in a WS_EX_COMPOSITED window and respond to WM_PAINT to capture a bitmap and display the bitmap in WPF.
    7)   Hook the HWND control’s window proc and respond to WM_PAINT by capturing the bitmap and displaying it in WPF

    • Marked as answer by Tao Liang Monday, April 06, 2009 8:35 AM
    Monday, April 06, 2009 8:35 AM

All replies

  • Hi

    You can try set the background of Window to transparent like this.

    SolidColorBrush mySolidColorBrush = new SolidColorBrush(Colors.Gray);
    mySolidColorBrush.Opacity = 0.1;
    myWindow.Background = mySolidColorBrush;

    Or you can try to set the Opacity directly on Window class.

    Good luck.

    Yiling, MVP(Visual C++)
    Thursday, April 02, 2009 1:38 PM
  • Hi,

    Thanks for replying, but unfortunatly i was asking somthing different than ur answer.
    My intension is to make, window Borderless, without affecting transpercy of any other object.

    If we make WindowStyle=None, still it show defuault border to WPF window, so to hide that, is there any other way than AllowsTransperancy property, because if i change AllowsTransperancy  then its affecting transperancy of embeded ActiveX in WPF.

    Hope, you understood..

    Waiting for reply.
    Datta
    Friday, April 03, 2009 4:40 AM
  • This is an old issue that Shetty had a detailed discussion in another thread:
    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6f9dd3b5-af92-4076-9b4e-1a770dd52f70/

    Per-pixel opacity is an entirely different painting model than the standard Win32 mechanism.  There is no WM_PAINT anymore.  Instead, the top-level window composes a bitmap and sends it to the OS to use as the visual representation of the window on screen.  Child windows are not drawn into this bitmap, and so they are not shown on the screen.  This is a general limitation of a WS_EX_LAYERED window when used via UpdateLayeredWindow().
    You may have some luck by using a top-level window with the WS_EX_LAYERED style (instead of child windows), and then positioning the window over its location in the WPF application.  Keeping the app window and this “fake” top-level aligned on the screen may be difficult.

    I confirmed this with our expert, Dwayne Need and here's what he had to say:
    This is a limitation of using WS_EX_LAYERED and UpdateLayeredWindow().  This form of layered windows does not support child windows.  This is a Win32 limitation, not a WPF limitation.  Child windows could be used with constant opacity (WS_EX_LAYERED and SetLayeredWindowAttributes) but WPF does not support that mode, as it is more restrictive (constant versus per-pixel opacity).
    Anyways, there are various ways to try and work around the limitation.  None are great.  Limitations like these are part of the motivation for a new generation of presentation APIs such as WPF.

    Possible solutions (various degrees of hackery):
    1)     Don’t host legacy child HWND controls.  Try to find a WPF equivalent.
    2)     Write a WPF equivalent of the HWND control (HTML content seems to be a popular request)
    3)     Don’t use per-pixel alpha.  Consider applying a HREGION instead.
    4)     Place your HWND control in a regular top-level window that has the app window as its owner.  Position the control window where you want it.
    5)     Use a timer and call Win32’s PrintWindow (or send a WM_PRINT) to capture the HWND control to a bitmap, and display that bitmap in WPF.
    6)     Try to wrap the containing window in a WS_EX_COMPOSITED window and respond to WM_PAINT to capture a bitmap and display the bitmap in WPF.
    7)   Hook the HWND control’s window proc and respond to WM_PAINT by capturing the bitmap and displaying it in WPF

    • Marked as answer by Tao Liang Monday, April 06, 2009 8:35 AM
    Monday, April 06, 2009 8:35 AM