Question ContextMenuStrip not show when panel playing video

ptdanh392

New member
Joined
Oct 7, 2020
Messages
3
Programming Experience
1-3
I use Panel control to play video file using right mouse click to show menu and then add a video file. In first time, Menu is shown, I add video file and when panel control run video, I click mouse again to change other file, Menustrip control is not show
This is my code:

C#:
private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                RightContextMenuStrip.Show(new Point(MousePosition.X, MousePosition.Y));
            }
        }
Please help me to solve this problem.
 
How EXACTLY 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?
 
I use Medialooks SDK to preview frame from video.
I highlighted "EXACTLY" because I wanted specific details, i.e. the code or a detailed description of the code. What 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.
I'm sure I click many times after panel preview video.
Set a breakpoint on the event handler. Does it get hit after the first time?
 
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

I Set a breakpoint on the event handler. It is not get hit after the first time
 
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.
 
Back
Top Bottom