对delphi高级编程不熟悉的人慎入(30分)

  • 主题发起人 主题发起人 我爱PASCAL
  • 开始时间 开始时间

我爱PASCAL

Unregistered / Unconfirmed
GUEST, unregistred user!
SendMessage(hEdit, EM_GETLINE, 0, 0);<br>SendMessage(hEdit, EM_GETLINECOUNT, 0, 0);<br>这两个函数怎么得到返回值。
 
hEdit是编辑框的句柄,<br>EM_GETLINE是得到hEdit一行的消息。<br>EM_GETLINECOUNT是得到hEdit行数的消息。<br><br>i:=SendMessage(hEdit, EM_GETLINECOUNT, 0, 0);<br>i返回1,请问1表示返回成功还是返回一行.
 
好象里面有个参数(好象是最后一个)是返回值
 
SendMessage(hEdit, EM_GETLINECOUNT, i, 0);<br>SendMessage(hEdit, EM_GETLINECOUNT, 0, i);<br>都试过。<br>getwindowtext也试过
 
欢迎加入DELPHI技术交流群:23889386
 
对delphi高级编程不熟悉的人慎入 ??????????
 
function TMemoStrings.GetCount: Integer;<br>begin<br> &nbsp;Result := 0;<br> &nbsp;if Memo.HandleAllocated or (Memo.WindowText &lt;&gt; nil) then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := SendMessage(Memo.Handle, EM_GETLINECOUNT, 0, 0);<br> &nbsp; &nbsp;if SendMessage(Memo.Handle, EM_LINELENGTH, SendMessage(Memo.Handle,<br> &nbsp; &nbsp; &nbsp;EM_LINEINDEX, Result - 1, 0), 0) = 0 then Dec(Result);<br> &nbsp;end;<br>end;<br><br>function TMemoStrings.Get(Index: Integer): string;<br>var<br> &nbsp;Text: array[0..4095] of Char;<br>begin<br> &nbsp;Word((@Text)^) := SizeOf(Text);<br> &nbsp;SetString(Result, Text, SendMessage(Memo.Handle, EM_GETLINE, Index,<br> &nbsp; &nbsp;Longint(@Text)));<br>end;<br>第一个作用是返回行数,最后一行能为空。<br>第二个是得到 所在行的长度,输出字符到Text中。
 
对delphi高级编程不熟悉的人慎入 ??????????
 
老兄,如果你对消息不熟悉,就不要用这么惹眼的标题。<br>--------------------------<br>随便推销一下:<br>Delphi编程天地:18600851
 
procedure TForm1.btn1Click(Sender: TObject);<br>var<br> &nbsp;I: Integer;<br> &nbsp;Count: Integer;<br> &nbsp;Len: Integer;<br> &nbsp;Text: PChar;<br>begin<br> &nbsp;Count := SendMessage(mmo1.Handle, EM_GETLINECOUNT, 0, 0);<br> &nbsp;for I := 0 to Count - 1 do<br> &nbsp;begin<br> &nbsp; &nbsp;Len := SendMessage(mmo1.Handle, EM_LINELENGTH, SendMessage(mmo1.Handle, EM_LINEINDEX, I, 0), 0) + 1;<br> &nbsp; &nbsp;GetMem(Text, Len);<br> &nbsp; &nbsp;SendMessage(mmo1.Handle, EM_GETLINE, I, Integer(Text));<br> &nbsp; &nbsp;Text[Len - 1] := #0;<br> &nbsp; &nbsp;ShowMessage(string(Text));<br> &nbsp; &nbsp;FreeMem(Text, Len);<br> &nbsp;end;<br>end;
 
hoho,这就叫做高级编程?
 
sendmessage 返回值依赖发送的具体信息,<br>EM_GETLINECOUNT 返回值代表 行数<br>EM_GETLINE &nbsp;返回值代表 结果字节串的字节数<br>//这种问题不会就去google就可以了<br> <br><br> 
 
试了jeffrey_s的函数,TMemoStrings.GetCount能够返回值,<br>TMemoStrings.Get(Index: Integer)返回为空.<br>寻路的函数返回的是乱码.
 
不太可能是乱码,我在我的机器上面做过测试了,请问你是对什么组件取字符串?
 
qq的聊天窗口,richedit.
 
就是qq聊天的录入窗口.<br>如果要得到录入窗口上面哪个显示聊天对话记录的窗口的内容我觉得更困难.
 
简单的写了一下,应该是可以的,你先试试看:<br><br>procedure GetControlText(hWnd: THandle);<br>var<br> &nbsp;ArrText: array [0..1024] of Char;<br>begin<br> &nbsp;SendMessage(hWnd, WM_GETTEXT, 1024, LongInt(@ArrText));<br><br> &nbsp;ShowMessage(StrPas(ArrText));<br>end;<br><br>function EnumerateChildWindows(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;<br>var<br> &nbsp;ClassName: &nbsp; &nbsp; array [0..255] of Char;<br>begin<br> &nbsp;FillChar(ClassName, 256, 0);<br> &nbsp;GetClassName(hWnd, ClassName, 255);<br> &nbsp;if (StrPas(ClassName) = 'RichEdit20A') then<br> &nbsp;begin<br> &nbsp; &nbsp;GetControlText(hWnd);<br> &nbsp; &nbsp;Result := False;<br> &nbsp;end;<br><br> &nbsp;Result := True;<br>end;<br><br><br><br>procedure TForm1.btn1Click(Sender: TObject);<br>var<br> &nbsp;Hwnd: THandle;<br>begin<br> &nbsp;Hwnd := FindWindow(nil, '与 ★f.f╃ 交谈中');<br> &nbsp;if Hwnd &lt;&gt; 0 then EnumChildWindows(Hwnd, @EnumerateChildWindows, 0);<br>end;
 
试了寻路的方法,完全成功,谢谢你,你帮我解决了一个大问题。<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=3423984<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=3419735<br>我这两个贴子没人回答,请你来拿分,请笑纳。
 
呵呵,我可是个穷富翁,有分就不客气了!<br>我觉得还有一个问题,不知道你是怎么处理的:你怎么寻找现有的所有聊天窗口呢?
 

Similar threads

后退
顶部