+ 1
new windows creation watcher in c++
Hi I just want to perform some action when new windows is created. How to catch that action? In other words, i am right now checking continuously that specific window handler is available to user or not using FindWindowA. I just want to check this command when new window of any type is created from Windows. Any thoughts will be helpful.
3 Réponses
+ 1
Any window within your app, or any window system-wide?
The former case would just require that you check if you need to do [function containing whatever you need your script to perform] any time your app calls a new window.
That is, create a general function that controls app window calls (you can just have it take an id variable and use it to call whatever function(s) you’re already using to govern that particular window), and run everything you need to check from there, e.g.:
void WinManage(int ID) {
switch (ID) {
case [winImWaitingFor]:
ThingsImWaitingFor();
relevantWinFunc();
break;
case [otherWin]:
relevantWinFunc();
break;
…}}
The latter would be more difficult, as it likely requires listening through Windows API/Cocoa (Mac)/whatever linux uses to manage windows (XWindows?).
Happy to discuss more if I’ve missed something.
+ 1
Need listener for windows system wide...
I am having windows 10 as os.
The window I am concerned is of a third party application whose source code is not in my control... Continuously checking by an application that concern window is opened or not is very inefficient and impacts the system performance
+ 1
From a Stack Overflow thread [1]:
“…you can write a CBT hook [linked in thread] and watch for HCBT_CREATEWND. See also SetWindowsHookEx() [linked in thread].
Note that this will allow you to be notified of all window creation, before the windows being created are even fully initialized.”
I believe HCBT_WNDCREATE can give access to the window’s handle, so you can use that to figure out if the window is coming from the app you’re watching for; a caveat - I don’t do a lot of system’s stuff, so I’m not entirely sure how involved this is. As I understand it, this will limit resource consumption such that your window query will only run when new windows are sent to Win32 for display.
[1] - https://stackoverflow.com/questions/1024756/how-can-i-be-notified-when-a-new-window-is-created-on-win32