Delphi - 바탕 화면을 만들고,...로 보내기빠른 시작 막대, 시작 메뉴, 프로그램 메뉴, 마우스 오른쪽 버튼 메뉴

9960 단어 Delphi
{=================================================================
   :
     、   ...、     、    、    、         
   :
FileName :          
Description :         
Arguements :         
ShowName :         
Location :       
id :          (255    )
CreateOrDelete:        (      true)
     :  
   :
     Registry, ShlObj, ComObj, ActiveX, RegStr   
=================================================================}

 
procedure TMainForm.CreateShortcut(FileName,Description,Arguements,ShowName:
string;
Location: ShortcutType; id: byte; CreateOrDelete: boolean=true);
var
cObj :IUnknown;
sLink :IShellLink;
pFile :IPersistFile;
sDir,spath,key,tmp :string;
wFileName :WideString;
mReg :TRegistry;
begin
cObj :=CreateComObject(CLSID_ShellLink); //  COM  
sLink :=cObj as IShellLink; //COM     IShellLink   
pFile :=cObj as IPersistFile; //COM     IPersistFile   
//    
sPath :=ExtractFilePath(FileName);
with sLink do begin
SetPath(PChar(FileName)); //       
SetArguments(PChar(arguements)); //      
SetDescription(Pchar(Description)); //      
SetWorkingDirectory(PChar(sPath)); //
end;
//            
mReg :=TRegistry.Create;
with mReg do begin
if Location=ST_CONTEXT then //      
begin
RootKey :=HKEY_CLASSES_ROOT;
tmp:= '*shell'+ShowName;
if CreateOrDelete then
begin
if OpenKey(tmp,true) then
begin
// writestring           
WriteString('',ShowName+'(&k)');
CloseKey;
end;
if OpenKey(tmp+'command',true) then
begin
//command                       ;
//%1             
//WriteString(,'c:delphimyprogram.exe+"%1"');
WriteString('',FileName);
CloseKey;
end;
end
else
DeleteKey(tmp);
Free;
exit;
end;
RootKey :=HKEY_CURRENT_USER;
key :=REGSTR_PATH_EXPLORER; //Delphi   RegStr      
tmp :=key + 'Shell Folders';
OpenKey(tmp, false);
case Location of
ST_DESKTOP: sDir :=ReadString('Desktop');
ST_SENDTO: sDir :=ReadString('SendTo');
ST_STARTMENU: sDir :=ReadString('Start Menu');
ST_PROGRAMS: sDir :=ReadString('Programs');
ST_QUICKLAUNCH:
begin
sDir :=ReadString('AppData');
sDir :=sDir + 'MicrosoftInternet ExplorerQuick Launch';
end;
end;
//         
if ShowName='' then
begin
ShowName :=ChangeFileExt(FileName, '.Lnk');
ShowName :=ExtractFileName(ShowName);
end
else
ShowName:= ShowName+'.lnk';
if sDir<>'' then
begin
//          
wFileName :=sDir + '' + ShowName;
if (id<255) then
begin
if FileExists(wFileName) then
//RzCheckGroup1.ItemChecked[id]:= true;
end
else
//              
if CreateOrDelete then
pFile.Save(PWChar(wFileName), false)
else
DeleteFile(wFileName);
end;
Free;
end;
end;

좋은 웹페이지 즐겨찾기