title: How can I detect message boxes popping up in another process?
body: <p>I'd like to execute some code whenever a (any!) message box (as spawned by the <a href="http://msdn.microsoft.com/en-us/library/ms645505%28VS.85%29.aspx" rel="nofollow noreferrer">MessageBox Function</a>) is shown in another process. I didn't start the process I'm monitoring.</p>
  
  <p>I can think of three approaches:</p>
  
  <ol>
  <li>Install a global <a href="http://msdn.microsoft.com/en-us/library/ms644977%28VS.85%29.aspx" rel="nofollow noreferrer">CBT Hook</a> 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 <code>#32770</code> (which is the class name of dialogs according to the <a href="http://msdn.microsoft.com/en-us/library/ms633574%28VS.85%29.aspx#system" rel="nofollow noreferrer">About Window Classes</a> 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.</li>
  <li>Try to subclass the <code>#32770</code> system window class (is this possible at all?) and look for WM_CREATE messages in my custom window procedure.</li>
  <li>Intercept the  <a href="http://msdn.microsoft.com/en-us/library/ms645505%28VS.85%29.aspx" rel="nofollow noreferrer">MessageBox Function</a> API call (even though the remote process is running already!) and call my code from the hook function.</li>
  </ol>
  
  <p>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?</p>