Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:38:52+00:00 2026-05-31T21:38:52+00:00

OpenCV version 2.2, C++ interface. When showing a loaded image in a window with

  • 0

OpenCV version 2.2, C++ interface.

When showing a loaded image in a window with following code snippet

cvStartWindowThread();

Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

if(! image.data )                              // Check for invalid input
{
    cout <<  "Could not open or find the image" << std::endl ;
    return -1;
}

namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image );   

while( 1 ) {
    if( cvWaitKey(100) == 27 ) break;
}

I face a problem when closing image by pressing the close button with the mouse, instead of using escape key.

In this case my program will be blocked in the while and the only way to exit it is to stop execution, which obviously is not desired.

Is there any function that controls if the close button has been pressed?
In that way I could add it in the while loop as this:

E.g.

while( 1 ) {
    if( cvWaitKey(100) == 27 ) break;
    if( cvCloseButtonPressed == 1) break; <--- purely invented method I'm looking for...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:38:53+00:00Added an answer on May 31, 2026 at 9:38 pm

    You can use cvGetWindowHandle() function to get handle of your named window. Window handle is an OS specific feature.
    An example for win32 looks like this:

    HWND hwnd = (HWND)cvGetWindowHandle("Display window");
    while(IsWindowVisible(hwnd)) {
        if( cvWaitKey(100) == 27 ) break;
    }
    

    IsWindowVisible() is a winapi function, so you may want to add #include <windows.h>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile OpenCV version 2.3.1 on an Ubuntu 11.10 following instructions described
I get the following error while building OpenCV on OS X 10.5 (intel): ld:
I have some problems with OpenCV s cvCanny(...) and the Image data types it
I'm trying to use the new 2.0 c++ version of OpenCV , but everything
I am updating some older OpenCV code that was written in (I guess) an
Here is my problem: I want have my qmake script detect my opencv version
How to access individual pixels in OpenCV 2.3 using C++? For my U8C3 image
I'm new in opencv and use the version 2.3 in C++. My approach is
I am using openCV python bindings. I am trying to show the output image
I have a multithreaded openCV program that uses 4 threads to do the following:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.