Program association

Operation

So, can programs written in VB realize this function?

This requires the use of the Command function that comes with VB. The Command function is very mysterious in the online help of VB and in the corresponding language tutorial, which is difficult to understand and no reference. The author has discussed and tried with netizens and found that it can obtain the complete FileName including the path in the form of a string, which is undoubtedly very useful.

Instructions

The following is the code snippet of the author's music player, it is this line of code that enables double-clicking and opening:

Private Sub Form_Load()< /p>

Dim dF As String

dF = Command()

With MMControl1

.FileName = dF

. Command = "Open"

.Command = "Play"

End With

End Sub

Dialogs,

< p>Registry,shlobj, StdCtrls, ExtCtrls;

type

TForm1 = class(TForm)

Memo1: TMemo;

Panel1 : TPanel;

Button1: TButton;

procedure Button1Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

private

procedure reg;

{ Private declarations }

public

{ Public declarations }

end ;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.reg;

var

reg: TRegistry;

begin

reg := TRegistry.Create;

< p>reg.RootKey := HKEY_CLASSES_ROOT;

reg.OpenKey('.sos', true);

reg.WriteString('','myzip');

reg.CloseKey;

reg.OpenKey('myzip\shell\open\command', true);

//Can be used to open .sos files Executing the program

reg.WriteString('','"' + application.ExeName +'" "%1"');

reg.CloseKey;

reg.OpenKey('myzip\DefaultIcon',true);

//Take the icon of the current executable program as the icon of the .sos file

reg.WriteString('', ''+application.ExeName+',0');

reg.Free;

//Refresh now

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil );

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

reg;

< p>end;

procedure TForm1.FormCreate(Sender: TObject);

var

sFile: string;

begin p>

if ParamCount > 0 then

begin

(* Get parameter content*)

sFile := ParamStr(1); p>

if LowerCase(ExtractFileExt(sFile))='.sos' then memo1.Lines.LoadFromFile(sfile);

end;

end;

end.

Steps

Type "regedit" in "Start→Run", open the "Registry Editor", and expand the branch "HKEY_CURRENT_USER\Software\Microsoft\Windows \CurrentVersion\Explorer\FileExts\.mp3\OpenWithList". Then delete the key-value items corresponding to the useless program name in the window on the right, such as the key-value items (such as a, b, c) corresponding to the main program (RealPlay.exe) of RealOne Player. In addition, the value of the "MRUList" key value item (string value) must be modified. For example, it was originally "abcd". Now that the "d" key value item is deleted, then it must be changed to "abc".

Related Articles
TOP