面板播放视频时不显示ContextMenuStrip

ptdanh392

新成员
已加入
2020年10月7日
留言内容
3
编程经验
1-3
我使用面板控件来播放视频文件,方法是单击鼠标右键以显示菜单,然后添加视频文件。第一次显示菜单,我添加视频文件,当面板控件运行视频时,再次单击鼠标以更改其他文件,Menustrip控件不显示
这是我的代码:

C#:
private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                RightContextMenuStrip.Show(new Point(MousePosition.X, MousePosition.Y));
            }
        }
请帮我解决这个问题。
 

金西尼

C#论坛主持人
工作人员
已加入
2011年4月23日
留言内容
3,501
地点
悉尼,澳大利亚
编程经验
10+
How 究竟 are you displaying this video? Are you sure that it's actually the Panel that you're clicking on the second time and not some other control that's hosting the video?
 

金西尼

C#论坛主持人
工作人员
已加入
2011年4月23日
留言内容
3,501
地点
悉尼,澳大利亚
编程经验
10+
我使用Medialooks SDK预览视频中的帧。
我强调了"EXACTLY" because I wanted specific details, i.e. the code or a detailed description of the code. 什么 I suspect is happening is that you are loading another control into the Panel and so subsequent clicks are occurring on that rather than the Panel.
我敢肯定,我会在面板预览视频后单击很多次。
在事件处理程序上设置一个断点。第一次之后会受到打击吗?
 

ptdanh392

新成员
已加入
2020年10月7日
留言内容
3
编程经验
1-3
C#:
m_objPanelPreview = new Panel[9] { panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9 };
 

        private void NineViewForm_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            m_objMFReader = new MFReaderClass[9];
            m_objPreview = new MFPreviewClass[9];
            m_objAudioMeter = new Object[9] { mAudioMeter1, mAudioMeter2, mAudioMeter3, mAudioMeter4, mAudioMeter5, 
                                                mAudioMeter6, mAudioMeter7, mAudioMeter8, mAudioMeter9 };
            m_objPanelPreview = new Panel[9] { panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9 };

            for (int i = 0; i < 9; i++)
            {
                m_objMFReader[i] = new MFReaderClass();
                m_objPreview[i] = new MFPreviewClass();
                m_objPreview[i].PreviewWindowSet("", m_objPanelPreview[i].Handle.ToInt32());
                m_objPreview[i].PreviewEnable("", 0, 1);
                //mAudioMeter1.ChannelsUpdated += mAudioMeter1_ChannelsUpdated;
            }
            //showUdpData();
            cancelSource = new CancellationTokenSource();
            m_threadWorker = new Thread(() => thread_DoWork(cancelSource.Token));
            m_threadWorker.Name = "thread_DoWork";
            m_threadWorker.Start();
        }


#region CALL THREAD
        private void thread_DoWork(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                DisplayFrame();

            }
        }

        private void DisplayFrame()
        {
            lock (m_objLock)
            {
                if (playerState.Count > 0)
                {
                    foreach (var state in playerState)
                    {
                        if (state.ViewType == "file")
                        {
                            int index = state.playerIndex;
                            MFFrame pFrame;
                            m_objMFReader[index].SourceFrameGetByTime(-1, -1, out pFrame, "");
                            if (pFrame != null)
                            {
                                ((MAudioMeter)m_objAudioMeter[index]).pFrame = pFrame;
                                ((MAudioMeter)m_objAudioMeter[index]).UpdateControl();
                                ((MAudioMeter)m_objAudioMeter[index]).SetValues();
                                ((MFPreviewClass)m_objPreview[index]).ReceiverFramePut(pFrame, -1, "");
                            }
                            Marshal.ReleaseComObject(pFrame);
                        }
                        else if (state.ViewType == "udp")
                        {
                            int index = state.playerIndex;
                            MFFrame pFrame;
                            m_objMFReader[index].SourceFrameGetByNumber(-1, -1, out pFrame, "");
                            if (pFrame != null)
                            {
                                ((MAudioMeter)m_objAudioMeter[index]).pFrame = pFrame;
                                ((MAudioMeter)m_objAudioMeter[index]).UpdateControl();
                                ((MAudioMeter)m_objAudioMeter[index]).SetValues();
                                ((MFPreviewClass)m_objPreview[index]).ReceiverFramePut(pFrame, -1, "");
                            }
                            Marshal.ReleaseComObject(pFrame);
                        }
                    }
                }
            }
        }
        #endregion

我在事件处理程序上设置一个断点。第一次之后没有被击中
 

金西尼

C#论坛主持人
工作人员
已加入
2011年4月23日
留言内容
3,501
地点
悉尼,澳大利亚
编程经验
10+
There is almost certainly another control being created and hosted in the Panel. I imagine that it's happening here:
C#:
m_objPreview[i].PreviewWindowSet("", m_objPanelPreview[i].Handle.ToInt32());
The SetParent API is likely being used inside that method to embed another window inside the Panel using its handle and that window is what you're actually clicking on. You would likely need to use Windows API methods to detect clicks on that window. The first step would be to confirm that that is what's happening. You can use Spy++ or a similar tool to inspect the window hierarchy of your application and I think you'll find that there is a window inside that Panel after you run that code that wasn't there beforehand.
 
最佳 底部