mfc:editcontrol 输出附加到末尾,换行

在这里插入图片描述
控件设置打开:
Auto SHcroll false,Mutiline true

void CTG_HelperDlg::OnBnClickedButtonSubmit()
{
    
    
	CString str;
GetDlgItem(IDC_EDIT_HTTP_INPUT)->GetWindowText(str);
str =  _T("\r\n") + str;

//GetDlgItem(IDC_EDIT_HTTP_OUTPUT)->SetWindowText(str);

CEdit* http_output_editbox = (CEdit*)GetDlgItem(IDC_EDIT_HTTP_OUTPUT);

//在末尾添加内容
int nCount    = 0;
int nLastLineStart = 0;
int nLastLineEnd = 0;
nCount         =  http_output_editbox->GetLineCount();              //获取行数,包括回车行
//http_output_editbox->
//MessageBox(nCount);
nLastLineStart    =  http_output_editbox->LineIndex( nCount - 1 );   //获取字符数,许可多行
nLastLineEnd    = nLastLineStart + http_output_editbox->LineLength(nLastLineStart);
http_output_editbox->SetSel( nLastLineEnd + 1, nLastLineEnd + 2 );      //设定光标选中的区域
http_output_editbox->ReplaceSel( str);                 //文字替换


TRACE(L"\nsend [%s] to engine",str);
MessageBox(str);
}

参考:
mfc中在editbox末尾加入内容
MFC在编辑框(EDIT)尾部追加内容

おすすめ

転載: blog.csdn.net/hunter___/article/details/113508339