如何在WPF应用程序中托管Flash内容并使用透明度?

时间:2022-06-19 06:33:12

How can I go about hosting flash content inside a WPF form and still use transparency/alpha on my WPF window? Hosting a WinForms flash controls does not allow this.

如何在WPF表单中托管Flash内容并在我的WPF窗口中仍然使用透明度/ alpha?托管WinForms Flash控件不允许这样做。

4 个解决方案

#1


2  

Unless the control you use to display the Flash content is built in WPF, you will run in to these "airspace" issues. Every display technology from Win32 to WinForms used HWNDs "under the hood", but WPF uses DirectX. The Window Manager in Windows however, still only understands HWNDs, so WPF apps have one top-level HWND-based window, and everything under that is done in DirectX (actually things like context menus and tooltips also have top-level HWNDs as well). Adam Nathan has a very good description of WPF interop in this article.

除非用于显示Flash内容的控件是在WPF中构建的,否则您将遇到这些“空域”问题。从Win32到WinForms的每种显示技术都在“引擎盖下”使用了HWND,但WPF使用DirectX。然而,Windows中的Window Manager仍然只能理解HWND,因此WPF应用程序有一个基于HWND的*窗口,其下的所有内容都在DirectX中完成(实际上上下文菜单和工具提示也有*HWND) 。 Adam Nathan在本文中对WPF互操作有很好的描述。

#2


1  

Although I haven't done it, you can probably use the WebBrowser control found in WPF 3.5 sp1 to wrap your Flash content within WPF. I'm not sure how the transparency will be affected though.

虽然我还没有这样做,但你可以使用WPF 3.5 sp1中的WebBrowser控件将你的Flash内容包装在WPF中。我不确定透明度会受到怎样的影响。

#3


0  

Can you use Expression to convert the flash content to XAML? I believe that there are tools in there or off to the side that do this.

您可以使用Expression将Flash内容转换为XAML吗?我相信有一些工具可以在这里或旁边执行此操作。

#4


-1  

Just have been struggling with same problem of how to upload & Make WPF transparent with ability of displaying Flash, because if you enable on your MainWindow "Allow transparency" Flash will not show once the application will run.

只是一直在努力解决如何上传和使WPF透明与显示Flash的能力相同的问题,因为如果你在MainWindow上启用“允许透明度”,一旦应用程序运行,Flash就不会显示。

1) I used WebBrowser Control to play Flash(.swf) files. They are on my PC, however it can play from internet or wherever you have hosted them. Don't forget to name your WebBrowser Control to get to it in C#.

1)我使用WebBrowser Control来播放Flash(.swf)文件。它们在我的电脑上,但它可以从互联网或任何你托管它们的地方播放。不要忘记命名您的WebBrowser控件以在C#中访问它。

 private void Window_Loaded(object sender, RoutedEventArgs e)
 {   
    MyHelper.ExtendFrame(this, new Thickness(-1));    
    this.MyBrowser.Navigate(@"C:\Happy\Download\flash\PlayWithMEGame.swf");         
 }

2) Now for transparency. I have set in WPF 'false' to "Allow Transparency" and set "Window Style" to 'None'. After that I have used information from HERE and HERE and created a following code that produced desired effect of allowing transparency on MainWindow and running Flash at same time, here is my code:

2)现在提高透明度。我已将WPF中的'false'设置为“允许透明度”并将“窗口样式”设置为“无”。之后我使用了HERE和HERE的信息并创建了以下代码,这些代码产生了在MainWindow上允许透明度并同时运行Flash的预期效果,这是我的代码:

public class MyHelper
{
    public static bool ExtendFrame(Window window, Thickness margin)
    {
        IntPtr hwnd = new WindowInteropHelper(window).Handle;
        window.Background = Brushes.Transparent;
        HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
        MARGINS margins = new MARGINS(margin);
        DwmExtendFrameIntoClientArea(hwnd, ref margins);
        return true;
    }
    [DllImport("dwmapi.dll", PreserveSig = false)]
    static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
}

 struct MARGINS
    {
        public MARGINS(Thickness t)
        {
            Left = (int)t.Left;
            Right = (int)t.Right;
            Top = (int)t.Top;
            Bottom = (int)t.Bottom;
        }
        public int Left;
        public int Right;
        public int Top;
        public int Bottom;
    }

And called it from Window_Loaded() + you need 'below' line for 'DllImport' to work.

并从Window_Loaded()+调用它,你需要'下面'行'DllImport'才能工作。

using System.Runtime.InteropServices;
using System.Windows.Interop;

#1


2  

Unless the control you use to display the Flash content is built in WPF, you will run in to these "airspace" issues. Every display technology from Win32 to WinForms used HWNDs "under the hood", but WPF uses DirectX. The Window Manager in Windows however, still only understands HWNDs, so WPF apps have one top-level HWND-based window, and everything under that is done in DirectX (actually things like context menus and tooltips also have top-level HWNDs as well). Adam Nathan has a very good description of WPF interop in this article.

除非用于显示Flash内容的控件是在WPF中构建的,否则您将遇到这些“空域”问题。从Win32到WinForms的每种显示技术都在“引擎盖下”使用了HWND,但WPF使用DirectX。然而,Windows中的Window Manager仍然只能理解HWND,因此WPF应用程序有一个基于HWND的*窗口,其下的所有内容都在DirectX中完成(实际上上下文菜单和工具提示也有*HWND) 。 Adam Nathan在本文中对WPF互操作有很好的描述。

#2


1  

Although I haven't done it, you can probably use the WebBrowser control found in WPF 3.5 sp1 to wrap your Flash content within WPF. I'm not sure how the transparency will be affected though.

虽然我还没有这样做,但你可以使用WPF 3.5 sp1中的WebBrowser控件将你的Flash内容包装在WPF中。我不确定透明度会受到怎样的影响。

#3


0  

Can you use Expression to convert the flash content to XAML? I believe that there are tools in there or off to the side that do this.

您可以使用Expression将Flash内容转换为XAML吗?我相信有一些工具可以在这里或旁边执行此操作。

#4


-1  

Just have been struggling with same problem of how to upload & Make WPF transparent with ability of displaying Flash, because if you enable on your MainWindow "Allow transparency" Flash will not show once the application will run.

只是一直在努力解决如何上传和使WPF透明与显示Flash的能力相同的问题,因为如果你在MainWindow上启用“允许透明度”,一旦应用程序运行,Flash就不会显示。

1) I used WebBrowser Control to play Flash(.swf) files. They are on my PC, however it can play from internet or wherever you have hosted them. Don't forget to name your WebBrowser Control to get to it in C#.

1)我使用WebBrowser Control来播放Flash(.swf)文件。它们在我的电脑上,但它可以从互联网或任何你托管它们的地方播放。不要忘记命名您的WebBrowser控件以在C#中访问它。

 private void Window_Loaded(object sender, RoutedEventArgs e)
 {   
    MyHelper.ExtendFrame(this, new Thickness(-1));    
    this.MyBrowser.Navigate(@"C:\Happy\Download\flash\PlayWithMEGame.swf");         
 }

2) Now for transparency. I have set in WPF 'false' to "Allow Transparency" and set "Window Style" to 'None'. After that I have used information from HERE and HERE and created a following code that produced desired effect of allowing transparency on MainWindow and running Flash at same time, here is my code:

2)现在提高透明度。我已将WPF中的'false'设置为“允许透明度”并将“窗口样式”设置为“无”。之后我使用了HERE和HERE的信息并创建了以下代码,这些代码产生了在MainWindow上允许透明度并同时运行Flash的预期效果,这是我的代码:

public class MyHelper
{
    public static bool ExtendFrame(Window window, Thickness margin)
    {
        IntPtr hwnd = new WindowInteropHelper(window).Handle;
        window.Background = Brushes.Transparent;
        HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
        MARGINS margins = new MARGINS(margin);
        DwmExtendFrameIntoClientArea(hwnd, ref margins);
        return true;
    }
    [DllImport("dwmapi.dll", PreserveSig = false)]
    static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
}

 struct MARGINS
    {
        public MARGINS(Thickness t)
        {
            Left = (int)t.Left;
            Right = (int)t.Right;
            Top = (int)t.Top;
            Bottom = (int)t.Bottom;
        }
        public int Left;
        public int Right;
        public int Top;
        public int Bottom;
    }

And called it from Window_Loaded() + you need 'below' line for 'DllImport' to work.

并从Window_Loaded()+调用它,你需要'下面'行'DllImport'才能工作。

using System.Runtime.InteropServices;
using System.Windows.Interop;