c++ Make the edit box scroll all the time through the thread

1. Create a new dialog box project, put an edit box, multiple lines, display the vertical scroll bar, add a button

2 Note that the function executed by the thread must be a global function, and the parameter is a pointer representing the window 

UINT ScrollTest(LPVOID pParam)
{
	CEditScrollDlg* dlg = (CEditScrollDlg*)pParam;
	
	CString str, strtemp;
	for (size_t i = 0; i < 100; i++)
	{
		strtemp.Format("%d\r\n", i);
		str += strtemp;
		dlg->m_edit.SetWindowTextA(str);
		dlg->m_edit.LineScroll(dlg->m_edit.GetLineCount());
		Sleep(200);
	}
	return 0;
}


void CEditScrollDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	AfxBeginThread((AFX_THREADPROC)ScrollTest, this);
}

 

Guess you like

Origin blog.csdn.net/dxm809/article/details/114240021