怎样设置SendMessage中的参数?(16分)

  • 主题发起人 主题发起人 bingxueshanren
  • 开始时间 开始时间
B

bingxueshanren

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用SendMessage向RichEdit组件中的RTF文本发送消息,消息的内容是:将选中的一个单词更改颜色,比如红色。我写的消息格式如下:<br>SendMessage(RichEdit1.Handle,WM_SYSCOLORCHANGE,0,Red);<br>但运行时,显示错误:Red没有定义。<br>我不知道该如何来设置这个颜色参数,请各位专家帮我更改一下。
 
The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread's message queue and returns immediately. <br><br>LRESULT SendMessage(<br><br> &nbsp; &nbsp;HWND hWnd, // handle of destination window<br> &nbsp; &nbsp;UINT Msg, // message to send<br> &nbsp; &nbsp;WPARAM wParam, // first message parameter<br> &nbsp; &nbsp;LPARAM lParam // second message parameter<br> &nbsp; ); <br> <br><br>Parameters<br><br>hWnd<br><br>Identifies the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows. <br><br>Msg<br><br>Specifies the message to be sent. <br><br>wParam<br><br>Specifies additional message-specific information. <br><br>lParam<br><br>Specifies additional message-specific information. <br><br> <br><br>Return Values<br><br>The return value specifies the result of the message processing and depends on the message sent. <br><br>Remarks<br><br>Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.<br>If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, Windows switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message.
 
SendMessage(RichEdit1.Handle,WM_SYSCOLORCHANGE,0,Red);<br>把red 转换为integer 再发就可以了
 
SendMessage(ComboBox1.Handle, WM_copy, 0, 0);<br>复制,但是不同的消息,wParam与lParam值不同,具体参考DELPHI HELP中的SDK。
 
Johnny_du给出的是delphi中有关SendMessage的帮助,之前我已看过了,但就是不知道如何来设置颜色这个消息参数,kk2000的建议我也试了,可也不行啊,把red转换成integer起不到使字体变色的作用。<br>procedure TForm1.SetWordProp(i, j: Integer);<br>begin<br> &nbsp;RichEdit1.SelStart := i; &nbsp;//i是所选单词的第一个字母位置<br> &nbsp;RichEdit1.SelLength := j-i;//j是所选单词的最后一个字母位置<br> &nbsp;RichEdit1.SelAttributes.Color := clRed;<br> &nbsp;RichEdit1.SelAttributes.Style := [fsitalic];<br><br>end;<br>上面这些代码能够达到使所选单词变色的目的,难点就是获得i,j 的位置。
 
uses RichEdit;<br>procedure TTextAttributes.SetAttributes(var Format: TCharFormat);<br>var<br> &nbsp;Flag: Longint;<br>begin<br> &nbsp;if FType = atSelected then Flag := SCF_SELECTION<br> &nbsp;else Flag := 0;<br> &nbsp;if RichEdit.HandleAllocated then<br> &nbsp; &nbsp;SendMessage(RichEdit.Handle, EM_SETCHARFORMAT, Flag, LPARAM(@Format))<br>end;<br>procedure TTextAttributes.SetColor(Value: TColor);<br>var<br> &nbsp;Format: TCharFormat;<br>begin<br> &nbsp;InitFormat(Format);<br> &nbsp;with Format do<br> &nbsp;begin<br> &nbsp; &nbsp;dwMask := CFM_COLOR;<br> &nbsp; &nbsp;if Value = clWindowText then<br> &nbsp; &nbsp; &nbsp;dwEffects := CFE_AUTOCOLOR else<br> &nbsp; &nbsp; &nbsp;crTextColor := ColorToRGB(Value);<br> &nbsp;end;<br> &nbsp;SetAttributes(Format);<br>end;
 
接受答案了.
 
后退
顶部