如何检查是否在c ++中打开了一个新窗口
问题描述:
您好,
制作程序时我遇到了问题。我希望在我的程序执行期间如果在我的笔记本电脑屏幕上打开一个新窗口,那么我的程序应该打印1并为每个打开的新窗口执行此操作直到我关闭程序。
谢谢
Hello,
While making a program I encountered a problem. I want that during the execution time of my program if a new window is opened on my laptop screen then my program should print 1 and do this for every new window opened until I close the program.
Thank you
答
您可以使用 SetWindowsHookEx功能 [ ^ ]。
您的请求的最佳程序类型可能是WH_CALLWNDPROCRET
。从过程处理程序内部检查与窗口创建有关的消息,如WM_CREATE
。
You can install a hook procedure using the SetWindowsHookEx function[^].
The best procedure type for your request will be probablyWH_CALLWNDPROCRET
. From inside the procedure handler check for a message that is involved with window creation likeWM_CREATE
.
另一个想法是捕获WM_NCPAINT消息, WM_NCPAINT消息表示您的窗口框架已失效,因为其他窗口可能已重叠,这可能很棘手,因为当没有窗口重叠时也可以触发WM_NCPAINT消息。查看更多详情。
WM_NCPAINT消息(Windows) [ ^ ]
Another idea is to catch WM_NCPAINT Message, WM_NCPAINT message means your window frame has been invalidated because other window might have overlapped, this could be tricky because WM_NCPAINT message can also be triggered when no window overlapped. Check this for further details.
WM_NCPAINT message (Windows)[^]