?
Solved

How to get a Windows Explorer handle?

Posted on 2000-05-15
6
Medium Priority
?
981 Views
Last Modified: 2012-06-21
I need to lauch NT Windows Explorer from an VC++ application, get the handle of the explorer (Note, not Internet Explorer!), and direct the explorer to a specific folder. Someone please tell me how to achieve this?
0
Comment
Question by:yzmao
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 600 total points
ID: 2812009
To open the explorer & direct it to a specific directory is quite easy, simply use

ShellExecute(handle, "explore", <path_to_folder>, NULL, NULL, SW_SHOWNORMAL);

Getting the handle turns out to be more difficult, the easiest solution that I could imagine would be sth. like this:

// globals
HWND  g_hwnd;
int  g_nFound;

BOOL CALLBACK FindHwndFromPID( HWND hwnd, LPARAM lParam) :


HWND GetWindowHandleFromPID ( DWORD dwProcessId)
{
 g_hwnd = NULL;
 g_nFound = 0;

 EnumWindows (  FindHwndFromPID,    ( LPARAM) dwProcessId));

 if ( g_hwnd)  // we found one...
      return ( g_hwnd);

 // nothing found :-(

 return (NULL);
}

BOOL CALLBACK FindHwndFromPID( HWND hwnd, LPARAM lParam)
{
    DWORD   dwPID2Find  =   ( DWORD) lParam;
    DWORD   dwPID       =   0;

    if  (   GetWindowThreadProcessId    (   hwnd,   &dwPID))
        {
            if  (   dwPID   ==  dwPID2Find)
                {
                    g_hwnd  =   hwnd;

                    return  (   FALSE);
                }
        }

    return  (   TRUE);
}

    STARTUPINFO         si;
    PROCESS_INFORMATION pi;

    BOOL                bRes;

    DWORD               dwCode  =   0;

    ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

    si.cb           =   sizeof  (   STARTUPINFO);
    si.dwFlags      =   STARTF_USESHOWWINDOW;
    si.wShowWindow  =   SW_SHOWNORMAL;


    bRes    =   CreateProcess   (   NULL,
                                    "explorer.exe /root,<path_to_folder>",
                                    NULL,
                                    NULL,
                                    TRUE,
                                    NORMAL_PRIORITY_CLASS,
                                    NULL,
                                    NULL,
                                    &si,
                                    &pi
                                );


    //...
    HWND hwnd = GetWindowHandleFromPID ( pi.dwProcessId);

Feel free to ask if you need more information!

0
 

Author Comment

by:yzmao
ID: 2812446
Hi jkr:

Thank you very much for your quick and detailed response. I appreciate your help very much.

I'm testing t your code now... one question - there is an error from the follwing line:

 EnumWindows (  FindHwndFromPID,    ( LPARAM) dwProcessId));

where the varialbe g_hwnd gets the return value from function FindHwndFromPID?

Thank you agin!

yzmao
0
 
LVL 22

Expert Comment

by:nietod
ID: 2812741
That probable is because th FindhwndFromPID procedure has not been defined at that point.  You should move the procedure before that point, or add a forward declaration for the procedure
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:jkr
ID: 2813866
>>there is an error from the follwing >>line

Well, which error do you get? nietod is probably right, though there is a forward declaration in the example above...
0
 
LVL 22

Expert Comment

by:nietod
ID: 2814158
Missed that.
0
 

Author Comment

by:yzmao
ID: 2817061
I couldn't get the handle yet. But I don't have time to play this for a while. Thanks anyway.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question