IShellExtInit
(1)
QueryContextMenu
(1)
IContextMenu
(1)
InvokeCommand
(1)
ViewDetails
(1)
InsertMenu
(1)
IdCmdFirst
(1)
IdCmdLast
(1)

folder background context-menu extesion disables 'create new folder' button

Asked By arloan
15-Dec-09 09:28 AM
Hi all,

I created a very simple shell extension using vc6, implemented IShellExtInit
& IContextMenu interfaces to provide a 'hello' context menu item for
directory background, which shows up a message box with 'hello world!'. It
works perfectly, but I found that it disabled the 'Create New Folder' button
on the toolbar of the shell open/save dialog box. In fact, when  I hit the
'Create New Folder' button, the shell calls my extension's
IContextMenu::InvokeCommand() method. Am I doing anything wrong? Thanks for
anybody's help.

The whole project can be download at here:
http://cid-0475c87002affa39.skydrive.live.com/self.aspx/temp/testext.zip

Below is the most significant codes:

// IContextMenu
STDMETHODIMP Cshmenu::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT
idCmdFirst, UINT idCmdLast, UINT uFlags)
{
if (uFlags & CMF_DEFAULTONLY)
{
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0));
}

InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_STRING, idCmdFirst,
_T("&Hello, world!"));
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 1);
}

STDMETHODIMP Cshmenu::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT *
pwReserved, LPSTR pszName, UINT cchMax)
{
switch (uFlags)
{
case GCS_HELPTEXTW:
lstrcpyW((LPWSTR)pszName, L"HelloW!");
break;
case GCS_HELPTEXTA:
lstrcpyA(pszName, "HelloA!");
break;
case GCS_VERBW:
lstrcpyW((LPWSTR)pszName, L"test_hello");
break;
case GCS_VERBA:
lstrcpyA(pszName, "test_hello");
break;
}

return S_OK;
}

STDMETHODIMP Cshmenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
{
LPCMINVOKECOMMANDINFOEX exinfo = (LPCMINVOKECOMMANDINFOEX)pici;

if (HIWORD(exinfo->lpVerbW))
{
MessageBox(pici->hwnd, _T("Hello, world!"), _T("helloW"),
MB_ICONINFORMATION);
}
else
{
MessageBox(pici->hwnd, _T("Hello, world!"), _T("helloA"),
MB_ICONINFORMATION);
}

return S_OK;
}

nitttontheordrive.live.com/self.aspx/temp/testext.

bviksoe replied to arloan
16-Dec-09 11:28 AM
nit
t
ton
the
or
drive.live.com/self.aspx/temp/testext.zip
*

Does it matter if you actually filter on idCmd in GetCommandString() ?
It looks like you could be returning data and S_OK for a lot of things
that you really should not.

bjarke

arloan wrote:Yes - you mustn't respond to InvokeCommand unless you recognise

Jim Barry replied to arloan
16-Dec-09 05:09 AM
Yes - you mustn't respond to InvokeCommand unless you recognise the
command as one of your own. In all other cases you must ignore the call
and return a failure code such as E_FAIL.

- Jim

According to my understanding, the shell should not call my

arloan replied to bviksoe
16-Dec-09 06:52 AM
According to my understanding, the shell should not call my extension's
GetCommandString() if the idCmd is not belong to my extension registered
during QueryContextMenu(), of which the return value should play it is role.

I tried to filter the idCmd in GetCommandString() according to your
suggestion, but it does not work still. Thanks a lot.

Arloan
"Jim Barry" wrote:I modified InvokeCommand() and directly return E_FAIL, but
arloan replied to Jim Barry
16-Dec-09 07:01 AM
I modified InvokeCommand() and directly return E_FAIL, but the 'Create New
Folder' button still does not work.

STDMETHODIMP Cshmenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
{
return E_FAIL;
}

I think that the shell just should not call my extension's InvokeCommand()
if the verb/id is not belong to my extension registered during
QueryContextMenu() on it is return value.

Thanks.
arloan wrote:Then I am not sure what else to suggest - it works for me.
Jim Barry replied to arloan
16-Dec-09 08:11 AM
Then I am not sure what else to suggest - it works for me. Are there any
other background context menu handlers registered?


The issue is that the file dialog wants to invoke the "NewFolder"
command on a composite context menu. The composite menu does not know
which of its contained menu handlers implements the command so it calls
each of them in turn until one succeeds. Yes the composite menu could
query the verb of every single menu item until it finds one that
matches, but it would be less efficient.

- Jim
"Jim Barry" wrote:There is no other background handlers registered.
arloan replied to Jim Barry
17-Dec-09 05:32 AM
There is no other background handlers registered. I tested my extension in a
fresh installed windows 2000 in vmware, the same prolem's still there. This
is really weired. :-(
project, or my project supplied in previous message works in your system?
Thanks.


Yes, I found the shell calls my extension with ver 'NewFolder', and I have
been thought that the shell goes wrong somewhere. If the shell behaves like
that u've figured out, that is just reasonable. Would you be so nice to tell
me where to find the official or unofficial tech-info about this behavour?
Thank u so much for your patient.

Arloan. P
"Jim Barry" wrote:Hi, it works now!
arloan replied to Jim Barry
17-Dec-09 05:59 AM
Hi, it works now! I reinstalled my build system & test system, and it works
perfectly.
Maybe one of the systems is polluted by other 3rd-party shell extensions
which out of my mind. Thank you very much for your suggestion & patient!!

PS. I still want to learn about that is there any further
official/unofficeal techinfo about how the shell handles the
'NewFolder'(and/or other standard verbs) verb, would you please tell me
about that? Thanks a lot.
arloan wrote:You're welcome.Not sure what there is to tell...
Jim Barry replied to arloan
17-Dec-09 11:54 AM
You're welcome.


Not sure what there is to tell... the verbs "NewFolder", "ViewDetails"
and "ViewList" are mentioned in the CMINVOKECOMMANDINFOEX documentation.
However, "ViewDetails" and "ViewList" fell out of use in Windows 2000,
when the file dialog's "List" and "Details" buttons were replaced by a
drop-down menu button. The file dialog implements the "Create New
Folder" command by invoking the "NewFolder" command on the folder's
background context menu object. This context menu is a composite menu
consisting of a hardwired menu merged with the context menu handlers
registered under the Directory\Background subkey.

- Jim
Post Question To EggHeadCafe