Click to See Complete Forum and Search --> : How Get Full Path by HWND pinter?
Sergio10
September 30th, 2008, 02:00 PM
Hello!
How to get path if I have HWND pinter of window or item pointer from ListView.
Thanks.
P.S. I get this pinter using GetForegroundWindow()
kirants
September 30th, 2008, 02:53 PM
What path are you referring to ? A HWND is a handle to a window and as such is not tied to any path
Sergio10
October 1st, 2008, 04:53 AM
How to get path to the current active window? ( even without HWND pointer)
kirants
October 1st, 2008, 12:10 PM
I still don't understand what you mean by path to the active window. Say for example, the internet explorer is the active window, now can you tell me what is the path to this internet explorer window ? If not, please give an example that you can think of
Sergio10
October 2nd, 2008, 07:39 AM
I need to know what is current folder, directory is active.
For example:
1. If you click to desktop then desktop is active and you receive current directory as: "C:\Documents and Settings\raptor\Desktop".
2. Then if you open Program Files in C disk and this window is still active then you receive "C:\Program Files" path.
Is it clear?
Thanks
kirants
October 2nd, 2008, 12:56 PM
There is no standard way to do it, you will have to write the algorigthm yourself. Like you said,
first you do a get the current active window. Compare it againts GetDesktopWindow() and if TRUE, use SHGetSpecialFolderPath to get the desktop folder path.
If not, get the process that corresponds to the HWND of active window using GetWindowThreadProcessId to get the process ID and compare it against the process ID of all explorers running ( EnumProcesses ) and go from there.
See this thread which has identical requirements as you have.
http://www.codeguru.com/forum/showthread.php?t=457359
Sergio10
October 2nd, 2008, 02:11 PM
kirants, thank very much you for reply.
As for first your point I did:
while(1)
{
HWND desktopWnd = GetDesktopWindow();
HWND activeWnd = GetForegroundWindow();
if (activeWnd == desktopWnd)
printf("Active Window is - Desktop\n");
CloseHandle(desktopWnd);
CloseHandle(activeWnd);
}
But it's not working( I run this code and clicked to Desktop but didn't print in console "Active Window is - Desktop". What is wrong with code?
As for second point I didn't understood how to implement it( Could you please explain more clearly?
Thanks
Igor Vartanov
October 2nd, 2008, 05:36 PM
Per my impression the guy wants some odd thing to be done: in case the Windows explorer window appears foreground, the explored path should be catched from it.
Sergio10
October 3rd, 2008, 08:58 AM
So how to implement it in my case? How to catch foreground window in Windows explorer?
Igor Vartanov
October 3rd, 2008, 09:35 AM
Well, it's not a big deal to find out that the foreground window belongs to explorer process (exactly like Kirant explained above). But I hardly know how to request the window what folder it is showing in.
Sergio10
October 3rd, 2008, 10:47 AM
Could you please example how to implement it?
fred100
October 4th, 2008, 06:41 AM
Getting Explorer current path is a win32 FAQ
See Google Groups.
Sergio10
October 4th, 2008, 03:13 PM
fred100, sorry but I can't find it(
Please give me a link to example please
nen
October 5th, 2008, 12:17 AM
I don't think I entirely understand your question.
But, if you're just needing to get the file path of the instance of your program from an HWND, you can call GetModuleFileName.
char path[MAX_PATH];
GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH);
MessageBox(NULL, path, NULL, NULL);
Would set 'path' as "C:\Your Apps Subdirs\YourApp.exe", and then pop up a message box displaying its value.
Sergio10
October 6th, 2008, 05:21 AM
Up
A need get Explorer current path
ovidiucucu
October 6th, 2008, 04:11 PM
A need get Explorer current path
Getting Explorer current path is... chasing Own tail. ;)
Sergio10
October 7th, 2008, 06:21 PM
ovidiucucu, what do you mean?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.