在全屏模式下,在VLC播放器顶部的C#覆盖图片框



我想在Windows表单应用程序中以全屏模式显示VLC播放器的图片框。

 `if(axVLCPlugin21.video.fullscreen == true)
        {
            Debug.WriteLine("Is fullscreen");
            pictureBox2.BringToFront();
            pictureBox2.Focus();
            pictureBox2.Show();
        }`

我尝试了此方法和另一种方法(在窗口表单上绘制半透明覆盖图像具有某些控件(,该方法使用Windows表单弹出它,但仅出现在完整屏幕的后面。

如果有人愿意分享他们的解决方案。

感谢@jimi建议我使用钩方法,并且它效果很好,以下是我的代码希望可以帮助他人。

public partial class Test : Form
{
    private IntPtr testPic;
    private IntPtr hWinEventHook;
    private Process Target;
    private WinApi.RECT rect = new WinApi.RECT();
    protected Hook.WinEventDelegate WinEventDelegate;
    public Test(Form toCover, AxAXVLC.AxVLCPlugin2 ply)
    {
        InitializeComponent();
        WinEventDelegate = new Hook.WinEventDelegate(WinEventCallback);
        this.SetTopLevel(true);
        this.TopMost = true;
        this.ControlBox = false;
        this.ShowInTaskbar = false;
        this.StartPosition = FormStartPosition.Manual;
        this.AutoScaleMode = AutoScaleMode.None;
        this.Show(toCover);
        toCover.Focus();
        try
        {
            Target = Process.GetProcessesByName("TestPlayer").FirstOrDefault(p => p != null);
            if (Target != null)
            {
                testPic = Target.MainWindowHandle;
                uint TargetThreadId = Hook.GetWindowThread(testPic);
                if (testPic != IntPtr.Zero)
                {
                    hWinEventHook = Hook.WinEventHookOne(Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE,
                                                         WinEventDelegate,
                                                         (uint)Target.Id,
                                                         TargetThreadId);
                    rect = Hook.GetWindowRect(testPic);
                }
                if (ply.video.fullscreen == true) 
                {
                    Debug.WriteLine("yes is ");
                    this.WindowState = FormWindowState.Maximized;
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    protected void WinEventCallback(IntPtr hWinEventHook,
                                Hook.SWEH_Events eventType,
                                IntPtr hWnd,
                                Hook.SWEH_ObjectId idObject,
                                long idChild,
                                uint dwEventThread,
                                uint dwmsEventTime)
    {
        if (hWnd == testPic &&
            eventType == Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE &&
            idObject == (Hook.SWEH_ObjectId)Hook.SWEH_CHILDID_SELF)
        {
            WinApi.RECT rect = Hook.GetWindowRect(hWnd);
            //this.Location = new System.Drawing.Point(rect.Left, rect.Top);
        }
    }
    private void Overlay_FormClosing(object sender, FormClosingEventArgs e)
    {
        Hook.WinEventUnhook(hWinEventHook);
    }
    private void Overlay_FormShown(object sender, EventArgs e)
    {
        this.BeginInvoke(new Action(() => this.Owner.Activate()))
        this.Location = toCover.PointToScreen(System.Drawing.Point.Empty);
        if (Target == null)
        {
            this.Hide();
            MessageBox.Show("Player not found!", "Target Missing", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            this.Close();
        }
    }
    private const int DWMWA_TRANSITIONS_FORCEDISABLED = 3;
    [DllImport("dwmapi.dll")]
    private static extern int DwmSetWindowAttribute(IntPtr hWnd, int attr, ref int value, int attrLen);
    private void Test_load(object sender, EventArgs e)
    {
        this.CenterToScreen();
        this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y); 
    }
    private void closeFullScreen_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }
}

最新更新