Solved

Appending Desktop Menu for Application

Posted on 1998-07-06
21
269 Views
Last Modified: 2010-04-04
Can I add a menuItem to the popup menu for an application(when
you right-click on the application on the desktop)  I've seen it done
with other applications.  I am using Delphi Desktop 2.0.
0
Comment
Question by:Stomper
  • 5
  • 4
  • 3
  • +5
21 Comments
 
LVL 4

Expert Comment

by:d003303
ID: 1357152
Do you mean for an application or a shortcut to an application ?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357153
You have to add a shortcut to your program in the registery  
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357154
I think Stomper means the window system menu (at the top left corner). The same menue is displayed also when right-clicking the application's button on task bar.
-I'm very curious too... :)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357155
Mmm, I think he means this :

When you are on your desktop and click on the Right mouse button, you get a popup menu. Well, I checked this out once and in my opinion you can easely add your program to it, by changing a registry entry. If you want that I search this entry, just give a sign and I'll try to do my best. But maybe there is an other way (without changing the registry, but I doubt that).

Zif.
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1357156
Normally the exe's are not on your desktop. Only shortcuts.

Maybe Stomper still wants something else:

Maybe his application works with files of a certain extension, and he wants to add an item to the popup when the user right clicks a file of that type.

That should be easy to accomplish by adding a file type to your browsers registry. (This can be done without the registry-editor). From the options menu in the browser choose file-type add)

Let me know if that is what you're looking for.

Regards Jacco

Zif-d003303-Matvey: Sometimes a question can be hard to understand.
0
 
LVL 1

Expert Comment

by:Greedy
ID: 1357157
I think he is talking about a property sheet...because he talks of right clicking the application's icon on the desktop...

003: don't you have a wizard for this?

0
 

Author Comment

by:Stomper
ID: 1357158
I see I caused quite a discussion.  I hope that I can clearify what I need.  I would like to add a menuitem to the popup menu that you get when you right click on an application either on the desktop or in a window.  

Stomper
0
 

Expert Comment

by:bome
ID: 1357159
I think he wants to add a menu item to explorer's context menu. Is it the menu that contains entries like Send To, Cut, Copy Paste, etc ?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357160
yes, bome that's the right name explorer's context menu. I'm talking about the same thing like you do, but your is much clearer.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357161
Hehehehe... :D
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1357162
Matvey?
0
 
LVL 4

Expert Comment

by:d003303
ID: 1357163
OK, so we all know that (s)he wants to have a menut item added to the context menu. Now, this should work for EXE files and for shortcut to EXE files (I think).
The EXE part is easy, the shortcut part a bit more difficult. But let'S first be sure if I misinterpreted the question.

Stomper, so you mean if you right-click on an icon on the desktop that starts an application without any documents in it, or when you right-click on an application icon in Explorer, you want a menu item added ?

Next thing is, what information do you need when this new item will be selected ?

Slash/d003303
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357164
No, no ;) I don't know what it is, but it's just funny that there are 5-6 very very wild guesses don't you think? ;-)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357165
:-) It is really funny indeed, maybe we should make a component which combines all 5-6 guesses and send it to the net. Then we always can refer to this component ;-) No offens to anybody offcourse. ZiF.
0
 

Expert Comment

by:LilitaN
ID: 1357166
Look Inprise (Borland) example at DEMOS\Shellext\ContMenu.dpr
0
 
LVL 4

Expert Comment

by:d003303
ID: 1357167
Zif, good idea ! Let's make a context menu that does everything that's useful:
Shutting down windows, formatting C:, repair the registry, make coffee, pays your ISP, ... ;-))

I think it's Stompers turn to clarify his needs. But any comments of the experts are welcome, of course. (I gotta get a coffee, first action for that component...)

Slash/d003303
0
 

Author Comment

by:Stomper
ID: 1357168
LilitaN, I can't find that file.

Bome, that is the menu that I want.  I just didn't what to call it.

Stomper
0
 

Accepted Solution

by:
LilitaN earned 50 total points
ID: 1357169
Sources for example

Contmenu.dpr
// You need to merge the ContMenu.reg file into the registry before you can use
// shell extension.   This Context Menu shell extension will allow you to right
// click on DPR files from the Explorer and Compile them using the DCC32.exe
// command line compiler.

library contmenu;

uses
  SysUtils,
  Classes,
  ComServ,
  ComObj,
  ContextM in 'ContextM.pas',
  ShlObj in 'Shlobj.pas';

exports
  DllGetClassObject resident,
  DllCanUnloadNow resident,
  DllRegisterServer resident,
  DllUnregisterServer resident;

begin
end.


unit ContextM;


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

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;



implementation

function GetCompilerPath: string;
// Returns string containing path to Delphi command line compiler
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    with Reg do
    begin
      RootKey := HKEY_LOCAL_MACHINE;
      OpenKey('\SOFTWARE\Borland\Delphi\3.0', False);
      Result := ReadString('RootDir');
    end;
    Result := Result + '\bin\dcc32.exe %s';
  finally
    Reg.Free;
  end;
end;

function TContextMenu.QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst,
          idCmdLast, uFlags: UINT): HResult;
begin
  // Add one menu item to context menu
  InsertMenu (Menu, indexMenu, MF_STRING or MF_BYPOSITION, idCmdFirst,
    'Compile...');
  // Return number of menu items added
  Result := 1;
end;

function TContextMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
var
  H: THandle;
begin
  // Make sure we are not being called by an application
  if HiWord(Integer(lpici.lpVerb)) <> 0 then
  begin
    Result := E_FAIL;
    Exit;
  end;
  // Make sure we aren't being passed an invalid argument number
  if LoWord(lpici.lpVerb) > 0 then
  begin
    Result := E_INVALIDARG;
    Exit;
  end;
  // Execute the command specified by lpici.lpVerb.
  if LoWord(lpici.lpVerb) = 0 then
  begin
    // invoke Delphi command line compiler
    H := WinExec(PChar(Format(GetCompilerPath, [szFile])), lpici.nShow);
    if H < 32 then
      MessageBox(lpici.hWnd, 'Error executing Delphi compiler.', 'Error',
        MB_ICONERROR or MB_OK);
  end;
  Result := NOERROR;
end;

function TContextMenu.GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
  pszName: LPSTR; cchMax: UINT): HRESULT;
begin
  if idCmd = 0 then
  begin
    // return help string for menu item
    strCopy(pszName, 'Compile the selected Delphi project');
    Result := NOERROR;
  end
  else
    Result := E_INVALIDARG;
end;

function TContextMenu.Initialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
  hKeyProgID: HKEY): HResult;
var
  medium: TStgMedium;
  fe: TFormatEtc;
begin
  with fe do
  begin
    cfFormat := CF_HDROP;
    ptd := Nil;
    dwAspect := DVASPECT_CONTENT;
    lindex := -1;
    tymed := TYMED_HGLOBAL;
  end;
  // Fail the call if lpdobj is Nil.
  if lpdobj = Nil then
  begin
    Result := E_FAIL;
    Exit;
  end;
  // Render the data referenced by the IDataObject pointer to an HGLOBAL
  // storage medium in CF_HDROP format.
  Result := lpdobj.GetData(fe, medium);
  if Failed(Result) then Exit;
  // If only one file is selected, retrieve the file name and store it in
  // szFile. Otherwise fail the call.
  if DragQueryFile(medium.hGlobal, $FFFFFFFF, Nil, 0) = 1 then
  begin
    DragQueryFile(medium.hGlobal, 0, szFile, SizeOf(szFile));
    Result := NOERROR;
  end
  else
    Result := E_FAIL;
  ReleaseStgMedium(medium);
end;

initialization
    TComObjectFactory.Create(ComServer, TContextMenu, CLSID_ContextMenuShellExtension,
         '', 'Delphi 3.0 ContextMenu Example', ciMultiInstance);

end.

Contmenu.reg
REGEDIT4

[HKEY_CLASSES_ROOT\CLSID\{8e3e0f0a-0fcc-11ce-bcb0-b3fd0e25381a}]
@= "Delphi 3.0 Context Menu Shell Extension"
[HKEY_CLASSES_ROOT\CLSID\{8e3e0f0a-0fcc-11ce-bcb0-b3fd0e25381a}\InProcServer32]
@= "contmenu.dll"
"ThreadingModel" = "Apartment"

[HKEY_CLASSES_ROOT\DelphiProject\shellex\ContextMenuHandlers\{8e3e0f0a-0fcc-11ce-bcb0-b3fd0e25381a}]
@= ""

0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357170
Just to say the example is only available from D3. I see you're using D2...
0
 

Expert Comment

by:LilitaN
ID: 1357171
Sorry
0
 

Expert Comment

by:bome
ID: 1357172
hehe, but you should at least change the CLSID...
bome
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now