在全屏模式下,C#覆盖在vlc播放器顶部的pictureBox

时间:2018-04-26 01:53:59

标签: c# winforms overlay vlc

我希望在Windows窗体应用程序中以全屏模式显示VLC播放器前面的pictureBox。

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

我尝试了这种方法和另一种方法(Draw semi transparent overlay image all over the windows form having some controls),它使用Windows窗体弹出它,但它只出现在全屏幕后面。

如果有人愿意分享他们的解决方案,我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

感谢@Jimi,他建议我使用hook方法,它工作得很好,下面是我的代码希望可以帮助别人。

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();
    }

}