How can I detect message boxes appearing in another process?

I would like to execute some code whenever a message box (any!) (As it was created by the MessageBox Function ) is shown in another process. I did not start the process that I am tracking.

I can think of three approaches:

  • Set up a global CBT hook procedure that tells me when a window is created on the desktop. Then check if the window belongs to the process that I control, and whether the class name #32770(which is the name of the dialog class according to About Window Classes on MSDN). This will probably work, but it will pull the DLL containing the hook procedure into almost every process on the desktop, and the hook procedure will get many names. It smells of a potential performance issue.
  • Try to subclass the system window class #32770(is this possible at all?) And look for WM_CREATE messages in my custom window procedure.
  • Intercept the MessageBox Function API call (even if the remote process is already running!) And call my code from the hook function.

So far, I only know that the first idea is possible, but it seems really ineffective. Can anyone think of a simpler solution than this problem?

+3
source share
3 answers

I can’t think of any effective solution that does not involve injecting code into another process (this is basically what many types of hooks do by the way). But if you want to go this route, you can intercept calls in the MessageBox.

, MessageBox , , (, ). , , , .

. http://www.codeproject.com/KB/threads/completeinject.aspx , , DLL .

+4

: 2 . 1-3 dll, , 3 " ". , ?

+1

I would go with the first option. You only have to leave by setting a hook for the main user interface thread of the application you control, but if that doesn't work, even CBT global hooks are not very resource intensive in my experience. Of course, you want your DLL hook to contain as little as possible than the hook logic itself. If you need something bulky, link it dynamically only when you know that you are in the right process.

+1
source

Source: https://habr.com/ru/post/1737554/


All Articles