简体   繁体   English

如何检测HWND是否属于我的应用程序?

[英]How to detect if a HWND belong to my application?

My application creates multiple windows and I want to enforce a Z order in-between these windows, ie, if two windows happen to overlap, a window with a higher priority should be painted over the window with lower priority. 我的应用程序创建了多个窗口,我想在这些窗口之间强制执行Z顺序,即,如果两个窗口碰巧重叠,则应在优先级较低的窗口上方绘制优先级较高的窗口。

I am getting the handles of different (invisible/visible) windows wrt to a window using the GetWindow function. 我正在使用GetWindow函数将不同(不可见/可见)窗口的句柄传递给窗口。 I want to know if a particular window returned by this function is created by my application. 我想知道我的应用程序是否创建了此函数返回的特定窗口。 Any ideas on how can I get that information? 关于如何获取该信息的任何想法?

You can use [MS.Docs]: GetWindowThreadProcessId function . 您可以使用[MS.Docs]:GetWindowThreadProcessId函数

In order to check the current process id, use [MS.Docs]: GetCurrentProcessId function . 为了检查当前进程ID,请使用[MS.Docs]:GetCurrentProcessId函数

If your app is more complex and spawns multiple processes that create windows, you'll have to construct the process tree using [MS.Docs]: Tool Help Functions (( CreateToolhelp32Snapshot , Process32First , Process32Next ) + CloseHandle ). 如果您的应用程序更复杂,并且产生了多个创建窗口的进程,则必须使用[MS.Docs]来构建进程树:工具帮助功能 ((( CreateToolhelp32SnapshotProcess32FirstProcess32Next )+ CloseHandle )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM