Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 22-Oct-10 14:17pm
v2

1 solution

Use PostMessage to send a user defined message to the main thread/dialog, and in the handler for that, update the UI.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900