比如在一个对话框中有个edit控件,一般情况是在edit中输入时,cursor(当然这时cursor没在edit之内)会消失。怎么样不让cursor消失

解决方案 »

  1.   

    貌似得重载一个EDIT控件,再OnSetcursor或者 OnChar里做一些处理,Edit自己对鼠标干了坏事
      

  2.   

    重载CEdit类,并在失去焦点时,绘制光标:
    void CEditEx::OnKillFocus(CWnd *pNewWnd)
    {
    int nStart,nEnd;
    this->GetSel(nStart,nEnd);
    CPoint pt=this->PosFromChar(nStart);
    CEdit::OnKillFocus(pNewWnd);


    ::CreateCaret(this->GetSafeHwnd(),NULL,1,12);
    ::SetCaretPos(pt.x,pt.y);
    ::ShowCaret(this->GetSafeHwnd());

    }
      

  3.   

    重载CEdit类,添加OnSetCursor与OnChar的消息处理,加载默认箭头图标:
    BOOL CEditEx::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
    {
    HCURSOR hCursor=LoadCursor(NULL,IDC_ARROW);

    SetCursor(hCursor);
    return TRUE;
    }
    void CEditEx::OnChar(UINT a, UINT b, UINT c)
    {
    HCURSOR hCursor=LoadCursor(NULL,IDC_ARROW);
    CEdit::OnChar(a,b,c);
    SetCursor(hCursor);
    }