Click here to Skip to main content
15,885,979 members
Articles / Desktop Programming / ATL
Article

Find Target Shell Extension

Rate me:
Please Sign up or sign in to vote.
4.92/5 (16 votes)
3 Feb 2003CPOL 134.1K   2.8K   24   23
An article about shortening the process of finding the target of a .lnk(windows shortcut) file

Find Target menu selected - findtarget.gif

Introduction

This shell extension will add a new option to the Context menu of .lnk (Shortcut) files. I've always been annoyed that to Perform a find target, you have to right click properties, then click find target. There doesn't seem to be a direct api call that simulates what the shell does so I've hunted around, and come up with this, which uses a CreateProcess, ShellExecute, and didn't seem to highlight the file.

Background

After reading Michael Dunn's articles on shell extension (well the first couple so far), I took the examples and came up with this. http://www.codeproject.com/shell/shellextguide1.asp

Using the code

To use the extension, either just regsvr32 it, or Recompile and Register.

Points of Interest

There is a quirk still in here that sometimes the selected file doesn't highlight. (Anyone with any clues, assistance would be greatly appreciated)

History

  • 08-02-2003 Correction for incorrect registry entry.
  • 04-02-2003 Initial release.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGreat Assisting Tool Pin
chessgod10110-Jan-10 8:23
chessgod10110-Jan-10 8:23 
QuestionHow to install in 3 steps! Pin
cherwally19-Sep-09 4:29
cherwally19-Sep-09 4:29 
Generaloh! thank you Paul!!!! Pin
bbsoft3-Aug-09 15:53
bbsoft3-Aug-09 15:53 
Generalcontext not working solved Pin
alxnto22-Jan-09 9:39
alxnto22-Jan-09 9:39 
Generalxp64 Pin
Tilo Kühn9-May-08 1:40
Tilo Kühn9-May-08 1:40 
GeneralGreat Tool Pin
charlie markwick8-Dec-07 21:17
charlie markwick8-Dec-07 21:17 
GeneralDifferent behaviour on expanded start menu to s/c's in an explorer pane Pin
dalchina24-Aug-07 16:13
dalchina24-Aug-07 16:13 
QuestionHow to get the route of Shortcut Pin
Yao11309-Dec-04 15:44
Yao11309-Dec-04 15:44 
Generalhigfails if the target directory is open Pin
Martijn1-Oct-03 1:59
Martijn1-Oct-03 1:59 
Generala very valuable tool Pin
Bill Hart26-Aug-03 16:52
Bill Hart26-Aug-03 16:52 
Generalmuch easier/more reliable way to do this Pin
chrisg23-Mar-03 12:20
chrisg23-Mar-03 12:20 
GeneralRe: much easier/more reliable way to do this Pin
Paul Farry23-Mar-03 15:01
professionalPaul Farry23-Mar-03 15:01 
GeneralRe: much easier/more reliable way to do this Pin
chrisg26-Mar-03 16:39
chrisg26-Mar-03 16:39 
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)
GeneralRe: much easier/more reliable way to do this Pin
LupinTaiwan13-Mar-08 6:46
LupinTaiwan13-Mar-08 6:46 
Generalnot display in context menu Pin
billhao4-Feb-03 4:59
billhao4-Feb-03 4:59 
GeneralRe: not display in context menu Pin
Daniel 'Tak' M.4-Feb-03 9:05
Daniel 'Tak' M.4-Feb-03 9:05 
GeneralRe: not display in context menu Pin
billhao4-Feb-03 20:24
billhao4-Feb-03 20:24 
GeneralRe: not display in context menu Pin
Paul Farry7-Feb-03 11:57
professionalPaul Farry7-Feb-03 11:57 
GeneralRe: not display in context menu Pin
billhao8-Feb-03 1:42
billhao8-Feb-03 1:42 
GeneralRe: not display in context menu Pin
Bill Hart26-Aug-03 16:41
Bill Hart26-Aug-03 16:41 
GeneralRe: not display in context menu Pin
Paul Farry5-Feb-03 21:21
professionalPaul Farry5-Feb-03 21:21 
GeneralRe: not display in context menu Pin
Paul Farry7-Feb-03 3:01
professionalPaul Farry7-Feb-03 3:01 
GeneralRe: not display in context menu Pin
billhao7-Feb-03 3:18
billhao7-Feb-03 3:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.