在Edit控件中,可发EM_LINEFROMCHAR 来获取光标所在行。
现在的问题是,我得到这一行Text后,将text中的单词一个一个的分离出来,现在我想知道光标的位置,即光标正处于哪个单词中。
一般的好的IDE环境中查找工具刚打开时,默认待查找的单词就是光标处所在的单词请问这个功能怎么实现?请注意,不能用MFC,要用API或消息谢谢

解决方案 »

  1.   

    先用WIN32函数GetCaretPos得到当前光标的坐标(像素坐标),然后可以向EDIT控件发送EM
    _CHARFROMPOS消息,以获知该坐标在文本中第几个字符,第几行。
      

  2.   

    用EM_LINEINDEX消息获取当前行的首字符的序号,返回的字符序号是EDIT控件中所有字符总的序号。好像没有直接返回列号
    的办法,不过既然有了总序号,可以顺序扫描EDIT框中的文本,只要数数
    换行回车的个数就可以算出列号了。
    用已经
    获得的当前字符的总序号减它再加1,这样就得到了当前列值。
      

  3.   

    EM_CHARFROMPOSReturn 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 在RichEdit中,可能文本大小超过64k,若光标在超过64k的地方,那么返回值如何用一个WORD来装载呢?