我想写一个记事本,但是不知道如何获得光标所在的位置,包括行和列,请各位大侠指点,谢谢。

解决方案 »

  1.   

    int cx=GetSystemMetrics(SM_CXCURSOR);
      int cy=GetSystemMetrics(SM_CXCURSOR);
      

  2.   

    上面那个是鼠标的大小
    这是那个闪锁的光标,,
    CPoint  GetCaretPos();
      

  3.   

    我说的是获得光标所在的行数和列数,就像word一样的。
    上面两个的我都没看,因为返回CPoint,我觉得好像有点不对。
      

  4.   

    int a, b;
    SendMessage(edit, EM_GETSEL, a, b);
    int pos = SendMessage(edit, EM_POSFROMCHAR, b, 0);
    int hang = pos >> 16;
    int lie = pos & 0xffff;
      

  5.   

    这是我以前用vb写的,只对英文的正确。
    Private Sub Timer1_Timer()
        On Error GoTo errhandle
        notepad = FindWindow("NotePad", vbNullString)
        notepadedit = FindWindowEx(notepad, 0, "Edit", vbNullString)
        Dim max As Long
        SetWindowPos Form1.hwnd, -1, 0, 0, 0, 0, 3
        Dim wParam As Long
        Dim lParam As Long
        SendMessage notepadedit, EM_GETSEL, wParam, lParam
        Dim pos As Long
        Dim X As Long
        Dim Y As Long
        pos = SendMessage(notepadedit, EM_POSFROMCHAR, lParam, 0)
        If pos < 0 Then
            pos = SendMessage(notepadedit, EM_POSFROMCHAR, vbGetWindowTextlength(notepadedit) - 1, 0)
        End If
        Dim r As RECT
        Y = pos \ 65536
        X = pos Mod 65536
        GetWindowRect notepadedit, r
        Me.Left = r.Left * 15 + X * 15 + 300
        Me.Top = r.Top * 15 + Y * 15 + 300
        Exit Sub
    errhandle:
        Err.Clear
    End Sub