How to execute some code every time the application window opens (other processes)?

I am trying to track visible windows from all currently running processes. My program interacts with these windows, and the faster it can detect them, the better. My goal is to move visible windows to a specific location on the screen before they even draw a default position, if possible. If not, I want to move them as soon as possible after they are created.

Right now, I am listing visble windows using EnumWindows (p / invoked from user32.dll) in a loop with a low delay between iterations, as far as I can justify.

I am looking for a method to connect to "something" that will allow me to wait until a "window opens", instead of constantly polling.

Are there any methods to achieve this?

+3
source share
1 answer

You need the API function SetWindowsHookEx () to set the WH_SHELL hook. The callback receives the HSHELL_WINDOWCREATED notification when a new top-level window is created.

This is a global hook; you cannot write code for this hook in C #. This requires a DLL that can be injected into the process, the CLR cannot be correctly initialized to support managed code. You will need an unmanaged DLL to do this job, this project offers one.

+5
source

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


All Articles