Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

check whether a window exists from handle.

hi,

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

while(true)
{
if(FindWindow(NULL, <title>) == 0)
break;

}

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,

matt.
0
flynny
Asked:
flynny
  • 2
2 Solutions
 
peprCommented:
Try IsWindow(handle). The documentation says "The IsWindow function determines whether the specified window handle identifies an existing window." See http://msdn2.microsoft.com/en-us/library/aa926895.aspx
0
 
itsmeandnobodyelseCommented:
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
0
 
peprCommented:
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 http://www.codeproject.com/threads/winspy.asp
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now