title: C++ application console not exiting
body: <p>I'm using OpenCV 2.4.5 and Visual Studio 2012 to write a program in C++. In its simplest form I'm retrieving an image from a webcam, showing it on screen and then exit the application. The first parts work, but I cannot exit the application. </p>
  
  <p>I'm using the <code>system("pause")</code> command instead of <code>cin.get()</code> at the end of my <code>main</code> function because I need that line of output right now, despite temporarily losing portability. And why? Because I'm seeing the "Press any key to continue..." line, but the console is not exiting. </p>
  
  <p>I've tried 'pumping' using <code>waitKey(1)</code> just after <code>showFrame()</code>, but it doesn't help. If I remove <code>cvStartWindowThread()</code> nothing changes (that I notice, at least). The application seems unable to shut down the console. Visual Studio is still in debug mode, too, and I can't even break the program using Ctrl+C after returning from <code>showFrame()</code>. I have no idea how to solve this.</p>
  
  <p>The project is still very much WIP, but I'll include the relevant code here:</p>
  
  <p>Defines:</p>
  
  <pre><code>#define EXTERNAL_CAM    0
  #define BUILT_IN_CAM    1
  #define SINGLE_SHOT     0
  #define VIDEO_GRAB      1
  #define WINDOW      "Frame"
  </code></pre>
  
  <p><code>main</code> function:</p>
  
  <pre><code>int main() {
      Mat frame = getFrameFromCam(EXTERNAL_CAM, SINGLE_SHOT);
      showFrame(WINDOW, frame);
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p><code>getFrameFromCam</code> function:</p>
  
  <pre><code>Mat getFrameFromCam(int cam, int captureMode) {
      Mat frame;
      CvCapture* capture = cvCaptureFromCAM(cam);
      IplImage* iplImage;
      switch(captureMode) {
      case SINGLE_SHOT:
          iplImage = cvQueryFrame(capture);
          frame = iplImage;
          break;
      case VIDEO_GRAB:
          bool firstFrame = true;
          do {
              iplImage = cvQueryFrame(capture);
              frame = iplImage;
              showVideo(WINDOW, frame, firstFrame, false);
              firstFrame = false;
          } while (cin.get() != 'y');
          showVideo(WINDOW, frame, firstFrame, true);
          break;
      }
  
      return frame;
  }
  </code></pre>
  
  <p><code>showFrame</code> function:</p>
  
  <pre><code>void showFrame(string window, Mat frame) {
      cvStartWindowThread();
      namedWindow(WINDOW, CV_WINDOW_AUTOSIZE);
      imshow(WINDOW, frame);
      waitKey(0);
      destroyWindow(WINDOW);
  
      return ; 
  }
  </code></pre>