在程序中相当于加了一个参数 abc.exe param1 一样 在程序中如果测到有参数
则自动打开文件并播放
则自动打开文件并播放
解决方案 »
- IdUDPServer有接收事件,IdUDPClient为何没有接收事件?它怎样接收数据呢?
- 请高手或大侠帮忙解决一下问题????
- 请问如何将该TXT文件对应的各个字段写入数据库?谢谢!!
- VB转Delphi中的字符串操作问题
- ErWin 4.0 在连接不上SqlServer 2000数据库,请帮助解决一下,急急急!!!
- ADODataSet有沒有讓某字段一次性填充指定值的屬性。
- Win2000+D6开发MTS,为什么导出组件的时候找不到msi文件?高手啊,显一下神威吧!
- 高手指点,如何将要打印的报表存成EXECL文件格式。
- 游戏服务器漏洞大讨论
- 大家帮帮我???我给分!!!!!!!!
- delphi操作access和SQL SERVER数据库有什么不同的地方的吗?
- 用回车输入跳到下一个控件
给你一个例子
---------
实际上你没有考虑参数: if(ParamCount() >0)
{
MessageBox(this->Handle,AnsiString("OpenFile="+
ParamStr(1)).c_str(),NULL,
MB_OK | MB_APPLMODAL | MB_ICONWARNING);
}我已经试过了,可以得到双击的那个文件.
---------
实际上你没有考虑参数: if(ParamCount() >0)
{
MessageBox(this->Handle,AnsiString("OpenFile="+
ParamStr(1)).c_str(),NULL,
MB_OK | MB_APPLMODAL | MB_ICONWARNING);
}我已经试过了,可以得到双击的那个文件.
To:BCB_FANS,你写的是c++的例子吧,delphi怎么写?能不能具体点?
begin
FileName:=ParamStr(1);//或ParamStr(2),你自己试一下.
end
function FileAssociate(ext:string;addorremove:boolean=true;iconcount:integer=-1;errormsg:boolean=false;exepath:string='#0'):boolean;
var
reg:tregistry;
keyvalue:string;
ext1:string;
i:integer;
begin
ext1:=ext;
for i:=0 to length(ext)-1 do
begin
ext1[i]:=ext[i+1];
end;
//ext1[length(ext)]:=#0;
setlength(ext1,length(ext)-1); if exepath='#0' then exepath:=application.ExeName;
keyvalue:=ext1+'file';
reg:=tregistry.Create;
reg.RootKey:=HKEY_CLASSES_ROOT; if addorremove then
begin
if reg.OpenKey(ext,true) then
begin reg.WriteString('',keyvalue);
reg.CloseKey; end
else
begin
result:=false;
if errormsg then msg('Sorry,but the registry could not be opened.',mb_iconerror);
reg.Free;
exit;
end;
end
else
begin
if reg.DeleteKey(ext) and reg.DeleteKey(ext1+'files') then
begin
result:=true;
reg.Free;
exit;
end
else
result:=false;
if errormsg then msg('Sorry,but the file association could not be removed.',mb_iconerror);
reg.Free;
exit;
end; if reg.OpenKey(keyvalue+'\DefaultIcon',true) then
begin
reg.WriteString('','"'+exepath+'"'+','+inttostr(iconcount));
reg.CloseKey;
end
else
begin
result:=false;
if errormsg then msg('Sorry,but the registry could not be opened.',mb_iconerror);
reg.Free;
exit;
end; if reg.OpenKey(keyvalue+'\shell\open\command',true) then
begin
reg.WriteString('','"'+exepath+'" "%1');
reg.CloseKey;
end
else
begin
result:=false;
if errormsg then msg('Sorry,but the registry could not be opened.',mb_iconerror);
reg.Free;
exit;
end;
result:=true;
reg.Free;
end;
function FileAssociate(ext:string;addorremove:boolean=true;iconcount:integer=-1;errormsg:boolean=false;exepath:string='#0'):boolean;
var
reg:tregistry;
keyvalue:string;
ext1:string;
i:integer;
begin
ext1:=ext;
for i:=0 to length(ext)-1 do
begin
ext1[i]:=ext[i+1];
end;
setlength(ext1,length(ext)-1); if exepath='#0' then exepath:=application.ExeName;
keyvalue:=ext1+'file';
reg:=tregistry.Create;
try
reg.RootKey:=HKEY_CLASSES_ROOT; if addorremove then
begin
if reg.OpenKey(ext,true) then
begin reg.WriteString('',keyvalue);
reg.CloseKey; end
else
begin
result:=false;
if errormsg then msg('Sorry,but the registry could not be opened.',mb_iconerror);
reg.Free;
exit;
end;
end
else
begin
if reg.DeleteKey(ext) and reg.DeleteKey(ext1+'files') then
begin
result:=true;
reg.Free;
exit;
end
else
result:=false;
if errormsg then msg('Sorry,but the file association could not be removed.',mb_iconerror);
reg.Free;
exit;
end; if reg.OpenKey(keyvalue+'\DefaultIcon',true) then
begin
reg.WriteString('','"'+exepath+'"'+','+inttostr(iconcount));
reg.CloseKey;
end
else
begin
result:=false;
if errormsg then msg('Sorry,but the registry could not be opened.',mb_iconerror);
reg.Free;
exit;
end; if reg.OpenKey(keyvalue+'\shell\open\command',true) then
begin
reg.WriteString('','"'+exepath+'" "%1');
reg.CloseKey;
end
else
begin
result:=false;
if errormsg then msg('Sorry,but the registry could not be opened.',mb_iconerror);
reg.Free;
exit;
end;
result:=true;
finclly
reg.Free;
end;
end;
function SetFileAssociation(Ext:string;
OpenApp:string;
FileTypeDescription:string='';
OpenMenuCaption:string='';
IconFile:string='';
IconIndex:integer=0;
Notify:boolean=true):boolean;
var
reg:tregistry;
key:string;
label
final;
begin
result:=false;
if ext='' then exit;
if ext[1]<>'.' then ext:='.'+ext;
if openmenucaption='' then openmenucaption:='&Open';
if IconFile='' then IconFile:=openapp;
key:=copy(ext,2,length(ext))+' File';
if filetypedescription='' then filetypedescription:=key;//////////////////////////////////////////
try
reg:=tregistry.Create;
reg.RootKey:=hkey_classes_root;
if reg.OpenKey(ext,true) then
begin
reg.WriteString('',key);
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key,true) then
begin
reg.WriteString('',filetypedescription);
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key+'\DefaultIcon',true) then
begin
reg.WriteString('',openapp+','+inttostr(iconindex));
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key+'\Shell\Open',true) then
begin
reg.WriteString('',openmenucaption);
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key+'\Shell\Open\Command',true) then
begin
reg.WriteString('','"'+openapp+'" "%1"');
reg.CloseKey;
end
else
goto final;
if notify then
notifyassociationchange;
result:=true;
final:
finally
reg.Free;
end;
end;
procedure NotifyAssociationChange;
begin
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
if(ParamCount() >0)
{
FileName := ParamStr(1); //一般FileName就得到第一个参数,从0开始,包含应用程序名称
}然后可以使用你的程序去操作这个文件了。
另外,还要将文件类型与这个程序文件关联起来,这样才能够直接打开这个文件^-^