How can I detect message boxes popping up in another process?

Posted by Frerich Raabe on Stack Overflow See other posts from Stack Overflow or by Frerich Raabe
Published on 2010-03-18T16:31:12Z Indexed on 2010/03/20 3:11 UTC
Read the original article Hit count: 454

Filed under:
|
|

I'd like to execute some code whenever a (any!) message box (as spawned by the MessageBox Function) is shown in another process. I didn't start the process I'm monitoring.

I can think of three approaches:

  1. Install a global CBT Hook procedure which tells me whenever a window is created on the desktop. Then, check whether the window belongs to the process I'm monitoring and whether the class name is #32770 (which is the class name of dialogs according to the About Window Classes page at the MSDN). This would probably work, but it would pull the DLL which contains the hook procedure into virtually every process on the desktop, and the hook procedure gets called a lot. It smells like a potential perfomance problem.
  2. Try to subclass the #32770 system window class (is this possible at all?) and look for WM_CREATE messages in my custom window procedure.
  3. Intercept the MessageBox Function API call (even though the remote process is running already!) and call my code from the hook function.

So far, I only know that the first idea is feasible, but it seems really inefficient. Can anybody think of a simpler solution than that to this problem?

© Stack Overflow or respective owner

Related posts about c++

Related posts about win32