求教关联文件打开方式更好的办法(200)

  • 主题发起人 popogens
  • 开始时间
P

popogens

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了个软件,自定义了cwf类型文件,并在自制的setup中写注册表:procedure TMain.RegOpen(CurrentDir: String);var Key: String;begin with RegCase do begin RootKey := HKEY_CLASSES_ROOT; //该分支下设定内容 Key := 'CaseManage'; WriteString(Key , 'path', CurrentDir); //写入安装路径 Key := 'CaseManage/shell/打开(&O)/command'; WriteString(Key , '', CurrentDir + 'ManageCasesServer.exe "%1"');//“打开(&O)”方式 Key := 'CaseManage/shell'; WriteString( Key , '', '打开(&O)'); //另一个分支设定同上 RootKey := HKEY_LOCAL_MACHINE; if not KeyExists('SOFTWARE/Classes/CaseManage/shell/打开(&O)') then CreateKey('SOFTWARE/Classes/CaseManage/shell/打开(&O)'); Key := 'SOFTWARE/Classes/.cwf'; WriteString(Key, '', 'CaseManage'); Key := 'SOFTWARE/Classes/CaseManage/shell/打开(&O)/command'; WriteString(Key , '', CurrentDir + 'ManageCasesServer.exe "%1"'); Key := 'SOFTWARE/Classes/CaseManage/shell'; WriteString( Key , '', '打开(&O)'); //设定图标 Key := 'SOFTWARE/Classes/CaseManage/DefaultIcon'; WriteString( Key , '', CurrentDir + 'ManageCases.exe,0'); CloseKey; Free; end;end;这样我可以在双击cwf文件时自动用ManageCases.exe打开(实际是ManageCasesserver.exe再调用ManageCases.exe)但问题是我现在想要实现的效果如下:在Windows文件夹中选中多个cwf文件,一按回车启动一个ManageCases.exe,把所有的cwf都用同一个ManageCases.exe进程打开。我在ManageCases.exe中加了消息监听过程:procedure TMain.ProcessMyMsg(var Message: TMessage);var cds: PCopyDataStruct; S: string;begin if is1st then begin try Splash.Show; Splash.Update; except Splash := TSplash.Create(nil); Splash.Update; end; cds := Pointer(Message.Lparam); S := Copy(PChar(Pointer(cds.lpData)), 1, cds.cbData); Message.Result := 0; OpenOrCreateACWFFile(S); try Splash.Release; except end; end;end;并在ManageCasesserver.exe(无窗体的单个工程文件的工程)中加入了消息发送过程:var cds: TCopyDataStruct; Recipients: DWord; pData : array [0..255] of Char; M: TMessage; Find, Found: Boolean; hSnapshot: THandle; lppe: TProcessEntry32; IID: Integer; S, AFileName: String;begin Application.Initialize; Found := false; hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); lppe.dwSize := SizeOf(TProcessEntry32); Find := Process32First(hSnapshot, lppe); AFileName := 'ManageCases.exe'; while Find do begin if ((UpperCase(ExtractFileName(lppe.szExeFile)) = UpperCase(AFileName)) or (UpperCase(lppe.szExeFile ) = UpperCase(AFileName))) then Found := True; Find := Process32Next(hSnapshot, lppe); end; if Found then Sleep(300)//不sleep好象经常会失败,但终究不是个好办法 else WinExec(PChar(ExtractFilePath(Application.ExeName) + 'ManageCases.exe'), SW_ShowNormal); Found := false; hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); lppe.dwSize := SizeOf(TProcessEntry32); Find := Process32First(hSnapshot, lppe); AFileName := 'ManageCases.exe'; IID := 1025;//算出接收消息的进程ID,这样不会影响其他进程是吗? while Find do begin if ((UpperCase(ExtractFileName(lppe.szExeFile)) = UpperCase(AFileName)) or (UpperCase(lppe.szExeFile ) = UpperCase(AFileName))) then IID := lppe.th32ProcessID; Find := Process32Next(hSnapshot, lppe); end; S := ParamStr(1); M.Msg := WM_COPYDATA; Recipients := BSM_ALLCOMPONENTS; FillChar(pData, 256, #0); StrPCopy(pData, S); cds.cbData := SizeOf(pData); cds.lpData := @pData; BroadcastSystemMessage(BSF_POSTMESSAGE, @Recipients, M.Msg, IID, LParam(@cds)); Application.Run;这样,在选中多个cwf文件时,按下回车后,等于启动了多个ManageCasesserver.exe进程,这些进程会将自己的参数再发给ManageCases.exe进程,ManageCases.exe会逐个接收。第一次出现了问题,当电脑中有迅雷或者Winamp启动时,Winamp和迅雷会自作多情的去接收这个消息,然后告诉我:种子解析失败,因此我才加了上述 IID := 1025;//算出接收消息的进程ID,这样不会影响其他进程是吗?这一句,迅雷不再有反应,Winamp仍然会出现问题。同时,那个Sleep(300)始终不是个好办法,我只能保证它“少犯错误”(有时会少打开一个cwf文件),不能保证“不犯错误”。我最想的效果是象Word文件(.doc)那样,选中多个doc,一按回车,会用同一个word进程打开它,看了一下注册表,好象很复杂,学不会。有没有人会的,请赐教,给的是最高分,谢谢。
 
顶部