ConfigExt.pas
上传用户:mjqmds
上传日期:2022-05-05
资源大小:2827k
文件大小:7k
源码类别:

DirextX编程

开发平台:

Delphi

  1. unit ConfigExt;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, CheckLst, TFlatButtonUnit, XPMenu,
  6.   TFlatCheckListBoxUnit, StrUtils;
  7. type
  8.   TCEForm = class(TForm)
  9.     RadioButton1: TRadioButton;
  10.     RadioButton2: TRadioButton;
  11.     RadioButton3: TRadioButton;
  12.     FlatCheckListBox1: TFlatCheckListBox;
  13.     XPMenu1: TXPMenu;
  14.     FlatButton1: TFlatButton;
  15.     FlatButton2: TFlatButton;
  16.     procedure RadioButton1Click(Sender: TObject);
  17.     procedure RadioButton2Click(Sender: TObject);
  18.     procedure RadioButton3Click(Sender: TObject);
  19.     procedure FlatButton1Click(Sender: TObject);
  20.     procedure FlatButton2Click(Sender: TObject);
  21.     procedure FormCreate(Sender: TObject);
  22.   private
  23.     procedure UpdateRegister(bLoad:Boolean=false);
  24.     procedure CustomSelects(b:Boolean; Exts:String);
  25.     { Private declarations }
  26.   public
  27.     { Public declarations }
  28.   end;
  29. var
  30.   CEForm: TCEForm;
  31. implementation
  32. uses Main, RegFiles;
  33. {$R *.dfm}
  34. function GetExt(Str:String):String;
  35. Var
  36.     Index:Integer;
  37. begin
  38.     Index:=Pos('->',Str);
  39.     Result:=Copy(Str,1,Index-1);
  40.     Result:=Trim(Result);
  41. end;
  42. function GetIconIndex(Ext:String):Integer;
  43. begin
  44.     Result:=2;
  45.     Ext:=UpperCase(Trim(Ext));
  46.     if Ext='.ASF' then
  47.         Result:=1
  48.     else if Ext='.AVI' then
  49.         Result:=3
  50.     else if Ext='.BF' then
  51.         Result:=4
  52.     else if Ext='.DAT' then
  53.         Result:=5
  54.     else if Ext='.DVD' then
  55.         Result:=6
  56.     else if Ext='.SWF' then
  57.         Result:=7
  58.     else if Ext='.WPL' then
  59.         Result:=8
  60.     else if Ext='.M4B' then
  61.         Result:=9
  62.     else if Ext='.M4P' then
  63.         Result:=10
  64.     else if Ext='.M4V' then
  65.         Result:=11
  66.     else if Ext='.MKV' then
  67.         Result:=12
  68.     else if Ext='.MP3' then
  69.         Result:=13
  70.     else if Ext='.MP4' then
  71.         Result:=14
  72.     else if Ext='.MPEG' then
  73.         Result:=15
  74.     else if Ext='.MPG' then
  75.         Result:=16
  76.     else if Ext='.OGM' then
  77.         Result:=17
  78.     else if Ext='.PSS' then
  79.         Result:=18
  80.     else if Ext='.PVA' then
  81.         Result:=19
  82.     else if Ext='.MOV' then
  83.         Result:=20
  84.     else if (Ext='.RM') OR (Ext='.RMVB') then
  85.         Result:=21
  86.     else if Ext='.TP' then
  87.         Result:=22
  88.     else if Ext='.TPR' then
  89.         Result:=23
  90.     else if Ext='.TS' then
  91.         Result:=24
  92.     else if Ext='.VOB' then
  93.         Result:=25
  94.     else if Ext='.WM' then
  95.         Result:=26
  96.     else if Ext='.WMA' then
  97.         Result:=27
  98.     else if Ext='.WMP' then
  99.         Result:=28
  100.     else if Ext='.MMV' then
  101.         Result:=29
  102. end;
  103. procedure TCEForm.CustomSelects(b: Boolean; Exts:String);
  104. Var
  105.     i:Integer;
  106.     Tmp:String;
  107. begin
  108.     Exts:=UpperCase(Exts);
  109.     For i:=0 to FlatCheckListBox1.Items.Count-1 do
  110.     begin
  111.         Tmp:=UpperCase(GetExt(FlatCheckListBox1.Items.Strings[i]));
  112.         if AnsiPos(Tmp,Exts)<>0 then
  113.             FlatCheckListBox1.Checked[i]:=b
  114.         else
  115.             FlatCheckListBox1.Checked[i]:=Not b;
  116.     end;
  117. end;
  118. procedure TCEForm.RadioButton1Click(Sender: TObject);
  119. begin
  120.     CustomSelects(true,'.RM,.3GP,.MP4,.3G,.RMVB,.AVI,.WMV,.ASF,.DAT,.VOB,.MPG,.MKV,.MOV,.MP3,.WMA,.WAV,.WPL');
  121. end;
  122. procedure TCEForm.RadioButton2Click(Sender: TObject);
  123. begin
  124.     CustomSelects(true,'.RM,.RMVB,.AVI,.WMV,.ASF,.DAT,.VOB,.MPG,.MKV,.MOV,.3GP,.MP4,.3G,.WPL');
  125. end;
  126. procedure TCEForm.RadioButton3Click(Sender: TObject);
  127. begin
  128.     CustomSelects(true,'.MP3,.WMA,.WAV,.WPL');
  129. end;
  130. procedure TCEForm.FlatButton1Click(Sender: TObject);
  131. Var
  132.     i:Integer;
  133.     Str:String;
  134. begin
  135.     For i:=0 to FlatCheckListBox1.Items.Count-1 do
  136.     begin
  137.         if FlatCheckListBox1.Checked[i] then
  138.         begin
  139.             if Str='' then
  140.                 Str:=FlatCheckListBox1.Items[i]
  141.             else
  142.                 Str:=Str+','+FlatCheckListBox1.Items[i];
  143.         end;
  144.     end;
  145.     if RadioButton1.Checked then
  146.         Str:=RadioButton1.Name+','+Str
  147.     else if RadioButton2.Checked then
  148.         Str:=RadioButton2.Name+','+Str
  149.     else
  150.         Str:=RadioButton3.Name+','+Str;
  151.     MainForm.WriteIni('Play','Exts',Str);
  152.     UpdateRegister;
  153.     ModalResult:=mrok;
  154. end;
  155. procedure TCEForm.UpdateRegister(bLoad:Boolean=false);
  156. Var
  157.     i:Integer;
  158.     Str,Tmp:String;
  159.     StrList:TStringList;
  160. Var
  161.     Radio:TRadioButton;
  162. begin
  163.     StrList:=TStringList.Create;
  164.     Try
  165.         if bLoad then
  166.         begin
  167.             Str:=UpperCase(MainForm.ReadIni('Play','Exts',''));
  168.             StrList.Text:=AnsiReplaceStr(Str,',',#13#10);
  169.             if StrList.Count=0 then
  170.             begin
  171.                 Radio:=RadioButton1;
  172.                 Radio.Checked:=true;
  173.                 Radio.OnClick(Radio);
  174.             end
  175.             else
  176.             begin
  177.                 Radio:=TRadioButton(Self.FindComponent(StrList.Strings[0]));
  178.                 Radio.Checked:=true;
  179.                 Radio.OnClick(Radio);
  180.             end;
  181.         end;
  182.         For i:=0 to FlatCheckListBox1.Items.Count-1 do
  183.         begin
  184.             Tmp:=UpperCase(GetExt(FlatCheckListBox1.Items[i]));
  185.             if bLoad then
  186.             begin
  187.                 FlatCheckListBox1.Checked[i]:=Pos(Tmp,Str)<>0;
  188.             end;
  189.             if FlatCheckListBox1.Checked[i] then
  190.             begin
  191.                 CreateAssociation(Tmp,Application.ExeName,Application.ExeName+','+IntToStr(GetIconIndex(ExtractFileExt(Tmp))),
  192.                     'WHSUPPERPLAY'+Tmp,'老王的超级播放器',false);
  193.             end
  194.             else
  195.                 RemoveAssociation(Tmp,'WHSUPPERPLAY'+Tmp,
  196.                     true,false);
  197.         end;
  198.     Finally
  199.         StrList.Free;
  200.     end;
  201.     if Not bLoad then
  202.         CreateAssociation('','','','','',true);
  203. end;
  204. procedure TCEForm.FlatButton2Click(Sender: TObject);
  205. begin
  206.     ModalResult:=mrCancel;
  207. end;
  208. procedure TCEForm.FormCreate(Sender: TObject);
  209. Var
  210.     i:Integer;
  211. begin
  212.     FlatCheckListBox1.Items.Add('.RM          ->视频文件');
  213.     FlatCheckListBox1.Items.Add('.RMVB        ->视频文件');
  214.     FlatCheckListBox1.Items.Add('.AVI         ->视频文件');
  215.     FlatCheckListBox1.Items.Add('.WMV         ->视频文件');
  216.     FlatCheckListBox1.Items.Add('.ASF         ->视频文件');
  217.     FlatCheckListBox1.Items.Add('.DAT         ->视频文件');
  218.     FlatCheckListBox1.Items.Add('.VOB         ->视频文件');
  219.     FlatCheckListBox1.Items.Add('.MPG         ->视频文件');
  220.     FlatCheckListBox1.Items.Add('.MKV         ->视频文件');
  221.     FlatCheckListBox1.Items.Add('.MOV         ->视频文件');
  222.     FlatCheckListBox1.Items.Add('.MP3         ->声音文件');
  223.     FlatCheckListBox1.Items.Add('.WMA         ->声音文件');
  224.     FlatCheckListBox1.Items.Add('.WAV         ->声音文件');
  225.     FlatCheckListBox1.Items.Add('.WPL         ->播放列表文件');
  226.     UpdateRegister(true);
  227.     for i:=0 to  FlatCheckListBox1.Items.Count-1 do
  228.     begin
  229.         if FlatCheckListBox1.Checked[i] then
  230.             Exit;
  231.     end;
  232.     RadioButton1.OnClick(RadioButton1);
  233. end;
  234. end.