none
WindowsFormsHost and AllowsTransparency makes all win32 controls transparent

    Question

  • If I set AllowsTransparency=True on a form, all of my WindowsFormsHost controls become invisible. These controls obviously don't have an opacity property, it there anything I can do to get these controls visible ?

     

    (June CTP)

     

    Mark

    Wednesday, July 19, 2006 9:02 PM

Answers

  • 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.
    Friday, July 21, 2006 9:17 PM
    Moderator

All replies

  • Hey Mark, I also stuck with same problem :(

    Do you get any idea to solve the problem

     

    Cheers,

    A. Kahn

    Friday, July 21, 2006 12:42 PM
  • 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.
    Friday, July 21, 2006 9:17 PM
    Moderator
  • Ashish,

    Thanks for the answer. I'll just make do without the transparent border for the moment :)

     Please consider warning users when they do this. it took me a little while to diagnose.

     

    Thanks,

     

    Mark

    Sunday, July 23, 2006 9:36 PM
  • Hi there

    We are also experiencing this problem, and in our situation getting around this is a very critical thing.  Is there a way to get around this problem?  Is this going to be fixed in the next release of WinFX?  We would like to know what the plans are for this particular issue.

    Thank you!

    Bridgette
    www.k2workflow.com

    Tuesday, July 25, 2006 5:07 PM
  • Hi there

    We are also experiencing this problem, and in our situation getting around this is a very critical thing.  Is there a way to get around this problem?  Is this going to be fixed in the next release of WinFX?  We would like to know what the plans are for this particular issue.

    Thank you!

    Bridgette
    www.k2workflow.com

    Tuesday, July 25, 2006 5:08 PM
  • 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

     

    Tuesday, July 25, 2006 9:54 PM
    Moderator
  • Hello

    I have this problem

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1073648&SiteID=1&mode=1

    is it the same?

    if it does can u give some code to demonstrate the solutions for those of us who have not familiar with what you written?

    Thanx Itzik

     Solved my problem thanx anyway

    Thursday, January 04, 2007 1:15 PM
  • Asish,

    We are experiencing the same problems as others have mentioned here. We are a COTS vendor and we use an Active-X control which runs opengl. We run pretty much realtime with a refresh delta of about once every tenth of a second. None of the solutions you have mentioned seem viable in our situation. Are there any plans for changing the way the WindowsFormsHost element works or any other solutions in the works for this problem? This is a setback for us updating our exisiting application over to WPF.

    Thanks,

    -Joe

    • Proposed as answer by Sofien Gnawi Friday, May 04, 2012 5:22 PM
    Thursday, January 18, 2007 8:23 AM
  • hi every body ,  if it s not possible to show the windowsformsHost while allawTransparency=true ,so is there any other way to solve this problem ?? there must be a solution or a trick .. do anybody figure it out ?? did Microsoft considered  this WPF limitation in later versions of VS ?? Does anybody know if microsoft has a straight forward solution for this issue in 4.0? please i need help ! thanx for answer :)
    Friday, May 04, 2012 5:23 PM