了解 WM_Copydata 的富翁请进!有问题请教。(50分)

  • 主题发起人 主题发起人 xdzhan
  • 开始时间 开始时间
X

xdzhan

Unregistered / Unconfirmed
GUEST, unregistred user!
我打算使用WM_COPYDATA消息在不同的程序间传递数据,这些数据包括:文件夹、文件等等,<br>请问在我的接收程序中如何将它们一一分解出来,得到这些文件夹和文件的名称?<br>请不吝赐教!谢谢!如果不行有没有其他方法?
 
用消息也可以。C++ Builder例子:<br>#define WM_SELFMSG (WM_USER+100)<br>LPSTR str="asdasd";<br>LPARAM lp=(LPARAM)str;<br>PostMessage(Handle,WM_SELFMSG,0,lp);<br><br>处理消息:<br>AnisString str=(LPSTR)lp;
 
//分少了点,但总比没有好<br>//接受<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br>Const<br>SfMsg : Array[0..2] of String=('股东信息','代理一信息','代理二信息');<br>Type<br>&nbsp;SFArray= Array[1..20]of Char &nbsp;;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp;procedure Receivemsg(var Message: TMessage) ; Message WM_COPYDATA;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br>PSfyzxtInformation = ^TSfyzxtInformation;<br>TSfyzxtInformation = packed record<br>&nbsp; &nbsp;Checkid: &nbsp; &nbsp;SFArray ;<br>&nbsp; &nbsp;Name: &nbsp; &nbsp; &nbsp; SFArray ;<br>&nbsp; &nbsp;CardId: &nbsp; &nbsp; SFArray ; &nbsp; &nbsp; &nbsp;<br>&nbsp;end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; Inf: PSfyzxtInformation;<br>implementation<br><br>{$R *.DFM}<br><br><br>procedure TForm1.Receivemsg(var Message: TMessage) ;<br>begin<br>&nbsp; Memo1.Lines.Clear ;<br>&nbsp; Memo1.Lines.add(SfMsg[integer(PCOPYDATASTRUCT(Message.LParam)^.dwData) ]);<br>&nbsp; Memo1.Lines.add(PSfyzxtInformation((PCOPYDATASTRUCT(Message.LParam)^.lpData ))^.Checkid);<br>&nbsp; Memo1.Lines.add(PSfyzxtInformation((PCOPYDATASTRUCT(Message.LParam)^.lpData ))^.Name);<br>&nbsp; Memo1.Lines.add(PSfyzxtInformation((PCOPYDATASTRUCT(Message.LParam)^.lpData ))^.Cardid);<br>end;<br><br>end.<br><br>//发送<br><br>unit Unit2;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br>Type<br>&nbsp;SFArray= Array[1..20]of Char &nbsp;;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Label2: TLabel;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; &nbsp; Label3: TLabel;<br>&nbsp; &nbsp; Edit3: TEdit;<br>&nbsp; &nbsp; ComboBox1: TComboBox;<br>&nbsp; &nbsp; Label4: TLabel;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br><br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>PSfyzxtInformation = ^TSfyzxtInformation;<br>TSfyzxtInformation = packed record<br>&nbsp; &nbsp;Checkid: &nbsp; &nbsp;SFArray ;<br>&nbsp; &nbsp;Name: &nbsp; &nbsp; &nbsp; SFArray ;<br>&nbsp; &nbsp;CardId: &nbsp; &nbsp; SFArray ; &nbsp; &nbsp; &nbsp;<br>&nbsp;end;<br><br><br>var<br>&nbsp; Form1: TForm1;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>Var<br>Cd : PCOPYDATASTRUCT ;<br>Inf: PSfyzxtInformation;<br>Hwnd:Thandle;<br>begin<br>hwnd:=Findwindow(Nil,'WM_COPYDATA范例');<br>if Hwnd = 0 then begin Showmessage('窗口没有找到!');Exit;end;<br>try<br>&nbsp; &nbsp; Getmem(Inf, sizeof(TSfyzxtInformation));<br>&nbsp; &nbsp; strpcopy(@inf.Checkid,Edit1.Text );<br>&nbsp; &nbsp; strpcopy(@inf.Name,Edit2.Text );<br>&nbsp; &nbsp; strpcopy(@inf.CardId,Edit3.Text );<br>&nbsp; &nbsp; Getmem(cd,sizeof(TCOPYDATASTRUCT));<br>&nbsp; &nbsp; cd.dwData:=Dword(Combobox1.ItemIndex );<br>&nbsp; &nbsp; cd.cbData:=sizeof(SFArray)*3;<br>&nbsp; &nbsp; cd.lpData:=Inf;<br>&nbsp; &nbsp; Sendmessage(Hwnd,WM_COPYDATA,Handle,LPARAM(cd));<br>finally<br>&nbsp; &nbsp; Freemem(cd);<br>&nbsp; &nbsp; Freemem(Inf) ;<br><br>end;<br>end;<br><br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; ComboBox1.ItemIndex:= 0 ;<br>end;<br><br>end.<br><br><br>
 
谢谢!<br>我的思路是用鼠标随意选取一些文件和文件夹,用wm_COPYDATA发送给我的程序!<br>由于不知道这些文件或文件夹的名称和数目,请问接收程序该如何分解除他们呢?<br>在此感谢!
 
应该可以,你把发送端改改,可以的,具体的我没时间写<br>再等等其他人吧
 
多人接受答案了。
 
后退
顶部