How to find application title by hWnd ?

Hello experts !

I know hWnd - how to find what application (title) is it owner ?
hWnd is form, but can be application written in Visual Basic 6 or  C++ (Net. 2003)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


If you have a valid HWND then you can find the title of that window by using GetWindowText() API function call.

dvplayltdAuthor Commented:
ok, but I do NOT want caption of windows, I want application title.

application title is NOT same as window caption
you mean you want the "application.exe" name of the app that has created the windows?

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

dvplayltdAuthor Commented:
"application.exe" will be OK, but I prefer caption of Main Windows of process.

I am NOT sure, but I think all EXE has ONE main windows. In VB6 it is set by Project Properties/Make/ frame Application and text box Title.

The caption of the main window is the text you will get using GetWindowText (this is the Title setting you are refering to in VB6 and it is setting the window text or caption). I think what you mean is that you just don't want the child window text. In that case I would suggest the following:

Starting with your initial HWND
Use HWND Parent = GetWindowLong(hWnd, GWL_HWNDPARENT)
and repeat until parent==NULL.
then you know you have the topmost window.
Use the last hWnd (the one for which the parent == NULL) and use GetWindowText() to get the caption for the main window.

Main application window is not defined. Generally, application can have number of windows. You can enumarate all process windows and find parent of all other windows, but this doesn't give 100% correct result. If you want executable name, use the following way:

Using GetWindowThreadProcessId function find process ID from HWND.
Using OpenProcess function get process handle.
Enumerate process modules using EnumProcessModules function. For each module call GetModuleFileNameEx function to get module name. One of them has .exe extension.
You could use

#include <psapi.h>

char acImageName[MAX_PATH];
HANDLE hProcess;



EnumProcessModules(hProcess,&hMod,sizeof(hMod),&dw); // just 1 module


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
is it just me or was the asker not really after the .exe name of the process?
>>> "application.exe" will be OK, but I prefer caption of Main Windows of process."

in which case working your way through the parent windows and then finally GetWindowText() will provide the answer.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.