-2

I'm building a small .NET desktop app with C#. I have a video playing on topmost window (System.Windows) where we can control transparency of the Media Element and Window so we can see all windows below of this window.

My goal is to get mouse and keyboard events through this topmost window for all windows below. User like to play the video and work with other window same time.

We are making our Mac OS version for Windows users.

I can do that on Mac OS by this property.

self.ignoresMouseEvents = true;

This is my video player window.

<Window x:Class="VideoPlayerWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:SSAPlayerApp"
    mc:Ignorable="d" 
    Title="VideoPlayerWindow" Height="450" Width="800"
    WindowStartupLocation="CenterScreen" AllowsTransparency="True" 
    WindowStyle="None" Topmost="True" ShowActivated="False" MouseDown="Window_MouseDown" KeyDown="Window_KeyDown">

<MediaElement x:Name="player" Width="450" Height="250" MouseDown="Window_MouseDown" KeyDown="Window_KeyDown" LoadedBehavior="Manual" MediaOpened="player_MediaOpened" MediaEnded="player_MediaEnded" MediaFailed="player_MediaFailed"/>

Can anybody help?

Here is the Mac OS answer App window on top of all windows including others app windows

1 Answers1

-1

I found the piece of code I needed

   [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
    private static extern int GetWindowLongPtr(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
    private static extern int SetWindowLongPtr(IntPtr hWnd, int nIndex, int dwNewLong);

    const int GWL_EXSTYLE = -20;
    const int WS_EX_Transparent = (int) 0x00000020L;

    private void Window_SourceInitialized(object sender, EventArgs e)
    {
        IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
        int extendedStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);

        SetWindowLongPtr(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_Transparent);
    }

And Window must have SourceInitialized event. The DLL import and entry point will work for both 32-bit and 64-bit.

Now my MediaElement which is a child of the Window, both passing all the mouse and keyboard events (did not test touch event) to all windows and app below to my Window.