Get parent window of an application

Started by
1 comment, last by ongamex92 8 years, 6 months ago
Hi guys,

Is it possible to retrieve the parent window of a application without knowing the window handle?

The reason I want to do this, is to get the HWND of the parent window to use in a function, without passing it via function parameter and not setting HWND to a global.

Hoping there is something like GetModuleHandle(NULL), which retrieves the HINSTANCE without having to pass around the HINSTANCE from the main function - if you get my drift.

Thanks in advance smile.png
Advertisement

A win32 application can have as many top level windows as it wants, there's no requirement for there to be a 'parent' window. The best you could maybe do is enumerate all top level windows (perhaps something in here might be of help: https://social.msdn.microsoft.com/Forums/en-US/c19a695d-a7d1-42b7-851e-12e98f427b39/can-i-get-all-the-windows-a-process-has?forum=vcgeneral) and filter them by some criteria.

Well, isn't "GetParent" what you want?

https://msdn.microsoft.com/en-us/library/windows/desktop/ms633510(v=vs.85).aspx

I've missed that you dont know the cureent handle. You could try with GetActiveWindow, or if you know the caption of the window FindWindow

This topic is closed to new replies.

Advertisement