home *** CD-ROM | disk | FTP | other *** search
- unit MainForm;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, ComCtrls, StdCtrls, Buttons, ActnList, Menus, ImgList,
- IniFiles;
-
- type
- TMainForm1 = class(TForm)
- MainPanel1: TPanel;
- Image1: TImage;
- ItemsListBox1: TListBox;
- ExecModeGroupBox1: TGroupBox;
- Label1: TLabel;
- AssocSpeedButton1: TSpeedButton;
- UserSpeedButton1: TSpeedButton;
- ExitSpeedButton1: TSpeedButton;
- SortedCheckBox1: TCheckBox;
- Bevel1: TBevel;
- DescriptionStaticText1: TStaticText;
- ActionList1: TActionList;
- ExitAction1: TAction;
- AssocAction1: TAction;
- UserAppAction1: TAction;
- SortAction1: TAction;
- MinimizeAction1: TAction;
- SystemPopupMenu1: TPopupMenu;
- Iconify1: TMenuItem;
- N1: TMenuItem;
- Exit1: TMenuItem;
- ExecIconCheckBox1: TCheckBox;
- ExecIconiAction1: TAction;
- ExecCloseCheckBox1: TCheckBox;
- ExecCloseAction1: TAction;
- ViewPopupMenu1: TPopupMenu;
- Standardassociation1: TMenuItem;
- Userapplication1: TMenuItem;
- N2: TMenuItem;
- Sorted1: TMenuItem;
- N3: TMenuItem;
- Iconifyafterexecute1: TMenuItem;
- Closeafterexecute1: TMenuItem;
- AboutAction1: TAction;
- AboutSpeedButton1: TSpeedButton;
- InitItemsListBox1: TListBox;
- ImageList1: TImageList;
- DisplayImage1: TImage;
- Timer1: TTimer;
- About1: TMenuItem;
- SpeedButton1: TSpeedButton;
- ExploreAction1: TAction;
- Exploreselecteditem1: TMenuItem;
- SpeedButton2: TSpeedButton;
- ExploreCDAction1: TAction;
- N4: TMenuItem;
- ExploreCD1: TMenuItem;
- ShortcutsAction1: TAction;
- N5: TMenuItem;
- Keyboardshortcuts1: TMenuItem;
- Keyboardshortcuts2: TMenuItem;
- N6: TMenuItem;
- SystemMenu1: TMenuItem;
- ExploreCD2: TMenuItem;
- N7: TMenuItem;
- Keyboardshortcuts3: TMenuItem;
- About2: TMenuItem;
- N8: TMenuItem;
- Iconify2: TMenuItem;
- Exit2: TMenuItem;
- OpenDialog1: TOpenDialog;
- CmdListBox1: TListBox;
- Bevel2: TBevel;
- CDNamePanel1: TPanel;
- CDNameLabel1: TLabel;
- SpeedButton3: TSpeedButton;
- procedure OnDeviceChange(var Msg : TMsg); message WM_DeviceChange;
- procedure OnMoveOnScreen(Sender : TObject; Button : TMouseButton;
- Shift : TShiftState; X, Y : Integer);
- procedure ExitAction1Execute(Sender: TObject);
- procedure MinimizeAction1Execute(Sender: TObject);
- procedure AboutAction1Execute(Sender: TObject);
- procedure SortAction1Execute(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure ShortcutsAction1Execute(Sender: TObject);
- procedure ExploreCDAction1Execute(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure ExecIconiAction1Execute(Sender: TObject);
- procedure ExecCloseAction1Execute(Sender: TObject);
- procedure AssocAction1Execute(Sender: TObject);
- procedure UserAppAction1Execute(Sender: TObject);
- procedure ExploreAction1Execute(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure ItemsListBox1Click(Sender: TObject);
- procedure ItemsListBox1KeyPress(Sender: TObject; var Key: Char);
- private
- DisplayedIcon : Byte;
- IniFile : TIniFile;
- public
- { Public declarations }
- end;
-
- var
- MainForm1 : TMainForm1;
- CDDrive : String;
- IniFileName : String;
- CDVName : String;
- CDVSerial : Cardinal;
-
- procedure FillInfo(var AVolumeName : String; var AVolumeSerial : Cardinal);
-
- implementation
-
- uses ShellAPI, AboutForm, ShortCutForm, ErrorForm, EventForm;
-
- {$R *.DFM}
-
- var
- RootPathName : PChar = nil;
- VolumeNameBuffer : PChar = nil;
- VolumeNameSize : Cardinal = 0;
- VolumeSerialNumber : Cardinal = 0;
- MaxComponentLength : Cardinal = 0;
- FileSystemFlags : Cardinal = 0;
- FileSystemName : PChar = nil;
- FileSystemNameSize : Cardinal = 0;
-
- procedure FillInfo(var AVolumeName : String; var AVolumeSerial : Cardinal);
- begin
- GetMem(RootPathName, 512);
- StrPCopy(RootPathName, CDDrive + '\');
- GetMem(VolumeNameBuffer, 512);
- VolumeNameSize := 512;
- GetMem(FileSystemName, 512);
- FileSystemNameSize := 512;
- GetVolumeInformation(RootPathName, VolumeNameBuffer,
- VolumeNameSize, @VolumeSerialNumber,
- MaxComponentLength, FileSystemFlags,
- FileSystemName, FileSystemNameSize);
- AVolumeName := VolumeNameBuffer;
- AVolumeSerial := VolumeSerialNumber;
- FreeMem(FileSystemName, 512);
- FreeMem(VolumeNameBuffer, 512);
- FreeMem(RootPathName, 512);
- end;
-
- procedure TMainForm1.OnDeviceChange(var Msg : TMsg);
- var
- NewVolumeName : String;
- NewVolumeSerial : Cardinal;
- begin
- FillInfo(NewVolumeName, NewVolumeSerial);
- If (NewVolumeName <> CDVName) or (NewVolumeSerial <> CDVSerial) then
- Application.Terminate;
- end;
-
- procedure TMainForm1.OnMoveOnScreen(Sender : TObject; Button : TMouseButton;
- Shift : TShiftState; X, Y : Integer);
- var
- Point : TPoint;
- begin
- If Button = mbLeft then
- begin
- Point.x := X;
- Point.y := Y;
- ReleaseCapture;
- SendMessage(Handle, wm_NCLButtonDown, htCaption, Integer(@Point));
- end;
- end;
-
- procedure TMainForm1.ExitAction1Execute(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TMainForm1.MinimizeAction1Execute(Sender: TObject);
- begin
- Application.Minimize;
- end;
-
- procedure TMainForm1.AboutAction1Execute(Sender: TObject);
- begin
- AboutForm1.ShowModal;
- end;
-
- procedure TMainForm1.SortAction1Execute(Sender: TObject);
- begin
- If not ItemsListBox1.Sorted then
- begin
- ItemsListBox1.Sorted := True;
- SortAction1.Checked := True;
- end
- else
- begin
- ItemsListBox1.Sorted := False;
- SortAction1.Checked := False;
- ItemsListBox1.Clear;
- ItemsListBox1.Items.AddStrings(InitItemsListBox1.Items);
- end;
- If ItemsListBox1.Items.Count > 0 then
- ItemsListBox1.ItemIndex := 0;
- end;
-
- procedure TMainForm1.Timer1Timer(Sender: TObject);
- begin
- case DisplayedIcon of
- 0:
- begin
- ImageList1.GetIcon(1, DisplayImage1.Picture.Icon);
- DisplayedIcon := 1;
- end;
- 1:
- begin
- ImageList1.GetIcon(2, DisplayImage1.Picture.Icon);
- DisplayedIcon := 2;
- end;
- 2:
- begin
- ImageList1.GetIcon(0, DisplayImage1.Picture.Icon);
- DisplayedIcon := 0;
- end;
- end;
- end;
-
- procedure TMainForm1.FormCreate(Sender: TObject);
- var
- i : Cardinal;
- S : String;
- begin
- DisplayedIcon := 2;
- IniFile := TIniFile.Create(IniFileName);
- CDNameLabel1.Caption := IniFile.ReadString('global',
- 'CDName', 'AutoRun Version 1.0');
- Application.Title := CDNameLabel1.Caption;
- Caption := CDNameLabel1.Caption;
- If CDNameLabel1.Width > (CDNamePanel1.ClientWidth - 10) then
- begin
- repeat
- CDNameLabel1.Font.Size := CDNameLabel1.Font.Size - 1;
- until CDNameLabel1.Width < (CDNamePanel1.ClientWidth - 10);
- CDNameLabel1.Align := alClient;
- end
- else
- begin
- repeat
- CDNameLabel1.Font.Size := CDNameLabel1.Font.Size + 1;
- until CDNameLabel1.Height > CDNamePanel1.ClientHeight;
- CDNameLabel1.Align := alClient;
- end;
- i := 1;
- while IniFile.ReadString('items', 'Item' + IntToStr(i), '') <> '' do
- begin
- If (IniFile.ReadString('items',
- 'Item' + IntToStr(i) + 'Command', '') <> '') and
- (InitItemsListBox1.Items.IndexOf(IniFile.ReadString('items',
- 'Item' + IntToStr(i), '')) = -1) then
- begin
- InitItemsListBox1.Items.Add(IniFile.ReadString('items',
- 'Item' + IntToStr(i), ''));
- S := IniFile.ReadString('items', 'Item' + IntToStr(i) + 'Command', '');
- If ExtractFileDrive(S) <> '' then
- Delete(S, 1, 2);
- If S[1] <> '\' then
- S := '\' + S;
- CmdListBox1.Items.Add(S);
- end;
- Inc(i);
- end;
- ItemsListBox1.Items.AddStrings(InitItemsListBox1.Items);
- If IniFile.ReadInteger('options', 'SortItems', 0) = 1 then
- begin
- SortAction1.Checked := True;
- SortAction1Execute(Sender);
- end;
- If IniFile.ReadInteger('options', 'IconifyAfterExec', 0) = 1 then
- ExecIconiAction1.Checked := True;
- If IniFile.ReadInteger('options', 'CloseAfterExec', 0) = 1 then
- ExecCloseAction1.Checked := True;
- end;
-
- procedure TMainForm1.ShortcutsAction1Execute(Sender: TObject);
- begin
- ShortCutForm1.ShowModal;
- end;
-
- procedure TMainForm1.ExploreCDAction1Execute(Sender: TObject);
- begin
- ShellExecute(0, 'explore', PChar(CDDrive + '\'), '', '', SW_Normal);
- end;
-
- procedure TMainForm1.FormDestroy(Sender: TObject);
- begin
- IniFile.Free;
- end;
-
- procedure TMainForm1.ExecIconiAction1Execute(Sender: TObject);
- begin
- ExecIconiAction1.Checked := not ExecIconiAction1.Checked;
- end;
-
- procedure TMainForm1.ExecCloseAction1Execute(Sender: TObject);
- begin
- ExecCloseAction1.Checked := not ExecCloseAction1.Checked;
- end;
-
- procedure TMainForm1.AssocAction1Execute(Sender: TObject);
- var
- S : String;
- begin
- S := ItemsListBox1.Items[ItemsListBox1.ItemIndex];
- If InitItemsListBox1.Items.IndexOf(S) = -1 then
- begin
- ErrorForm1.ShowModal;
- Close;
- Exit;
- end;
- If ShellExecute(0, 'open', PChar(CDDrive +
- CmdListBox1.Items[InitItemsListBox1.Items.IndexOf(S)]),
- '', '', SW_Normal) <= 32 then
- begin
- EventForm1.Execute(ARE_CantExec);
- Exit;
- end;
- If ExecCloseAction1.Checked then
- begin
- Close;
- Exit;
- end;
- If ExecIconiAction1.Checked then
- Application.Minimize;
- end;
-
- procedure TMainForm1.UserAppAction1Execute(Sender: TObject);
- var
- S : String;
- begin
- S := ItemsListBox1.Items[ItemsListBox1.ItemIndex];
- If InitItemsListBox1.Items.IndexOf(S) = -1 then
- begin
- ErrorForm1.ShowModal;
- Close;
- Exit;
- end;
- If not OpenDialog1.Execute then
- Exit;
- If ShellExecute(0, 'open', PChar(OpenDialog1.FileName), PChar(CDDrive +
- CmdListBox1.Items[InitItemsListBox1.Items.IndexOf(S)]),
- '', SW_Normal) <= 32 then
- begin
- EventForm1.Execute(ARE_CantExec);
- Exit;
- end;
- If ExecCloseAction1.Checked then
- begin
- Close;
- Exit;
- end;
- If ExecIconiAction1.Checked then
- Application.Minimize;
- end;
-
- procedure TMainForm1.ExploreAction1Execute(Sender: TObject);
- var
- S : String;
- begin
- S := ItemsListBox1.Items[ItemsListBox1.ItemIndex];
- If InitItemsListBox1.Items.IndexOf(S) = -1 then
- begin
- ErrorForm1.ShowModal;
- Close;
- Exit;
- end;
- If ShellExecute(0, 'explore', PChar(ExtractFilePath(CDDrive +
- CmdListBox1.Items[InitItemsListBox1.Items.IndexOf(S)])),
- '', '', SW_Normal) <= 32 then
- begin
- EventForm1.Execute(ARE_CantExec);
- end;
- end;
-
- procedure TMainForm1.FormShow(Sender: TObject);
- begin
- If ItemsListBox1.Items.Count > 0 then
- ItemsListBox1.ItemIndex := 0;
- ItemsListBox1Click(Sender);
- end;
-
- procedure TMainForm1.ItemsListBox1Click(Sender: TObject);
- var
- S : String;
- begin
- S := ItemsListBox1.Items[ItemsListBox1.ItemIndex];
- If InitItemsListBox1.Items.IndexOf(S) = -1 then
- begin
- ErrorForm1.ShowModal;
- Close;
- Exit;
- end;
- DescriptionStaticText1.Caption := CDDrive + CmdListBox1.Items[
- InitItemsListBox1.Items.IndexOf(S)];
- end;
-
- procedure TMainForm1.ItemsListBox1KeyPress(Sender: TObject; var Key: Char);
- begin
- ItemsListBox1Click(Sender);
- end;
-
- end.
-
-