[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 609
  • Last Modified:

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)
0
dvplayltd
Asked:
dvplayltd
1 Solution
 
gerhardschoemanCommented:
dvplayltd,

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

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

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

regards
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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.
0
 
gerhardschoemanCommented:
dvplayltd,

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.

regards
0
 
AlexFMCommented:
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.
0
 
jkrCommented:
You could use

#include <psapi.h>

DWORD dwPID;
DWORD dw;
char acImageName[MAX_PATH];
HANDLE hProcess;
HMODULE hMod;

GetWindowThreadProcessId(hWnd,&dwTID);

hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,dwPID);

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

GetModuleBaseName(hProcess,hMod,acImageName,MAX_PATH);
0
 
gerhardschoemanCommented:
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.

regards
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now