title: How to display opencv frames in MFC?
body: <p>I'm writing an opencv code, and want to use MFC to show frames on GUI.</p>
  
  <p>The question is I don't know how.</p>
  
  <p>In the OnInitDialog()</p>
  
  <p>If I tried to embed the cvWindow to the MFC Form, and this could work.</p>
  
  <pre><code>display = new IplImage(trackview);//trackview is a totally black Mat.
      cvNamedWindow("IDC_STATIC_OUTPUT", 0); 
      cvResizeWindow("IDC_STATIC_OUTPUT", 480, 640);
  
      hWnd = (HWND) cvGetWindowHandle("IDC_STATIC_OUTPUT"); 
      hParent = ::GetParent(hWnd); 
       ::SetParent(hWnd, GetDlgItem(ID_DISPLAY)-&gt;m_hWnd); 
       ::ShowWindow(hParent, SW_HIDE); 
  
      cvShowImage("IDC_STATIC_OUTPUT", display);
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/cr1kV.jpg" alt="enter image description here"></p>
  
  <p>But when I embed OpenCV code and open the webcam, the GUI is not responding, and the frame cannot be shown. Even I just add this sample code (open webcam) to OnInitDialog(), the application form will not be shown. </p>
  
  <p>It is strange that I wrote a "imwrite("frame.png",tmp)", the frame could be written to file. But the GUI is not responding.</p>
  
  <pre><code>while( true )
      {
          CvCapture* capture;
          capture = cvCaptureFromCAM(0);
          frame = cvQueryFrame( capture );
          Mat tmp(frame);
          imwrite("frame.png",tmp);
      }
  </code></pre>
  
  <p>BTW, are there any better way to show OpenCV IplImage on MFC? There's a cvvImage.showImage() function, but it is discarded in Opecv 2.4 version.</p>