TheBlueNotebook
TheBlueNotebook

Reputation: 1254

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, i.e, if two windows happen to overlap, a window with a higher priority should be painted over the window with lower priority.

I am getting the handles of different (invisible/visible) windows wrt to a window using the GetWindow function. 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?

Upvotes: 3

Views: 23183

Answers (1)

CristiFati
CristiFati

Reputation: 41116

You can use [MS.Docs]: GetWindowThreadProcessId function.

In order to check the current process id, use [MS.Docs]: GetCurrentProcessId function.

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).

Upvotes: 6

Related Questions