Search code examples
c++winapihandle

Waiting for another application window


What is the best way (with a view to optimization and using system resources) to make waiting in my application when window of another app will be shown?

For example:

  1. My application starts.
  2. Waiting while, for example, Notepad will be started so i can get handle of its window.
  3. Using handle im doing something with it and then closing my app.

How to accomplish item 2? I know only one possible way: just check if handle exists in loop using FindWindow. But I hope there is a more smart solution exists.


Solution

  • If you launched the process (with CreateProcess) use WaitForInputIdle and then start the FindWindow loop. Adding a Sleep(20) or something to the loop will ensure your resource usage is minimal.