wParam怎么总是0(100分)

  • 主题发起人 主题发起人 Kang
  • 开始时间 开始时间
K

Kang

Unregistered / Unconfirmed
GUEST, unregistred user!
if wParam&gt;0 then SendMessage(hWnd,WM_USER+100,wParam,0);<br>可我对WM_USER+100处理时,收到的wParam却时0,Why?
 
Return Value<br>If the function succeeds, it returns a message specific value<br>&nbsp;indicating the result of the message processing. If the <br>function fails, it returns zero.<br><br>maybe fail?<br><br>
 
说明 <br>调用一个窗口的窗口函数,将一条消息发给那个窗口。除非消息处理完毕,否则该函数不会返回。SendMessageBynum, SendMessageByString是该函数的“类型安全”声明形式 <br>返回值 <br>Long,由具体的消息决定 <br>参数表 <br>参数 类型及说明 <br>hwnd Long,要接收消息的那个窗口的句柄 <br>wMsg Long,消息的标识符 <br>wParam Long,具体取决于消息 <br>lParam Any,具体取决于消息 <br>
 
》wjiachun<br>&nbsp; 不会是fail,因为我接收到了消息,并响应。<br>》千中元 <br>&nbsp; 我发送的是非0,可接收到的却是0<br><br>多谢二位光临,可我需要根据wParam的不同来进行相应处理,再帮我想想
 
这个...<br>我去看看
 
呵呵,我发怎么没问题,同一程序,程序间都试过。
 
把程序简化一下,请大家帮忙看看:<br><br>unit Unit1a;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; procedure pro(var msg:TMsg);message WM_USER+100;<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>implementation<br><br>{$R *.DFM}<br>uses Unit2;<br><br>var tthr:temp;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;if not Assigned(tthr) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hWnd:=handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IsTrue:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tthr:=temp.Create(false);<br>&nbsp; &nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;IsTrue:=false;<br>&nbsp; &nbsp;if Assigned(tthr) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tthr.Terminate; &nbsp;tthr:=nil;<br>&nbsp; &nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.pro(var msg:TMsg);<br>begin<br>&nbsp; &nbsp;Edit1.Text:=inttostr(strtoint(Edit1.Text)+1);<br>&nbsp; &nbsp;Edit2.Text:=inttostr(msg.wParam); //一直是0;<br>end;<br><br>end.<br><br>Unit2:<br>unit Unit2;<br><br>interface<br><br>uses<br>&nbsp; Classes, mmSystem, Messages, Forms, Windows;<br><br>type<br>&nbsp; temp = class(TThread)<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; protected<br>&nbsp; &nbsp; procedure Execute; override;<br>&nbsp; &nbsp; procedure FreeTimer(Sender: TObject);<br>&nbsp; end;<br><br>var hWnd:LongInt; &nbsp;tID,i:UINT; &nbsp;IsTrue:boolean;<br><br>implementation<br><br>{ Important: Methods and properties of objects in VCL can only be used in a<br>&nbsp; method called using Synchronize, for example,<br><br>&nbsp; &nbsp; &nbsp; Synchronize(UpdateCaption);<br><br>&nbsp; and UpdateCaption could look like,<br><br>&nbsp; &nbsp; procedure temp.UpdateCaption;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Form1.Caption := 'Updated in a thread';<br>&nbsp; &nbsp; end; }<br><br>{ temp }<br>procedure temppro(uTimerID, uMessage: UINT;dwUser, dw1, dw2: DWORD); stdcall;<br>begin<br>&nbsp; &nbsp; Inc(i);<br>&nbsp; &nbsp; if i mod 10=0 then SendMessage(hWnd,WM_USER+100,i div 10,0);<br>end;<br><br>procedure temp.Execute;<br>var Mypro:TFNTimeCallBack;<br>begin<br>&nbsp; FreeOnTerminate:=true;<br>&nbsp; OnTerminate:=FreeTimer;<br>&nbsp; Mypro:=temppro;<br>&nbsp; tID:=TimeSetEvent(100,1,Mypro,0,1);<br>&nbsp; While IsTrue do Application.ProcessMessages;<br>&nbsp; { Place thread code here }<br>end;<br><br>procedure temp.FreeTimer(Sender: TObject);<br>begin<br>&nbsp; &nbsp;TimeKillEvent(tID);<br>end;<br><br>end.
 
请大家帮忙,我请大家喝喜酒
 
kang<br>&nbsp; &nbsp;到现在还想着程序,不怕嫂子吃醋?
 
》千中元<br>&nbsp; &nbsp;离着千里呢。可程序就在这摆着 :(
 
将Unit1a改为:<br><br>unit Unit1a;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; procedure pro(var msg:TMessage);message WM_USER+100;<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>implementation<br><br>{$R *.DFM}<br>uses Unit2;<br><br>var tthr:temp;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;if not Assigned(tthr) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hWnd:=handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IsTrue:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tthr:=temp.Create(false);<br>&nbsp; &nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;IsTrue:=false;<br>&nbsp; &nbsp;if Assigned(tthr) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tthr.Terminate; &nbsp;tthr:=nil;<br>&nbsp; &nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.pro(var msg:TMessage);<br>begin<br>&nbsp; &nbsp;Edit1.Text:=inttostr(strtoint(Edit1.Text)+1);<br>&nbsp; &nbsp;Edit2.Text:=inttostr(msg.wParam); //一直是0;<br>end;<br><br>end.
 
没看帮助,让TMsg给坑了 :(
 
后退
顶部