在程序中相当于加了一个参数 abc.exe param1 一样 在程序中如果测到有参数
则自动打开文件并播放

解决方案 »

  1.   

    你的email?
    给你一个例子
      

  2.   

    把你程序关联到swf文件啊,可能要写注册表.
    ---------
    实际上你没有考虑参数:  if(ParamCount() >0)
      {
        MessageBox(this->Handle,AnsiString("OpenFile="+
                   ParamStr(1)).c_str(),NULL,
                   MB_OK | MB_APPLMODAL | MB_ICONWARNING);
      }我已经试过了,可以得到双击的那个文件.
      

  3.   

    把你程序关联到swf文件啊,可能要写注册表.
    ---------
    实际上你没有考虑参数:  if(ParamCount() >0)
      {
        MessageBox(this->Handle,AnsiString("OpenFile="+
                   ParamStr(1)).c_str(),NULL,
                   MB_OK | MB_APPLMODAL | MB_ICONWARNING);
      }我已经试过了,可以得到双击的那个文件.
      

  4.   

    TO:kmzym ,我的mail是:[email protected],多谢了。
    To:BCB_FANS,你写的是c++的例子吧,delphi怎么写?能不能具体点?
      

  5.   

    FileName:String;if ParamCount() >0 then
    begin
      FileName:=ParamStr(1);//或ParamStr(2),你自己试一下.  
    end
      

  6.   

    修改文件关联:
    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;
      

  7.   

    修改文件关联:
    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;
      

  8.   

    刚才的不好,你还是用下面的吧:
    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;
      

  9.   

    在delphi中也有象c语言中的main(argv,argc[])这样的主程序参数,应为delphi没有一个函数作为入口点,所以一般作为一个全局的变量来使用,其中有一个integer型的变量ParamCount用来说明有多少个命令行参数,ParamStr(i)用来存放命令行参数中用空格隔开的参数集,使用的时候就像BCB_FANS(四大名捕之追杀令) 说的那样就可以了。
      if(ParamCount() >0)
      {
         FileName := ParamStr(1);  //一般FileName就得到第一个参数,从0开始,包含应用程序名称
      }然后可以使用你的程序去操作这个文件了。
    另外,还要将文件类型与这个程序文件关联起来,这样才能够直接打开这个文件^-^