|
-
August 24th, 2004, 03:14 AM
#1
Telling Explorer to display a different folder?
I'm looking for a way to tell an instance of Explorer that is already running to change directory and display a different folder (of my choice).
My guess is that there is probably a PostMessage() type solution to this. Where might I find documentation of the messages accepted by Windows Explorer?
Or any other ideas?
Cheers,
Ian
-
August 24th, 2004, 04:28 AM
#2
Not sure, but probably Shell helper API and/or Browser Helper Objects are what you need
-
August 24th, 2004, 07:40 AM
#3
This will do it. I posted a similar method a while back showing how to get the address line from Internet Explorer.
Code:
#include <windows.h>
int main()
{
// The path we want to display in Explorer...
const TCHAR szPath[] = TEXT("c:\\");
// This is the "family tree" from Explorer's main window to the edit control...
const TCHAR szClassNames[][64] =
{
TEXT("WorkerW"),
TEXT("ReBarWindow32"),
TEXT("ComboBoxEx32"),
TEXT("ComboBox"),
TEXT("Edit")
};
// This is the number of generations (windows) in the family...
const int iWindows = sizeof(szClassNames) / sizeof(szClassNames[0]);
// Get the handle to the Explorer's main window (currently on "My Computer")...
HWND hExplorer = FindWindow(NULL, TEXT("My Computer"));
if (hExplorer == NULL)
{
// Couldn't find the main Explorer window...
return -1; // Error
}
// Start with the top level window...
HWND hChild = hExplorer;
// And continue getting children until we reach the edit control...
for (int i = 0; i < iWindows; i++)
if (!(hChild = FindWindowEx(hChild, NULL, szClassNames[i], NULL)))
return -1; // Error
// We now have a handle to Explorer's address bar edit control. Set the text...
SendMessage(hChild, WM_SETTEXT, NULL, (LPARAM) szPath);
// Now, simulate a press of the Enter key in the edit control...
SendMessage(hChild, WM_KEYDOWN, VK_RETURN, NULL);
SendMessage(hChild, WM_CHAR, VK_RETURN, NULL);
SendMessage(hChild, WM_KEYUP, VK_RETURN, NULL);
return 0;
}
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-
August 24th, 2004, 08:37 AM
#4
Hi Bond,
Will the way you suggested work if I remove from View the address box? Other windows?
Is it not more robust to use automation?
As far as I know Explorer is a COM server. What we usually call "Explorer" is only a GUI that communicates with this server.
-
August 24th, 2004, 08:53 AM
#5
 Originally Posted by sbubis
Hi Bond,
Will the way you suggested work if I remove from View the address box? Other windows?
Yep. The edit window has still been created. You just can't see it.
Is it not more robust to use automation?
You could argue that. But then you have to use COM and everything that goes along with that (try/catch, CoInitialize(), HRESULT's, etc.).
However, if Automation is your game, you could do something like this (though this doesn't use an existing instance and it actually loads IE, not Explorer, but they're one and the same, right?
Code:
#include <windows.h>
#include <ExDisp.h>
#include <ExDispID.h>
int main()
{
CoInitialize(NULL);
HRESULT hr;
IWebBrowser2* pWebBrowser = NULL;
hr = CoCreateInstance (CLSID_InternetExplorer, NULL, CLSCTX_SERVER, IID_IWebBrowser2, (LPVOID*)&pWebBrowser);
if (SUCCEEDED (hr) && (pWebBrowser != NULL))
{
VARIANT vDummy = {0};
VARIANT vUrl;
vUrl.vt = VT_BSTR;
vUrl.bstrVal = SysAllocString(L"c:\\");
pWebBrowser->Navigate2(&vUrl, &vDummy, &vDummy,&vDummy, &vDummy);
pWebBrowser->put_Visible(VARIANT_TRUE);
VariantClear(&vUrl);
}
else
{
if (pWebBrowser)
pWebBrowser->Release();
}
CoUninitialize();
return 0;
}
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-
August 24th, 2004, 08:59 AM
#6
Thank you Bond,
As for me, I would prefer automation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|