Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Q] QueryContextMenu() question...

1 view
Skip to first unread message

Donovan J. Edye

unread,
Oct 26, 2003, 3:26:00 AM10/26/03
to
G'Day,

I am writing a shell extension and have followed the demo in the ActiveX\ShellExt
directory. However it appears that my context menu only appears when I right mouse
click on DPR file. I would like it to work for any of the following scenarios:

- No files selected
- Once file selected
- Multiple files selected
- All the above should directories be invlolved in the selection

Irrespective of file name and extension. I cannot for the life of me see what is causing
the DPR restriction. I even removed the following IF test which was in the demo with no
success:

if ((AuFlags and $0000000F) = CMF_NORMAL) or
((AuFlags and CMF_EXPLORE) <> 0) then

Can anyone shed any light on this for me?

TIA

--
-- Donovan J. Edye
----------------------------------------------------------------------
SetiStats - Get your SETI statistics delivered to your mailbox daily.
http://www.edye.wattle.id.au/p.php?page=/delphi/setistats
----------------------------------------------------------------------

Jim Kueneman

unread,
Oct 26, 2003, 7:42:44 AM10/26/03
to

Hi,

> I am writing a shell extension and have followed the demo in the
> ActiveX\ShellExt directory. However it appears that my context menu
> only appears when I right mouse click on DPR file. I would like it to
> work for any of the following scenarios:
>
> - No files selected
> - Once file selected
> - Multiple files selected
> - All the above should directories be invlolved in the selection
>
> Irrespective of file name and extension. I cannot for the life of me
> see what is causing the DPR restriction. I even removed the following
> IF test which was in the demo with no success:
>
> if ((AuFlags and $0000000F) = CMF_NORMAL) or
> ((AuFlags and CMF_EXPLORE) <> 0) then
>
> Can anyone shed any light on this for me?

You have to register the NSE in the registry:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc
/platform/shell/programmersguide/shell_basics/shell_basics_extending/con
text.asp


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc
/platform/shell/reference/classes/classes.asp


To get all files register under

Registry\HKEY_CLASSES_ROOT\*

To get all Folders register under

HKEY_CLASSES_ROOT\.Folder

etc.


--
Jim

Posted with XanaNews 1.15.6.3

Donovan J. Edye

unread,
Oct 27, 2003, 4:18:22 AM10/27/03
to
Jim Kueneman wrote:

> You have to register the NSE in the registry:

Thanks for the pointer. I have managed to get the registrations I want. However I seem to
have screwed up the adding of the context menu. Can you see what I have done wrong in
the code below? I do not seem to be getting my menu identifiers back in GetCommandString()

All I get are the following values in that method call:

idCmd = 27
uType = 4

Here is my code to create the popup:


const
//Identifiers for the various commands
ID_TOP = 0;
ID_FILE_RENAME = 1;
ID_FILE_SELECT = 2;

function TFileAssistant.QueryContextMenu(AMenu: HMENU; AindexMenu,
AidCmdFirst, AidCmdLast, AuFlags: UINT): HResult;
var
miInfo : TMenuItemInfo;
popMenu : HMenu;
const
MENU_TOP_NAME = 'File Assistant';
MENU_SUB_REMAME = 'Rename...';
MENU_SUB_SELECT = 'Select...';
//SC_ITEM = $FF00;
begin
//Show we have not added anything at this point
result := 0;

if ((AuFlags and $0000000F) = CMF_NORMAL) or
((AuFlags and CMF_EXPLORE) <> 0) then

begin
//First off we need to create the popup menu for the submenu
popMenu := CreatePopupMenu;

//Add items into the popup menu
//-- Rename ----------------------------------------------------------------
FillChar(miInfo, SizeOf(miInfo), 0);
with miInfo do
begin
cbSize := SizeOf(MenuItemInfo);
fMask := MIIM_TYPE or MIIM_ID;
fType := MFT_STRING;
wID := ID_FILE_RENAME;
dwTypeData := PChar(MENU_SUB_REMAME);
cch := Length(MENU_SUB_REMAME);
end;
InsertMenuItem(popMenu, 0, TRUE, miInfo);
//-- /Rename ---------------------------------------------------------------
//-- Select ----------------------------------------------------------------
FillChar(miInfo, SizeOf(miInfo), 0);
with miInfo do
begin
cbSize := SizeOf(MenuItemInfo);
fMask := MIIM_TYPE or MIIM_ID;
fType := MFT_STRING;
wID := ID_FILE_SELECT;
dwTypeData := PChar(MENU_SUB_SELECT);
cch := Length(MENU_SUB_SELECT);
end;
InsertMenuItem(popMenu, 0, TRUE, miInfo);
//-- /Select ---------------------------------------------------------------

//Add top level item
//if InsertMenu(AMenu, AindexMenu, MF_STRING or MF_BYPOSITION, AidCmdFirst, MENU_TOP_NAME) then
if InsertMenu(AMenu, AindexMenu, MF_STRING or MF_BYPOSITION or MF_POPUP, popMenu, MENU_TOP_NAME) then
//Return the number of items added. Remember we have a sub menu that we
//have added so we have only added one menu as far as the shell is concerned
result := AidCmdFirst + 1;
end;
end;

Jim Kueneman

unread,
Oct 27, 2003, 7:31:26 AM10/27/03
to

Hi,

> //Add top level item
> //if InsertMenu(AMenu, AindexMenu, MF_STRING or MF_BYPOSITION,
> AidCmdFirst, MENU_TOP_NAME) then if InsertMenu(AMenu, AindexMenu,
> MF_STRING or MF_BYPOSITION or MF_POPUP, popMenu, MENU_TOP_NAME) then
> //Return the number of items added. Remember we have a sub menu that
> we //have added so we have only added one menu as far as the
> shell is concerned result := AidCmdFirst + 1; end;
> end;

I am not sure this is true. Your menu ID's should be

AidCmdFirst + ID_TOP
AidCmdFirst + ID_FILE_RENAME
AidCmdFirst + ID_FILE_SELECT

Note this value must not be greater than AidCmdLast

Then the return should be AidCmdFirst + 3. Explorer will then use this
new value as AidCmdFirst for the next NSE it encounters while building
the menu.

Explorer has a fixed number of menu identifiers reserved for menu
handlers and you must tell it how many you have consumed.

Note also YOU must remember what AidCmdFirst was in QueryContextMenu so
you can decipher what id it is when the item is selected.

0 new messages