Mega Code Archive

 
Categories / Delphi / Examples
 

Startmenuedit

YOU NEED DELPHI 3.0 OR LATER FOR THIS CODE TO HAPPEN... Richard... Technical Information Database TI1597D.txt Adding shortcuts to Win95/WinNT4 Desktop/StartMenu Category :Application Interop Platform :All Product :Delphi All Description: Title: Adding shortcuts to the Win95/WinNT40 desktop or start menu This sample project demonstrates an easy way to add shortcuts to your Windows 95 or Windows NT 4.0 desktop or start menu. 1. Launch Delphi 3 OR 4 (BUT NOT 2: -IT HASN'T GOT THE SOURCE FILES FOR ACTIVEX ETC...). 2. In a new project, drop a TButton on the form (make sure it's called Button1). Then double click on Button1. Now you can go ahead and directly replace the code for Unit1 with the code for Unit1 below. The program will set up a shortcut either (see the code) on the desktop or on the start menu. The shortcut will be called FooBar and it will open up your AUTOEXEC.BAT in NOTEPAD when executed. It will read the value of the "Desktop" and "Start Menu" strings from the registry key named (under HKEY_CURRENT_USER): Software\MicroSoft\Windows\CurrentVersion\Explorer\Shell Folders -------------- The Unit1 unit -------------- unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} uses ShlObj, ActiveX, ComObj, Registry; procedure TForm1.CreateButtonClick(Sender: TObject); {adapted slightly from the original Borland example by me Richard...} var MyObject: IUnknown; MySLink: IShellLink; MyPFile: IPersistFile; FileName: String; Directory: String; WFileName: WideString; MyReg: TRegIniFile; begin MyObject := CreateComObject(CLSID_ShellLink); MySLink := MyObject as IShellLink; MyPFile := MyObject as IPersistFile; FileName := 'C:\MYDELPHI\WTUTILS\PROGMAN\MYCHRMAP.EXE'; with MySLink do begin {SetArguments('PUT_ARGUMENTS_HERE');} SetPath(PChar(FileName)); SetWorkingDirectory(PChar(ExtractFilePath(FileName))); end; MyReg := TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer'); {Use the next line of code to put a shortcut on the desktop...} {Directory := MyReg.ReadString('Shell Folders','Desktop','');} {The next three lines of code put a shortcut on the start menu...} Directory := MyReg.ReadString('Shell Folders','Start Menu','') + '\Programs\Writers Toolkit'; CreateDir(Directory); WFileName := Directory+'\wt.lnk'; MyPFile.Save(PWChar(WFileName),False); MyReg.Free; end; end. Reference: 7/16/98 4:34:16 PM Trademarks & Copyright © 1998 INPRISE Corporation. Last modified on 8-December-1998