您好,请教一个消息处理,谢谢(50分)

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

pcgod

Unregistered / Unconfirmed
GUEST, unregistred user!
您好,我不会用消息处理的那些消息类型,不知道该怎么用 SendMessage 函数, 也不知道<br>该如何在消息函数中取得发送的数据 , 望您指导 。 <br>如 : 点击后发送一个字符串的 SendMessage 与 消息函数该怎么写 ? 谢谢您
 
WM_TRAYNOTIFY=WM_USER + 1;//定义通知消息<br><br>&nbsp;procedure messageproc(var Msg: TMessage);message WM_TRAYNOTIFY;<br>//<br>.................<br>//<br><br><br>sendmessage(desHandle,WM_TRAYNOTIFY,0,0);
 
&nbsp; &nbsp;Procedure WM_Deal(var M : TMessage); message WM_SetText ;<br>implementation<br><br>{$R *.dfm}<br>Procedure TForm1.WM_Deal(var M : TMessage);<br>begin<br>&nbsp; Inherited ;<br>&nbsp; Label1.Caption := Pchar(M.LParam) ;<br><br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; SendMessage(Handle, WM_SetText,0,0) ;<br>end;<br><br><br>我怎样 Send 一个字符串在Label1显示 ? 类似的这些知识我应该怎样学习 ? 通过何种途径 ?<br>谢谢您<br>
 
dlephi 中的 label 是非 Twincontrol,没有 handle ,不能用这种方式设置<br><br>以下是设置 Tedit 中文本内容的代码:<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; sendmessage(edit1.handle,wm_settext,0,integer(pchar('AAA')));<br>end;<br>
 
谢谢jsxjd先生的指导<br>能将 TMessage 各个域的作用给我讲讲吗 ?为何我用<br>&nbsp; Edit1.Text := Pchar(M.LParam) ;<br>&nbsp; Edit1.Text := Pchar(M.Result) ; &nbsp;<br>都可以得到这个字符串 ? TMessage各个域的含义是什么 ? 谢谢<br><br>&nbsp; TMessage = packed record<br>&nbsp; &nbsp; Msg: Cardinal;<br>&nbsp; &nbsp; case Integer of<br>&nbsp; &nbsp; &nbsp; 0: (<br>&nbsp; &nbsp; &nbsp; &nbsp; WParam: Longint;<br>&nbsp; &nbsp; &nbsp; &nbsp; LParam: Longint;<br>&nbsp; &nbsp; &nbsp; &nbsp; Result: Longint);<br>&nbsp; &nbsp; &nbsp; 1: (<br>&nbsp; &nbsp; &nbsp; &nbsp; WParamLo: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; WParamHi: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; LParamLo: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; LParamHi: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; ResultLo: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; ResultHi: Word);<br>&nbsp; end;<br><br>还有, SendMessage 的参数 为什么 ?后面的两个整型一般用来传递什么 ? 谢谢<br>
 
后两个是附加参数。<br>上面可换成这样。<br>SendMessage(Handle, WM_SetText,0,wParam(pchar('AAA'))) ;<br><br>TMessage的帮助如下:<br>TMessage represents a Windows message.<br><br>Unit<br><br>Messages<br><br>type <br>&nbsp; TMessage =packedrecord<br><br>&nbsp; &nbsp; Msg: Cardinal;<br>&nbsp; &nbsp; caseIntegerof<br>&nbsp; &nbsp; &nbsp; 0: (<br>&nbsp; &nbsp; &nbsp; &nbsp; WParam: Longint;<br>&nbsp; &nbsp; &nbsp; &nbsp; LParam: Longint;<br>&nbsp; &nbsp; &nbsp; &nbsp; Result: Longint);<br>&nbsp; &nbsp; &nbsp; 1: (<br>&nbsp; &nbsp; &nbsp; &nbsp; WParamLo: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; WParamHi: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; LParamLo: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; LParamHi: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; ResultLo: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; ResultHi: Word);<br><br>&nbsp; end;<br><br>Description<br><br>The TMessage type represents a Windows message in WndProc and other methods.<br><br>The Msg field represents the Windows Message code.<br><br>The WParam field represents the WParam of the message. To access the low and high words of this field, use the WParamLo and WParamHi fields instead.<br><br>The LParam field represents the LParam of the message. To access the low and high words of this field, use the LParamLo and LParamHi fields instead.<br><br>The Result field holds the return value. To access the low and high words of this field, use the ResultLo and ResultHi fields instead.
 
这个我看不懂:)<br><br>后面两个参数在消息中一般作何用途 ?<br><br>谢谢
 
附加参数,上面的例子中发送与接收文本就是通过其中一个参数。<br>如果参数过多可以通过记录类型发送。
 
发送的消息内容可以通过这两个参数传递(都可以用),是不是 ?<br>能将 TMessage 各个域的作用给我讲讲吗 ?为何我用<br>&nbsp; Edit1.Text := Pchar(M.LParam) ;<br>&nbsp; Edit1.Text := Pchar(M.Result) ; &nbsp;<br>都可以得到这个字符串 ? TMessage各个域的含义是什么 ? 谢谢<br><br>&nbsp;
 
可以通过那两个参数传递。<br>以下这句<br>sendmessage(edit1.handle,wm_settext,0,integer(pchar('AAA')));<br>发送消息的时候,由edit1接收,与form无关,你确定这个方法执行了?<br>Procedure TForm1.WM_Deal(var M : TMessage);<br>begin<br>&nbsp; Inherited ;<br>&nbsp; Label1.Caption := Pchar(M.LParam) ;<br>end;<br>TMessage是一个变体记录,<br>WParamLo与WParamHi合起来就是一个WParam,下同。
 
sendmessage(edit1.handle,wm_settext,0,integer(pchar('AAA')));<br>发送消息的时候,由edit1接收,与form无关,你确定这个方法执行了?<br>-------------------------------------------------------------------<br>确定。这样的,代码如下:<br>------------------------<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; SendMessage(Edit1.Handle, WM_SetText,0,Integer(pchar('1234'))) ;<br>End;<br><br>Procedure TForm1.WM_Deal(var M : TMessage);<br>begin<br>&nbsp; Inherited ;<br>&nbsp; //Edit1.Text := Pchar(M.LParam) ; //这句也可以得到 '1234'<br>&nbsp; Edit1.Text := Pchar(M.Result) ; &nbsp; // 这句可以得到 '1234'<br>end;<br>而在 TMessage &nbsp;的申明中:<br>&nbsp; &nbsp; &nbsp; &nbsp; WParam: Longint;<br>&nbsp; &nbsp; &nbsp; &nbsp; LParam: Longint;<br>&nbsp; &nbsp; &nbsp; &nbsp; Result: Longint);<br>&nbsp; &nbsp;LParam 与 Result 是不同的域 ,应该有不同的含义 ;那为何上面两句可以得到同样的结果呢?<br>谢谢 &nbsp; <br>
 
sendmessage是向edit1发送WM_SETTEXT消息。Procedure TForm1.WM_Deal(var M : TMessage)不可能会收到。<br><br>改为SendMessage(Edit1.Handle, WM_SetText,0,Integer(pchar('更改了'))) ;看看<br><br>关于TMessage,没有什么书详细说明它。有的东西我也不清楚,说多了可能会误导。<br>你不妨发个信息给jsxjd大虾,请他详细一点解答给你。
 
谢谢您:) 不过我不知道如何给jsxjd发短消息 ? CSDN上有,这儿好像没有
 
&gt;&gt;不过我不知道如何给jsxjd发短消息 <br>可以的,点上面的“在线富翁”,点开之后点在他名字旁边的那个闪电
 
多人接受答案了。
 
后退
顶部