check whether a window exists from handle.

Posted on 2007-10-16
Last Modified: 2010-05-18

a quick question, i have a windows hwnd handle (a window i have hooked into) and i want to poll this window and close my program when it closes.

I have been doing this like so

if(FindWindow(NULL, <title>) == 0)


however the program in question which im hooking into changes i title through its use. The hwnd stays constant though is there any was i can replace the findwindow to check if it exists using the handle?

many thanks,

Question by:flynny
    LVL 28

    Expert Comment

    Try IsWindow(handle). The documentation says "The IsWindow function determines whether the specified window handle identifies an existing window." See
    LVL 39

    Accepted Solution

    Hmmm. Polling on a window handle by calling IsWindow would take 100 percent CPU for nothing. At least you would need to make a little

          Sleep(10);   // sleep 10 ms

    to give other processes and threads a chance.

    If you are already hooking a message queue you easier may find out whether the window is closing by checking for a WM_CLOSE or WM_DESTROY message.

    Regards, Alex
    LVL 28

    Assisted Solution

    You may also be interested in studying the "Three Ways to Inject Your Code into Another Process"
    by Robert Kuster -- the Prize winner article from July 2003. See

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    PCH Sample and Makefile 14 57
    Quicksort a dynamic deque 33 50
    VS2015 compilation and missing DLLs 9 79
    Best book to learn C++ 3 29
    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now