|
the API SHOpenFolderAndSelectItems() does this in much less code.
give it the idlist from the shortcut and away you go.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shopenfolderandselectitems.asp
Chris Guzak (ms)
|
|
|
|
|
This call appears to be only for XP or better.
Anything comparable for W2k?
|
|
|
|
|
this is built on top of features that do exist in Win2K.
CLSID_ShellWindows/IShellWindows can be used to enumerate open folder
windows and to get to the FolderView (IShellView/IFolderView interfaces)
object that is hosted there. below is some code, with supporting helpers
that demonstrate some of this (some of these helpers are only in XP
but those too can be implemented on top of the shell architecture in Win2K).
---- code that uses shell windows objects and gets a reference to the views in those windows ---
#define IID_PPV_ARG(IType, ppType) IID_##IType,
reinterpret_cast<void**>(static_cast<itype**>(ppType))
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
STDAPI DisplayNameOf(IShellFolder *psf, LPCITEMIDLIST pidl, DWORD flags,
PWSTR psz, UINT cch)
{
*psz = 0;
STRRET sr;
HRESULT hr = psf->GetDisplayNameOf(pidl, flags, &sr);
if (SUCCEEDED(hr))
hr = StrRetToBufW(&sr, pidl, psz, cch);
return hr;
}
STDAPI_(DWORD) SHGetAttributes(IShellFolder *psf, LPCITEMIDLIST pidl, DWORD
dwAttribs)
{
// like SHBindToObject, if psf is NULL, use absolute pidl
LPCITEMIDLIST pidlChild;
if (!psf)
{
SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlChild);
}
else
{
psf->AddRef();
pidlChild = pidl;
}
DWORD dw = 0;
if (psf)
{
dw = dwAttribs;
dw = SUCCEEDED(psf->GetAttributesOf(1, (LPCITEMIDLIST *)&pidlChild,
&dw)) ? (dwAttribs & dw) : 0;
psf->Release();
}
return dw;
}
STDAPI IUnknown_QueryService(IUnknown* punk, REFGUID guidService, REFIID
riid, void **ppv)
{
*ppv = NULL;
HRESULT hr = E_FAIL;
if (punk)
{
IServiceProvider *psp;
hr = punk->QueryInterface(IID_PPV_ARG(IServiceProvider, &psp));
if (SUCCEEDED(hr))
{
hr = psp->QueryService(guidService, riid, ppv);
psp->Release();
}
}
return hr;
}
STDAPI SHGetIDListFromUnk(IUnknown *punk, LPITEMIDLIST *ppidl)
{
HRESULT hr = E_NOINTERFACE;
*ppidl = NULL;
IPersistFolder2 *ppf;
if (punk && SUCCEEDED(punk->QueryInterface(IID_PPV_ARG(IPersistFolder2,
&ppf))))
{
hr = ppf->GetCurFolder(ppidl);
ppf->Release();
}
return hr;
}
HRESULT SHGetName(LPCITEMIDLIST pidl, DWORD gdnFlags, PTSTR psz, UINT cch)
{
IShellFolder *psfDesktop;
HRESULT hr = SHGetDesktopFolder(&psfDesktop);
if (SUCCEEDED(hr))
{
IShellFolder *psf;
LPCITEMIDLIST pidlChild;
hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf),
&pidlChild);
if (SUCCEEDED(hr))
{
hr = DisplayNameOf(psf, pidlChild, gdnFlags, psz, cch);
}
psfDesktop->Release();
}
return hr;
}
HRESULT ViewFromWebBrowserApp(IWebBrowserApp *pwba, REFIID riid, void **ppv)
{
IShellBrowser* psb;
HRESULT hr = IUnknown_QueryService(pwba, SID_STopLevelBrowser,
IID_PPV_ARG(IShellBrowser, &psb));
if (SUCCEEDED(hr))
{
IShellView* psv;
hr = psb->QueryActiveShellView(&psv);
if (SUCCEEDED(hr))
{
hr = psv->QueryInterface(riid, ppv);
psv->Release();
}
psb->Release();
}
return hr;
}
HWND WindowFromUnk(IUnknown *punk)
{
HWND hwnd = NULL;
IOleWindow *pow;
if (SUCCEEDED(punk->QueryInterface(IID_PPV_ARG(IOleWindow, &pow))))
{
pow->GetWindow(&hwnd);
pow->Release();
}
return hwnd;
}
STDAPI FindWindowByHWND(HWND hwnd, REFIID riid, void **ppv)
{
HRESULT hr = E_FAIL;
*ppv = NULL;
IShellWindows* psw;
if (SUCCEEDED(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL,
IID_PPV_ARG(IShellWindows, &psw))))
{
VARIANT v;
v.vt = VT_I4;
IDispatch *pdispWBA;
for (v.intVal = 0; FAILED(hr) && S_OK == psw->Item(v, &pdispWBA);
v.intVal++)
{
IWebBrowserApp *pwba;
if
(SUCCEEDED(pdispWBA->QueryInterface(IID_PPV_ARG(IWebBrowserApp, &pwba))))
{
HWND hwndWBA;
if (SUCCEEDED(pwba->get_HWND((LONG_PTR*)&hwndWBA)) &&
(hwnd == hwndWBA))
{
hr = ViewFromWebBrowserApp(pwba, riid, ppv);
}
pwba->Release();
}
pdispWBA->Release();
}
psw->Release();
}
return hr;
}
----- Original Message -----
From: "Paul Farry" <forums@codeproject.com>
To: "chrisg" <chris_guzak@msn.com>
Sent: Sunday, March 23, 2003 6:01 PM
Subject: [CodeProject] Re: much easier/more reliable way to do this
> NOTE: This message has been sent from an unattended email box. To reply
> either visit the URL below or copy and paste the email address
> that was supplied to us below into your email client.
>
> An answer has been posted to your message on the page 'Find Target Shell
Extension':
>
> URL :
http://www.codeproject.com/useritems/findtarget.asp?msg=453682#xx453682xx
> From: Paul Farry (pfarry@coloradogroup.com.au)
>
> This call appears to be only for XP or better.
>
> Anything comparable for W2k?
>
>
>
> ---------------------------------------------------------------
> This message was created by The Code Project
> http://www.codeproject.com
>
>
>
Chris Guzak (ms)
|
|
|
|
|
For your information, "Find Target" can also be done with ShellExecute a command line as
"Explorer.exe /e,/select,C:\\Windows\\notepad.exe".
I tried and this works at WinXP.
I'm not sure if it also works at W2K or earlier Windows.
|
|
|
|