When the application displays a dialog box, (for me, quiet annoyance) the behavior of the Windows operating system is to display the newly created window on top of all the others. Therefore, if I assume that you know which process to look at, the way to detect a new window is to configure the Windows hook:
delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime); [DllImport("user32.dll")] public static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags); [DllImport("user32.dll")] public static extern bool UnhookWinEvent(IntPtr hWinEventHook);
I have not tried this code explicitly for dialog boxes, but for individual processes it works well. Please remember that this code cannot work in a Windows service or in a console application, since it requires a message pump (these are Windows applications). You will need to create your own.
Hope this helps
source share