Search code examples
winapimessageboxsetwindowshookex

Detecting MessageBoxes created by 3rd party DLLs


I'm loading 3rd party DLLs and sometimes they open MessageBox windows that stops the flow of the application, I want to be able to detect when such thing happens.

I'm trying to use SetWindowsHookEx with WH_CBT but my callback does not get called.

I tried calling it this way:

SetWindowsHookEx (WH_CBT, myCallback, NULL, 0);

But it didn't worked.

What should be the right call for this function?


Solution

  • You may use the WM_ENTERIDLE message to detect if there's any MessageBox window, simply check with FindWindowEx().

    This is C# but idea doesn't change: http://social.msdn.microsoft.com/forums/en-US/winforms/thread/d3f89686-e4d0-4bb1-9052-31abef2a9d2a