Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows sub-menu

Posted on 1999-07-30
9
Medium Priority
?
194 Views
Last Modified: 2010-04-04
Referencing Q.10189074. You can use the registry to create a Windows Explorer Menu popup. How do you add a sub menu popup?
0
Comment
Question by:CalvinDay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1392105
also curious..
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1392106
A shell extension is needed here. I don't know a way to do that without. It's quite complicated.
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 1392107
I also think that you can't create sub menus without a shell extension except the "sent to" menu there it's already done by windows.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 13

Expert Comment

by:Epsylon
ID: 1392108
Yep, that's a shell extension too. I checked that out before I posted my previous comment.

CalvinDay, I may be able to solve this problem but it will take far too much time that I don't have right now.

Delphi 3 and 4 come with a context menu demo (contmenu.dpr) which add an item to the menu when you right-click drag-and-drop. That demo can be modified to construct a submenu.
Then the DLL must be registered the right way.

It's tricky stuff so be carefull.

Eps.
0
 
LVL 2

Author Comment

by:CalvinDay
ID: 1392109
I couldn't get contmenu.dpr to work. I then realized I must copy contmenu.dll to C:\windows\system. It works fine.
0
 
LVL 2

Author Comment

by:CalvinDay
ID: 1392110
So far I've added this. (and it works)

function TContextMenu.QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst,
          idCmdLast, uFlags: UINT): HResult;
var
  popMenu:HMENU;
begin
  popMenu:=CreatePopupMenu;
  InsertMenu(popMenu,0,MF_STRING or MF_BYPOSITION,0,'Sub 1');
  InsertMenu(popMenu,1,MF_STRING or MF_BYPOSITION,1,'Sub 2');
  InsertMenu(popMenu,2,MF_STRING or MF_BYPOSITION,2,'Sub 3');
  InsertMenu(popMenu,3,MF_STRING or MF_BYPOSITION,3,'Sub 4');
  InsertMenu(Menu,indexMenu,MF_STRING or MF_POPUP,popMenu,'Compile...');
  Result := 1;
end;

0
 
LVL 2

Author Comment

by:CalvinDay
ID: 1392111
Other posting was wrong, this is correct: I have written a little utility to sort file names and print them according to sort criteria. It is called xprint.exe. Now with this little shell extension, I can highlight a group of files, right click and select the printed sort order on the fly.

Here's the final code:

unit ContextM;

interface
uses
    Windows, ComObj, ComServ, ShlObj, ActiveX, ShellApi, SysUtils, Classes;

Const
   CLSID_ContextMenuShellExtension: TGUID = (
    D1:$8e3e0f0a; D2:$0fcc; D3:$11ce; D4:($bc, $b0, $b3, $fd, $0e, $25, $38, $1a));

type
    TContextMenu = class(TComObject, IShellExtInit, IContextMenu)
    private
      szFile: array[0..MAX_PATH] of Char;
    public
      function QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst, idCmdLast,
        uFlags: UINT): HResult; stdcall;
      function InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; stdcall;
      function GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
        pszName: LPSTR; cchMax: UINT): HResult; stdcall;
      function Initialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
        hKeyProgID: HKEY): HResult; stdcall;
    end;

var
  t:TStringStream;

implementation

function GetCompilerPath(sort:integer): string;
const
  SortName='ntsd';
var
  sWinDir,s:string;
  l:integer;
begin
  SetLength(sWinDir,255);
  l:=GetWindowsDirectory(PChar(sWinDir),255);
  SetLength(sWinDir,l);
  Result := sWinDir+'\xPrint.exe /'+SortName[sort+1]+' %s';
end;

function TContextMenu.QueryContextMenu(Menu:HMENU;indexMenu,idCmdFirst,idCmdLast,uFlags:UINT):HResult;
const
  CmdName: array[0..3] of string=('by &Name','by &Type','by &Size','by &Date');
var
  popMenu:HMENU;
  i:integer;
begin
  popMenu:=CreatePopupMenu;
  for i:=0 to High(CmdName) do
    InsertMenu(popMenu,i,MF_STRING or MF_BYCOMMAND,idCmdFirst+i,PChar(CmdName[i]));
  InsertMenu(Menu,indexMenu,MF_STRING or MF_POPUP,popMenu,'xPrint ...');
  Result:=High(CmdName)+1;
end;

function TContextMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
var
  H: THandle;
begin
  Result:=E_FAIL;
  if HiWord(Integer(lpici.lpVerb))<>0 then exit;
  H:=WinExec(PChar(Format(GetCompilerPath(LoWord(lpici.lpVerb)),[t.DataString])),lpici.nShow);
  if H<32 then
    MessageBox(lpici.hWnd, 'Error executing xPrint.', 'Error',MB_ICONERROR or MB_OK);
end;

function TContextMenu.GetCommandString(idCmd,uType:UINT;pwReserved:PUINT;pszName:LPSTR;cchMax:UINT):HRESULT;
const
  CmdHint: array[0..3] of string=('Name','Type','Size','Date');
begin
  Result:=NOERROR;
  if (idCmd>=0) and (idCmd<=High(CmdHint)) then
    StrPCopy(pszName,'Prints selected items sorted by '+CmdHint[idCmd])
  else
    Result:=E_INVALIDARG;
end;

function TContextMenu.Initialize(pidlFolder:PItemIDList;lpdobj:IDataObject;hKeyProgID:HKEY):HResult;
var
  medium: TStgMedium;
  fe: TFormatEtc;
  i,count:integer;
begin
  with fe do
    begin
    cfFormat:=CF_HDROP;
    ptd:=nil;
    dwAspect:=DVASPECT_CONTENT;
    lindex:=-1;
    tymed:=TYMED_HGLOBAL;
    end;

  Result:=E_FAIL;
  if lpdobj=nil then exit;

  Result:=lpdobj.GetData(fe,medium);
  if Failed(Result) then exit;

  count:=DragQueryFile(medium.hGlobal,$FFFFFFFF,nil,0);
  t.Position:=0;
  for i:=0 to count-1 do
    begin
    DragQueryFile(medium.hGlobal,i,szFile,SizeOf(szFile));
    t.WriteString('"'+string(szFile)+'" ');
    end;

  Result:=NOERROR;
  ReleaseStgMedium(medium);
end;

initialization
  t:=TStringStream.Create('');
  TComObjectFactory.Create(ComServer, TContextMenu, CLSID_ContextMenuShellExtension,
         '', 'Delphi 3.0 ContextMenu Example', ciMultiInstance);
finalization
  t.Free;
end.

Epsylon, please post an answer for your wonderful suggestion.


0
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 total points
ID: 1392112
Thank you, CalvinDay, sorry I didn't have the time to do it for you. But this way you have learned more I think   :o)

Cheers,

Epsylon.
0
 
LVL 2

Author Comment

by:CalvinDay
ID: 1392113
Thanks, epsylon, I did learn alot. The only thing I'm missing is the little bitmap next to the menu. I may have to post a question to do that.
 
If anyone wants the xPrint program, drop me your email. it's pretty good when trying to compare dll's and such.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question