如何从线程更新对话框和/或CEdit框? [英] how to update a dialog and/or CEdit box from a thread?

查看:134
本文介绍了如何从线程更新对话框和/或CEdit框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我创建了一个MFC对话框应用程序.我创建了一个始终运行的线程,并且希望它更新CEdit框.我传递了一个指向对话框类线程的指针:

thread_handle = CreateThread(NULL,1024,MainThread,this,0,&threadID);

这是线程代码:

Hi, I created a MFC dialog application. I made a thread that is always running and I want it to update a CEdit box. I passed a pointer to the thread that is the dialog class:

thread_handle = CreateThread(NULL,1024,MainThread,this,0,&threadID);

here is the thread code:

DWORD WINAPI MainThread(PVOID arg)
{
	CMPIO_A2D_Carrier_UtilityDlg *obj = (CMPIO_A2D_Carrier_UtilityDlg *)arg;
	
	while(1)
	{
		obj->m_Messages.SetWindowText(_T("Hello...\r\nthis \r\n is a test\r\n"));
obj->UpdateData(FALSE);
		Sleep(1000);
	}

	return(0);
}




当我这样做时,我得到一个断言.那么,从线程更新对话框的正确方法是什么?




When I do this, I get an assertion. So, what is the proper way to update dialogs from a thread?

推荐答案

使用PostMessage 将用户定义的消息发送到主线程/对话框,然后在处理程序,请更新用户界面.
Use PostMessage to send a user defined message to the main thread/dialog, and in the handler for that, update the UI.


这篇关于如何从线程更新对话框和/或CEdit框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆