2.用shellexecute()
ShellExecute(Handle,"Open","notepad.exe",0,0,SW_SHOW);

解决方案 »

  1.   

    我不要单单只是用记事本,我要相应的程序打开相应的文件
    都可以用shellexecute吗?
    ShellExecute(Handle,"Open","notepad.exe",0,0,SW_SHOW);
                               这个可以改成什么样的变量可以实现吗?
      

  2.   

    增加一个ImageList控件
    动态把图片或图标加入到ImageList,以及动态改变ListView的图片索引
    打开这些文件和程序的命令:ShellExecute(Handle,'open',Pchar(你要打开的文件名),nil,nil,SW_SHOW)
      

  3.   

    下面是我曾见过的一个动态菜单的例子,正好解决你的问题,可以一试unit1.pas
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Menus, ImgList;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Button1: TButton;
        MainMenu1: TMainMenu;
        ImageList1: TImageList;
        PopupMenu1: TPopupMenu;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        procedure ItemClick(Sender: TObject);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}uses
      ShellApi;function GetSystemImageList(mImageList: TImageList): Boolean;
    var
      vHandle: THandle;
      vSHFileInfo: TSHFileInfo;
    begin
      FillChar(vSHFileInfo, SizeOf(vSHFileInfo), 0);
      vHandle := SHGetFileInfo('', 0, vSHFileInfo, SizeOf(vSHFileInfo),
        SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
      Result := vHandle <> 0;
      mImageList.Handle := vHandle;
      mImageList.ShareImages := True;
    end; { GetSystemImageList }function GetIconIndex(mPath: string): Integer;
    var
      vSHFileInfo: TSHFileInfo;
    begin
      FillChar(vSHFileInfo, SizeOf(vSHFileInfo), 0);
      SHGetFileInfo(PChar(mPath), 0, vSHFileInfo, SizeOf(vSHFileInfo),
        SHGFI_SYSICONINDEX);
      Result := vSHFileInfo.iIcon;
    end; { GetIconIndex }procedure PathToMenu(mDirName: string; mMenu: TMenu; mItemClick: TNotifyEvent);
      procedure pScanPath(mDirName: string; mGoalMenuItem: TMenuItem);
      var
        vSearchRec: TSearchRec;
        vPathName: string;
        K: Integer;
        vMenuItem: TMenuItem;
      begin
        vPathName := mDirName + '\*.*';
        K := FindFirst(vPathName, faAnyFile, vSearchRec);
        while K=0 do begin
          if (vSearchRec.Attr and faDirectory <> 0) and (Pos(vSearchRec.Name, '..') = 0) then begin
            vMenuItem := TMenuItem.Create(mMenu);
            vMenuItem.Caption := vSearchRec.Name;
            vMenuItem.Hint := mDirName + '\' + vSearchRec.Name;
            vMenuItem.ImageIndex := GetIconIndex(mDirName + '\' + vSearchRec.Name);
            vMenuItem.OnClick := mItemClick;
            mGoalMenuItem.Add(vMenuItem);
            pScanPath(mDirName + '\' + vSearchRec.Name, vMenuItem)
          end else if (Pos(vSearchRec.Name, '..') = 0) then begin
            vMenuItem := TMenuItem.Create(mMenu);
            vMenuItem.Caption := vSearchRec.Name;
            vMenuItem.Hint := mDirName + '\' + vSearchRec.Name;
            vMenuItem.ImageIndex := GetIconIndex(mDirName + '\' + vSearchRec.Name);
            vMenuItem.OnClick := mItemClick;
            mGoalMenuItem.Add(vMenuItem);
          end;
          K := FindNext(vSearchRec);
        end;
        FindClose(vSearchRec);
      end; { pScanPath }
    begin
      mMenu.Items.Clear;
      pScanPath(mDirName, mMenu.Items)
    end; { PathToMenu }procedure TForm1.Button1Click(Sender: TObject);
    begin
      PathToMenu(Edit1.Text, MainMenu1, ItemClick);
      PathToMenu(Edit1.Text, PopupMenu1, ItemClick);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      GetSystemImageList(ImageList1);
      ImageList1.DrawingStyle := dsTransparent;
      MainMenu1.AutoHotkeys := maManual;
      MainMenu1.Images := ImageList1;
      PopupMenu1.AutoHotkeys := maManual;
      PopupMenu1.Images := ImageList1;
    end;procedure TForm1.ItemClick(Sender: TObject);
    begin
      if FileExists(TMenuItem(Sender).Hint) then //避免目录
        ShellExecute(Handle, 'OPEN', PChar(TMenuItem(Sender).Hint), nil, nil, SW_SHOW);
    end;end.unit1.dfmobject Form1: TForm1
      Left = 192
      Top = 107
      Width = 544
      Height = 375
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      Menu = MainMenu1
      OldCreateOrder = False
      PopupMenu = PopupMenu1
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object Edit1: TEdit
        Left = 232
        Top = 16
        Width = 121
        Height = 21
        PopupMenu = PopupMenu1
        TabOrder = 0
        Text = 'Edit1'
      end
      object Button1: TButton
        Left = 240
        Top = 40
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 1
        OnClick = Button1Click
      end
      object MainMenu1: TMainMenu
        AutoHotkeys = maManual
        Left = 144
        Top = 56
      end
      object ImageList1: TImageList
        DrawingStyle = dsTransparent
        Left = 176
        Top = 56
      end
      object PopupMenu1: TPopupMenu
        Left = 112
        Top = 56
      end
    end