blog

枪手亨利

博客园 首页 新随笔 联系 订阅 管理

在richtextbox中,如何得到鼠标所在的段、行、句、词的内容?
http://search.csdn.net/Expert/topic/1132/1132440.xml?temp=.7275049

发送EM_CHARFROMPOS消息得到鼠标所指位置
发送EM_EXLINEFROMCHAR(因为是RichTextBox)取得行号
发送EM_LINELENGTH消息得到行长度,分配字符串缓冲区的大小
发送EM_GETLINE消息得到该行的文本


EM_CHARFROMPOS
The EM_CHARFROMPOS message retrieves the character index and line index of the character nearest a specified point in the client area of an edit control. The application can send this message to either an edit control or a rich edit control.

Rich edit controls use the following syntax:

EM_CHARFROMPOS
wParam = 0;                        // not used
lParam = (LPARAM) (POINTL *) lpPoint;
     // pointer to a POINTL structure with the point coordinates
 
Edit controls use the following syntax:

EM_CHARFROMPOS
wParam = 0;                        // not used
lParam = MAKELPARAM(xPos, yPos);   // coordinates of a point
 
Parameters
lParam
Specifies the coordinates of a point in the control's client area. The coordinates are in screen units and are relative to the upper-left corner of the control's client area.
Rich edit controls: lParam is a pointer to aPOINTL structure that contains the horizontal and vertical coordinates.

Edit controls: The low word of lParam contains the horizontal coordinate. The high word contains the vertical coordinate.

Return Values
The low word of the return value specifies the zero-based index of the character nearest the specified point. This index is relative to the beginning of the control, not the beginning of the line. If the specified point is beyond the last character in the edit control, the return value indicates the last character in the control.

The high word of the return value specifies the zero-based index of the line that contains the character. For single-line edit controls, this value is zero. The index indicates the line delimiter if the specified point is beyond the last visible character in a line.

QuickInfo
  Windows NT: Requires version 4.0 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.

 


EM_EXLINEFROMCHAR
The EM_EXLINEFROMCHAR message determines which line contains the specified character in a rich edit control.

EM_EXLINEFROMCHAR
wParam = 0;
lParam = (LPARAM) (DWORD) ichCharPos;
 
Parameters
ichCharPos
Zero-based index of the character.
Return Values
Returns the zero-based index of the line.

QuickInfo
  Windows NT: Requires version 3.51 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in richedit.h.

 

EM_LINELENGTH
An application sends an EM_LINELENGTH message to retrieve the length of a line, in characters, in an edit control.

EM_LINELENGTH
wParam = (WPARAM) ich;  // character index
lParam = 0;             // not used; must be zero
 
Parameters
ich
Value of wParam. Specifies the character index of a character in the line whose length is to be retrieved when EM_LINELENGTH is sent to a multiline edit control. If this parameter is –1, the message returns the number of unselected characters on lines containing selected characters. For example, if the selection extended from the fourth character of one line through the eighth character from the end of the next line, the return value would be 10 (three characters on the first line and seven on the next).
Return Values
The return value is the length, in characters, of the line specified by the ich parameter when an EM_LINELENGTH message is sent to a multiline edit control. The return value is the length, in characters, of the text in the edit control when an EM_LINELENGTH message is sent to a single-line edit control.

Remarks
Use the EM_LINEINDEX message to retrieve a character index for a given line number within a multiline edit control.

QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.


EM_GETLINE
An application sends an EM_GETLINE message to copy a line of text from an edit control and place it in a specified buffer.

EM_GETLINE
wParam = (WPARAM) line;          // line number to retrieve
lParam = (LPARAM) (LPCSTR) lpch; // address of buffer for line
 
Parameters
line
Value of wParam. 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.
lpch
Value of lParam. Pointer to the buffer that receives a copy of the line. The first word of the buffer specifies the maximum number of characters that can be copied to the buffer.
Return Values
The return value is the number of characters copied. The return value is zero if the line number specified by the line parameter is greater than the number of lines in the edit control.

Remarks
The copied line does not contain a terminating null character.

QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.



CharPos=SendMessgae(Text1.hWnd, EM_GETSEL, 0, 0&)
CharPos=CharPos\&h10000
行号=SendMessgae(Text1.hWnd, EM_LINEFROMCHAR, CharPos, ByVal 0&)+1
列号=CharPos-SendMessgae(Text1.hWnd, EM_LINEINDEX, CharPos, 0&)+1

posted on 2005-12-29 14:31  henry  阅读(1769)  评论(0)    收藏  举报