【问题标题】:C# overlay pictureBox on top of vlc player while in fullscreen mode在全屏模式下,C# 在 vlc 播放器上覆盖图片框
【发布时间】:2018-04-26 01:53:58
【问题描述】:

我想在 Windows 窗体应用程序中以全屏模式在 VLC 播放器前面显示图片框。

 `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 窗体弹出它,但它只出现在全屏后面。

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

【问题讨论】:

  • 这个问题太具体了,任何人都无法帮助您,而无需做任何工作以在 winforms 中显示 VLC ActiveX 插件,播放视频,然后切换到全屏。
  • 当您尝试其他方法时,发生了什么?为什么他们不够好?您是否尝试过创建一个新表单form.TopMost = true,将图片框放在那里?然后会发生什么?
  • @Warty 是的,我用from.TopMost = true 试过了,但还是一样,它只出现在全屏后面。
  • 那是因为全屏不只是一个无边框的窗口,就像游戏劫持了整个显示...
  • @RonBeyer 是的,它劫持了整个显示器,我找不到任何方法来劫持。

标签: c# winforms overlay vlc


【解决方案1】:

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    相关资源
    最近更新 更多