使用IVMRWindowlessControl在Winforms控件中显示视频并允许全屏切换

使用IVMRWindowlessControl在Winforms控件中显示视频并允许全屏切换,winforms,video,rendering,directshow,fullscreen,Winforms,Video,Rendering,Directshow,Fullscreen,我最近在自定义Winforms控件中从使用IVideoWindow界面切换到IVMRWindowlessControl来显示视频 这样做的原因是允许在控件内对视频进行缩放。 但是,在切换过程中,我发现IVideoWindow的全屏模式不可用,我目前正尝试使用SetVideoWindow()方法复制此模式 我发现我的控件中的视频大小与屏幕的分辨率相同,但是我无法使控件将自身定位到屏幕的顶部/左侧,并成为最顶部的窗口 由于IVideoWindow::put_FullScreenMode为您完成了这一

我最近在自定义Winforms控件中从使用IVideoWindow界面切换到IVMRWindowlessControl来显示视频

这样做的原因是允许在控件内对视频进行缩放。
但是,在切换过程中,我发现IVideoWindow的全屏模式不可用,我目前正尝试使用SetVideoWindow()方法复制此模式

我发现我的控件中的视频大小与屏幕的分辨率相同,但是我无法使控件将自身定位到屏幕的顶部/左侧,并成为最顶部的窗口


由于IVideoWindow::put_FullScreenMode为您完成了这一切,您对如何实现这一点有何想法?

以新的形式托管视频控件,解决了全屏问题,我将其调整为当前屏幕的大小,然后处理表单中的“Escape”键,以切换回正常大小的视频。下面是代码的摘录:-

成员

    private Rectangle fullScreenRectangle;
    private bool fullScreen;
    private Form fullScreenForm;
    private Control fullScreenParent;
切换全屏代码

    /// <summary>
    /// Toggle Full Screen Mode
    /// </summary>
    public bool FullScreen
    {
        get
        {
            return this.fullScreen;
        }
        set
        {
            this.fullScreen = value;

            if (this.fullScreen)
            {
                // If switch to full screen, save the current size of the control
                this.fullScreenRectangle = new Rectangle(this.Location, this.Size);

                // Get the current screen resolution and set that to be the control's size
                Rectangle screenRect = Screen.GetBounds(this);

                // Create a new form on which to host the control whilst we go to full screen mode.
                this.fullScreenForm = new Form();
                this.fullScreenForm.Location = PointToScreen(new Point(0, 0));
                this.fullScreenForm.Size = new Size(screenRect.Width, screenRect.Height);
                this.fullScreenForm.BackColor = Color.Black;
                this.fullScreenForm.ShowInTaskbar = false;
                this.fullScreenForm.ShowIcon = false;
                this.fullScreenForm.FormBorderStyle = FormBorderStyle.None;
                this.fullScreenForm.KeyPreview = true;
                this.fullScreenForm.PreviewKeyDown += new PreviewKeyDownEventHandler(fullScreenForm_PreviewKeyDown);
                this.fullScreenParent = this.Parent;
                this.fullScreenForm.Controls.Add(this);
                this.fullScreenForm.Show();

                this.windowlessControl.SetVideoPosition(null, screenRect);
            }
            else
            {
                // Revert to the original control size
                this.Location = PointToScreen(new Point(this.fullScreenRectangle.Left, this.fullScreenRectangle.Top));
                this.Size = new Size(this.fullScreenRectangle.Width, this.fullScreenRectangle.Height);

                this.windowlessControl.SetVideoPosition(null, this.fullScreenRectangle);

                if (this.fullScreenForm != null)
                {
                    this.fullScreenForm.Controls.Remove(this);

                    if (this.fullScreenParent != null)
                        this.Parent = this.fullScreenParent;

                    this.fullScreenForm.PreviewKeyDown -= new PreviewKeyDownEventHandler(fullScreenForm_PreviewKeyDown);
                    this.fullScreenForm.Close();
                }
            }
        }
    }

    void fullScreenForm_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        if (e.KeyCode == Keys.Escape)
        {
            var viewer = this.Controls[0] as ViewerControl;

            if (viewer != null)
                viewer.FullScreen = false;
        }
    }
//
///切换全屏模式
/// 
全屏公共广播
{
得到
{
返回此文件。全屏显示;
}
设置
{
this.fullScreen=值;
如果(这是全屏)
{
//如果切换到全屏,保存控件的当前大小
this.fullScreenRectangle=新矩形(this.Location,this.Size);
//获取当前屏幕分辨率并将其设置为控件的大小
矩形screenRect=Screen.GetBounds(这个);
//创建一个新窗体,在进入全屏模式时在其上托管控件。
this.fullScreenForm=新表单();
this.fullScreenForm.Location=指向屏幕的点(新点(0,0));
this.fullScreenForm.Size=新尺寸(screenRect.Width、screenRect.Height);
this.fullScreenForm.BackColor=Color.Black;
this.fullScreenForm.ShowInTaskbar=false;
this.fullScreenForm.ShowIcon=false;
this.fullScreenForm.FormBorderStyle=FormBorderStyle.None;
this.fullScreenForm.KeyPreview=true;
this.fullScreenForm.PreviewKeyDown+=新的PreviewKeyDownEventHandler(fullScreenForm\u PreviewKeyDown);
this.fullScreenParent=this.Parent;
this.fullScreenForm.Controls.Add(this);
这个.fullScreenForm.Show();
this.windowlessControl.SetVideoPosition(null,screenRect);
}
其他的
{
//恢复到原始控件大小
this.Location=PointToScreen(新点(this.fullScreenRectangle.Left,this.fullScreenRectangle.Top));
this.Size=新大小(this.fullScreenRectangle.Width,this.fullScreenRectangle.Height);
this.windowlessControl.SetVideoPosition(null,this.fullScreenRectangle);
if(this.fullScreenForm!=null)
{
this.fullScreenForm.Controls.Remove(this);
如果(this.fullScreenParent!=null)
this.Parent=this.fullScreenParent;
this.fullScreenForm.PreviewKeyDown-=新的PreviewKeyDownEventHandler(fullScreenForm_PreviewKeyDown);
这个.fullScreenForm.Close();
}
}
}
}
void fullScreenForm_PreviewKeyDown(对象发送方,PreviewKeyDownEventArgs e)
{
if(e.KeyCode==Keys.Escape)
{
var viewer=this.Controls[0]作为ViewerControl;
如果(查看器!=null)
viewer.FullScreen=false;
}
}

解决了全屏问题,以新的形式托管视频控件,我将其大小调整为当前屏幕的大小,然后处理表单中的“Escape”键,以切换回正常大小的视频。下面是代码的摘录:-

成员

    private Rectangle fullScreenRectangle;
    private bool fullScreen;
    private Form fullScreenForm;
    private Control fullScreenParent;
切换全屏代码

    /// <summary>
    /// Toggle Full Screen Mode
    /// </summary>
    public bool FullScreen
    {
        get
        {
            return this.fullScreen;
        }
        set
        {
            this.fullScreen = value;

            if (this.fullScreen)
            {
                // If switch to full screen, save the current size of the control
                this.fullScreenRectangle = new Rectangle(this.Location, this.Size);

                // Get the current screen resolution and set that to be the control's size
                Rectangle screenRect = Screen.GetBounds(this);

                // Create a new form on which to host the control whilst we go to full screen mode.
                this.fullScreenForm = new Form();
                this.fullScreenForm.Location = PointToScreen(new Point(0, 0));
                this.fullScreenForm.Size = new Size(screenRect.Width, screenRect.Height);
                this.fullScreenForm.BackColor = Color.Black;
                this.fullScreenForm.ShowInTaskbar = false;
                this.fullScreenForm.ShowIcon = false;
                this.fullScreenForm.FormBorderStyle = FormBorderStyle.None;
                this.fullScreenForm.KeyPreview = true;
                this.fullScreenForm.PreviewKeyDown += new PreviewKeyDownEventHandler(fullScreenForm_PreviewKeyDown);
                this.fullScreenParent = this.Parent;
                this.fullScreenForm.Controls.Add(this);
                this.fullScreenForm.Show();

                this.windowlessControl.SetVideoPosition(null, screenRect);
            }
            else
            {
                // Revert to the original control size
                this.Location = PointToScreen(new Point(this.fullScreenRectangle.Left, this.fullScreenRectangle.Top));
                this.Size = new Size(this.fullScreenRectangle.Width, this.fullScreenRectangle.Height);

                this.windowlessControl.SetVideoPosition(null, this.fullScreenRectangle);

                if (this.fullScreenForm != null)
                {
                    this.fullScreenForm.Controls.Remove(this);

                    if (this.fullScreenParent != null)
                        this.Parent = this.fullScreenParent;

                    this.fullScreenForm.PreviewKeyDown -= new PreviewKeyDownEventHandler(fullScreenForm_PreviewKeyDown);
                    this.fullScreenForm.Close();
                }
            }
        }
    }

    void fullScreenForm_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        if (e.KeyCode == Keys.Escape)
        {
            var viewer = this.Controls[0] as ViewerControl;

            if (viewer != null)
                viewer.FullScreen = false;
        }
    }
//
///切换全屏模式
/// 
全屏公共广播
{
得到
{
返回此文件。全屏显示;
}
设置
{
this.fullScreen=值;
如果(这是全屏)
{
//如果切换到全屏,保存控件的当前大小
this.fullScreenRectangle=新矩形(this.Location,this.Size);
//获取当前屏幕分辨率并将其设置为控件的大小
矩形screenRect=Screen.GetBounds(这个);
//创建一个新窗体,在进入全屏模式时在其上托管控件。
this.fullScreenForm=新表单();
this.fullScreenForm.Location=指向屏幕的点(新点(0,0));
this.fullScreenForm.Size=新尺寸(screenRect.Width、screenRect.Height);
this.fullScreenForm.BackColor=Color.Black;
this.fullScreenForm.ShowInTaskbar=false;
this.fullScreenForm.ShowIcon=false;
this.fullScreenForm.FormBorderStyle=FormBorderStyle.None;
this.fullScreenForm.KeyPreview=true;
this.fullScreenForm.PreviewKeyDown+=新的PreviewKeyDownEventHandler(fullScreenForm\u PreviewKeyDown);
this.fullScreenParent=this.Parent;
this.fullScreenForm.Controls.Add(this);
这个.fullScreenForm.Show();
this.windowlessControl.SetVideoPosition(null,screenRect);
}
其他的
{
//恢复到原始控件大小
this.Location=PointToScreen(新点(this.fullScreenRectangle.Left,this.fullScreenRectangle.Top));
this.Size=新大小(this.fullScreenRectangle.Width,th