본문 바로가기
개발/mfc

Mfc Edit Control 글자 지우며 마지막에 쓰기, 쓴 다음 마지막으로 가기

by 즐기며 2023. 12. 6.

Mfc 

 

1. EditBox 글자 지우며 마지막에 쓰기

 

멤버 변수 이용 한 거 입니다. 

editbox 최대값(별도 설정 없으면 30000)이 인데 , 글자 수가 29000 보다 크면, 앞 1000 개 지우는 거 입니다. 

 

void CDlg_Main::wCsDisp( CString cS ){
	int nLength;

//    if( ((CButton*)GetDlgItem(IDC_L_CHK_Pause))->GetCheck() )	return; // 쓰기 중지 상태면 나간다. 

	nLength = m_Disp.GetWindowTextLength();     //  Get the length of the text
	if(  (unsigned int)(nLength + 1000) > m_Disp.GetLimitText() ) {  // 남은 글자 수가 1000 개 가 안되면, 1000개 지운다.
		m_Disp.SetSel(1, 1000);		// 처음 부터 1000 개 선택
		m_Disp.Clear();
//		nLength = m_Disp.GetWindowTextLength();     //
	}

	m_Disp.SetSel(-1, -1); 		// 커서 위치를 맨 뒤로 이동
	m_Disp.ReplaceSel(cS);		// replace the selection
	m_Disp.SetFocus();		// 마지막 텍스트를 Focus
}

 

 

2. 줄 마지막으로 가기

void CDlg_Main::endDisp() {   	// 마지막 가기
	int nLines;
	static unsigned int oLines= 0;

	nLines =  m_Disp.GetLineCount();		// 현재 총 줄 수
	if( nLines > oLines ) {				// 이전 보다 크면
		m_Disp.LineScroll( nLines - oLines , 0); // 새로 생긴 줄 만큼 아래로 스크롤  
	}
	oLines = nLines;
}