在对话框中有20个EDIT BOX控件,初始值为0,要求实现以下功能:单击任意EDIT BOX,使其中的文本呈选中态,(高亮,变蓝),可以被以后的输入覆盖,在任意EDIT BOX中,反复单击,输入,也能实现此功能

解决方案 »

  1.   

    重载editbox控件!重载onActive函数
    在里面调用setsel
      

  2.   

    yeah
    -----------------------------
    CEdit::SetSel 
    void SetSel( DWORD dwSelection, BOOL bNoScroll = FALSE );void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );ParametersdwSelectionSpecifies the starting position in the low-order word and the ending position in the high-order word. If the low-order word is 0 and the high-order word is –1, all the text in the edit control is selected. If the low-order word is –1, any current selection is removed.bNoScrollIndicates whether the caret should be scrolled into view. If FALSE, the caret is scrolled into view. If TRUE, the caret is not scrolled into view.nStartCharSpecifies the starting position. If nStartChar is 0 and nEndChar is –1, all the text in the edit control is selected. If nStartChar is –1, any current selection is removed.nEndCharSpecifies the ending position.ResCall this function to select a range of characters in an edit control.
      

  3.   

    我在OnSetfocusEdit1()中,使用过SetSel(0,-1,TRUE);不行
      

  4.   

    你生成一个CEdit的字类
    CNewEdit
    然后重载OnSetFocus函数
    在这个函数里使用SetSel(0,-1,TRUE);
      

  5.   

    新建一MFC类
    如:CNewEdit
    基类为CEdit
    然后在你需要用到编辑框的对话框里调用头文件
    打开ClassWizard替每个Edit加一个control变量,类型为CNewEdit
    再打开CNewEdit的ClassWizard
    为其加上一个OnSetFocus()函数
    在这个函数里
    SetSel(0,-1,TRUE);
    一切OK
      

  6.   

    同意,shilong(星矢)的,重载OnSetFocus()
    void CEditDlg::OnEnSetfocusEdit()
    {
        m_editSel.SetSel(0,-1,TRUE);
    }不过,这只有当编辑框获得焦点时才会变,如果焦点已在它在面的话,要实现任意时侯单击之后选中,可以通过重载CEdit类,然后重载
    void CMyEdit::OnLButtonUp(UINT nFlags, CPoint point)
    {
    SendMessage(WM_LBUTTONDBLCLK,0,0);
    CEdit::OnLButtonUp(nFlags, point);
    }
    就行了。
      

  7.   

    如果只是单击之后获得焦点时选中,那就不用派生CEdit类,只需要在对话框类中处理Edit的EN_SETFOCUS消息就行了。如上开始,不过这样做的话,的编辑框都要重载此方法,所以还是派生的来的方便