dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: How Get Full Path by HWND pinter?

  1. #1
    Join Date
    Sep 2008
    Posts
    12

    Exclamation How Get Full Path by HWND pinter?

    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()

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How Get Full Path by HWND pinter?

    What path are you referring to ? A HWND is a handle to a window and as such is not tied to any path

  3. #3
    Join Date
    Sep 2008
    Posts
    12

    Re: How Get Full Path by HWND pinter?

    How to get path to the current active window? ( even without HWND pointer)

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How Get Full Path by HWND pinter?

    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

  5. #5
    Join Date
    Sep 2008
    Posts
    12

    Re: How Get Full Path by HWND pinter?

    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

  6. #6
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How Get Full Path by HWND pinter?

    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

  7. #7
    Join Date
    Sep 2008
    Posts
    12

    Post Re: How Get Full Path by HWND pinter?

    kirants, thank very much you for reply.
    As for first your point I did:
    Code:
    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
    Last edited by Sergio10; October 2nd, 2008 at 01:29 PM.

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,602

    Re: How Get Full Path by HWND pinter?

    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.
    Best regards,
    Igor

  9. #9
    Join Date
    Sep 2008
    Posts
    12

    Re: How Get Full Path by HWND pinter?

    So how to implement it in my case? How to catch foreground window in Windows explorer?

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,602

    Re: How Get Full Path by HWND pinter?

    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.
    Best regards,
    Igor

  11. #11
    Join Date
    Sep 2008
    Posts
    12

    Re: How Get Full Path by HWND pinter?

    Could you please example how to implement it?

  12. #12
    Join Date
    Jan 2008
    Posts
    178

    Re: How Get Full Path by HWND pinter?

    Getting Explorer current path is a win32 FAQ
    See Google Groups.

  13. #13
    Join Date
    Sep 2008
    Posts
    12

    Re: How Get Full Path by HWND pinter?

    fred100, sorry but I can't find it(
    Please give me a link to example please

  14. #14
    Join Date
    Oct 2008
    Posts
    2

    Resolved Re: How Get Full Path by HWND pinter?

    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.

    Code:
    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.

  15. #15
    Join Date
    Sep 2008
    Posts
    12

    Re: How Get Full Path by HWND pinter?

    Up
    A need get Explorer current path

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)