⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 《Delphi开发人员指南》配书原码
💻 PAS
字号:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses ComObj, ActiveX, ShlObj, Registry;

const
  { Registry key where Folder information is kept }
  SFolderKey = '\Software\Microsoft\Windows\CurrentVersion\' +
               'Explorer\Shell Folders';

function GetFolderLocation(const FolderType: string): string;
{ Retrieves from registry path to folder indicated in FolderType }
begin
  with TRegistry.Create do
    try
      RootKey := HKEY_CURRENT_USER;
      if not OpenKey(SFolderKey, False) then
        { open key where shell folder information is kept. }
        raise ERegistryException.CreateFmt('Folder key "%s" not found',
          [SFolderKey]);
      { Get path for specified folder }
      Result := ReadString(FolderType);
      if Result = '' then
        raise ERegistryException.CreateFmt('"%s" item not found in registry',
          [FolderType]);
      CloseKey;
    finally
      Free;
    end;
end;

procedure MakeNotepad;
const
  // NOTE: Assumed location for Notepad:
  AppName = 'c:\windows\notepad.exe';
var
  SL: IShellLink;
  PF: IPersistFile;
  LnkName: WideString;
begin
  OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER,
    IShellLink, SL));
  { IShellLink implementers are required to implement IPersistFile }
  PF := SL as IPersistFile;
  OleCheck(SL.SetPath(PChar(AppName)));   // set link path to proper file
  { create a path location and filename for link file }
  LnkName := GetFolderLocation('Desktop') + '\' +
    ChangeFileExt(ExtractFileName(AppName), '.lnk');
  PF.Save(PWideChar(LnkName), True);      // save link file
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MakeNotepad;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -