公司项目,要得到当前窗口的编辑光标的位置,注意,是编辑光标,就是在一个编辑框里一闪一闪的那个小竖线,不是鼠标光标哦....我用了GetCaretPos()函数,但是问题来了,对于一些窗体,我用GetFocus()函数确定了他是有当前的键盘焦点的,不过GetCaretPos()函数返回的x和y都是0,无论我怎么移动光标都没用,请问,这是怎么回事?是不是某些窗体经过特殊处理,GetCaretPos()函数无效?

解决方案 »

  1.   

    The system provides one caret per queue. A window should create a caret only when it has the keyboard focus or is active. The window should destroy the caret before losing the keyboard focus or becoming inactive. A window can set the caret position only if it owns the caret. 看应该edit的setfouse和inactive设置光标
      

  2.   

    http://search.csdn.net/Expert/topic/543/543091.xml?temp=.8899805
      

  3.   

    TO  laiyiling(最熟悉的陌生人)(知道的太少啦,好多的问题不会!) 我用的就是他的那个代码,呵呵...出问题哈...呵呵....TO  zfive5(醉马不肖):能说清楚点么?我这是用的SDK写的程序
      

  4.   

    int st, end;
    CEdit &edit = GetEditCtrl();
    edit.GetSel(st, end);
    int linechar;
    int row = 1;
    while(true)
    {
    linechar = edit.LineIndex(row);
    if(linechar > st || linechar == -1) break;
    row++;
    }
    linechar = edit.LineIndex(row-1);
    int col = st - linechar;
      

  5.   

    TO windyloft(好好吃饭):我用的是SDK来写的...呵呵...
      

  6.   

    楼主可以用以下代码轻松实现CEdit MyEdit;
    MyEdit=GetEditCtrl();
    MyEdit.GetSel(start,end); //start或end的值就是插入符的字符索引
    row=MyEdit.LineFromChar(start); //获取插入符的行坐标
    column=start-MyEdit.LineIndex(row); //获取插入符的列坐标这里面由于光标处于独立闪烁状态,所以start=end
      

  7.   

    呵呵...谢谢各位大哥了...不过,我这是SDK程序,没有MFC,只有WIN32API.....并且我用GetFocus()函数,对于某些窗口,只返回(0,0)....不知道怎么回事,郁闷...