SW 개발

[MFC] EditBox 에디트박스 기초사항

. . . 2010. 8. 12. 09:21
반응형
  • 기타사항 : winCE5 / EVC 테스트완료, 필요할때 마다 업데이트예정.

마지막 커서에 계속 업데이트하기..

CEdit *pEdit=(CEdit *)GetDlgItem(IDC_EDIT1);
int len = pEdit->GetWindowTextLength();
pEdit->SetSel(len, len);
pEdit->ReplaceSel(m_strEditBox);

커서 끝으로 이동하기

pEdit->SetSel(-1);

CEdit 전체 내용 삭제

CEdit 는 CListBox와 달리 전체 내용을 삭제하는 함수가 없다.대신 현재 선택된 값을 삭제하는 Clear()함수가 존재한다. 여기서 생각할 수 있는 것이 전체 선택 후 Clear()함수를 호출하는 것이다. clear()가 먹지않을때 또다른 방법은 전체선택후 ReplaceSel(m_strEditBox)에 빈 문자를 주는것이다.

전체 선택은 SetSel함수를 이용한다.

SetSel함수 설명

void SetSel( DWORD dwSelection, BOOL bNoScroll = FALSE );
void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );
  • dwSelection
    • Specifies 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.
  • bNoScroll
    • Indicates 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.
  • nStartChar
    • Specifies 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.
  • nEndChar
    • Specifies the ending position.

nStartChar을 0으로 하고 nEndChar을 -1로 하면 모든 문자가 선택된다.모든 문자를 선택한 후 Clear함수를 호출하여 삭제하면 된다.

CEdit m_editInput;    
m_editInput.SetSel(0, -1, TRUE);    
m_editInput.Clear();
반응형