改写程序---EM_GETLINE的使用(50分)

  • 主题发起人 主题发起人 mrzpz
  • 开始时间 开始时间
M

mrzpz

Unregistered / Unconfirmed
GUEST, unregistred user!
问题:我想问一下,在SendMessage中我想获得我取选中的那一行文本,那么在SendMessage中的第三个参数应该如何设置呀<br><br>回复 :先用EM_GETSEL取当前插入点,再用EM_LINEFROMCHAR取该点所在行即可 。<br><br>[8D][8D]请哪位高手将下面程序改为delphi [:D][:D]<br>--------------------------------------------------------<br>const int MAXLINELEN = 255; <br>TCHAR buf[MAXLINELEN + 1]; <br>DWORD dwSelStart; <br>::SendMessage(hWndEdit, EM_GETSEL, (WPARAM)&dwSelStart, NULL); <br>long nLine = ::SendMessage(hWndEdit, EM_LINEFROMCHAR, dwSelStart, 0); <br>*((LPWORD)buf) = MAXLINELEN; <br>int nLen = ::SendMessage(hWndEdit, EM_GETLINE, nLine, (LPARAM)buf); <br>buf[nLen] = _T('/0');
 
const<br> &nbsp;MaxLineLen = 255;<br>var<br> &nbsp;buf: array [0..MaxLineLen + 1] of Char;<br> &nbsp;dwSelStart: Cardinal;<br> &nbsp;nLine: LongWord;<br> &nbsp;nLen: Integer;<br>begin<br> &nbsp;SendMessage(hWndEdit, EM_GETSEL, Integer(@dwSelStart), 0);<br> &nbsp;nLine := SendMessage(hWndEdit, EM_LINEFROMCHAR, dwSelStart, 0);<br> &nbsp;nLen := SendMessage(hWndEdit, EM_GETLINE, nLine, Integer(@buf));<br> &nbsp;buf[nLine] := #0;<br>end;<br>未测试,大致如此。
 
zqw0117,我想问的问题其实是EM_getLine的使用,我在网上找到以下资料,其中‘Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer.’对EM_getLine使用有影响,我不知怎么设置,请帮忙!<br>-----------------------------------------------------------------------<br>EM_GETLINE的古怪又是没先好好看MSDN的注释,浪费了半天时间。。。 <br>看来磨刀不误砍柴工真是没错啊。。 <br><br>SendMessage( &nbsp;<br> &nbsp;(HWND) hWnd, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// handle to destination window &nbsp;<br> &nbsp;EM_GETLINE, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // message to send <br> &nbsp;(WPARAM) wParam, &nbsp; &nbsp; &nbsp;// line number <br> &nbsp;(LPARAM) lParam &nbsp; &nbsp; &nbsp; // line buffer (LPCTSTR) <br>); <br><br><br>Parameters <br><br>wParam <br><br>Specifies the zero-based index of the line to retrieve from a multiline edit control. A value of zero specifies the topmost line. This parameter is ignored by a single-line edit control. <br><br>lParam <br><br>Pointer to the buffer that receives a copy of the line. [red]Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer.[/red]<br> For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters. The size in the first word is overwritten by the copied line. <br>Return Values <br><br>The return value is the number of TCHARs copied. The return value is zero if the line number specified by the wParam parameter is greater than the number of lines in the edit control. <br>Remarks <br>Edit controls: [red]The copied line does not contain a terminating null character.[/red] <br>---------------------------------------------------------------------------
 
哦,明白了,我没仔细看msdn,应该如此:<br>const<br> &nbsp;MaxLineLen = 255;<br>var<br> &nbsp;buf: array [0..MaxLineLen + 1] of Char;<br> &nbsp;dwSelStart: Cardinal;<br> &nbsp;nLine: LongWord;<br> &nbsp;nLen: Integer;<br>begin<br> &nbsp;SendMessage(hWndEdit, EM_GETSEL, Integer(@dwSelStart), 0);<br> &nbsp;nLine := SendMessage(hWndEdit, EM_LINEFROMCHAR, dwSelStart, 0);<br> &nbsp;[red]buf[0] := Char(MaxLineLen);[/red]<br> &nbsp;nLen := SendMessage(hWndEdit, EM_GETLINE, nLine, Integer(@buf));<br> &nbsp;buf[nLine] := #0;<br>end;
 
Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer<br>在发送消息之前,要把这个buffer的第一个字节设置成buffer的长度。<br>The copied line does not contain a terminating null character. <br>拷贝的行不包括#0结束符
 
不对,红色的可能错了,应该改成<br>PCardinal(@buf[0])^ := Cardinal(MaxLineLen);
 
谢谢zqw00177!!!!!<br>你真是好人!!!!<br>[:)][:)][:)][:)]
 
后退
顶部