Board index » cppbuilder » How Can I get the Program path of a given hWnd

How Can I get the Program path of a given hWnd


2007-06-16 07:32:04 PM
cppbuilder34
Dear All,
If I got a hWnd of an application, How can I know the program file name,and
where the path of the program,
thank
Emmanuel
 
 

Re:How Can I get the Program path of a given hWnd

"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
Quote
See the help section: Retrieving a Window Property
msdn2.microsoft.com/en-us/library/Aa929345.aspx
That is for Windows CE only. "PROP_BUFFER" returns NULL data on
Win32.
Gambit
 

Re:How Can I get the Program path of a given hWnd

"Emmanuel" < XXXX@XXXXX.COM >wrote in message
Quote
If I got a hWnd of an application, How can I know the
program file name, and where the path of the program,
An HWND does not store that information. You cannot retreive the
filename directly from an HWND alone. What you will have to do
instead is use GetWindowThreadProcessId() to get the process ID of the
HWND, and then loop through all of the running processes on the
machine until you find a matching ID. Then you will know the
filename.
Gambit
 

{smallsort}

Re:How Can I get the Program path of a given hWnd

Emmanuel wrote:
Quote
If I got a hWnd of an application, How can I know the program file name,and
where the path of the program,
See the help section: Retrieving a Window Property
msdn2.microsoft.com/en-us/library/Aa929345.aspx
hMemProp = (HGLOBAL) GetProp(hwndSubclass, "PROP_BUFFER");
lpFilename = GlobalLock(hMemProp);
nSize = sprintf(tchBuffer, "Path to file: %s", lpFilename);
I haven't found where the magic strings are listed, but you can enum
them with EnumPropsEx
msdn2.microsoft.com/en-us/library/aa920752.aspx
 

Re:How Can I get the Program path of a given hWnd

Remy Lebeau (TeamB) wrote:
Quote
>See the help section: Retrieving a Window Property
>msdn2.microsoft.com/en-us/library/Aa929345.aspx

That is for Windows CE only. "PROP_BUFFER" returns NULL data on
Win32.
Good. I didn't like that "solution" anyway.
You didn't mention which function yields " running processes"
Ah! here it is..
SAMPLE: MODLIST.EXE Shows How to Enumerate Processes and Modules
support.microsoft.com/kb/192986
CreateToolhelp32Snapshot()
Process32First()
Process32Next()
And on the NT lineage (NT,2000,Xp,Vista) there is EnumProcesses
Example code:
msdn2.microsoft.com/en-us/library/ms682623.aspx