@coder777
I wanted to update my list box from a thread, Thomas above suggested that I use SendMessage() for that purpose.
I am not entirely sure what you mean by you don't know what SendMessage() is doing?
If you be so kind as to elaborate a little, is there any other way around it.
My question is fairly simple "Update a list box from a thread".
Thanks a lot
@kbw: I cannot access control variable from a thread, that is the whole issue here.
I cannot access control variable from a thread, that is the whole issue here.
That's not entirely correct.
The worker thread is passed a pointer to the instance of the dialog box to be updated. You can add a method to that dialog box, then call it form the worker thread. For example:
UINT MyThreadProc(void *pParam)
{
if (CCMFCApplication1Dlg* pMainDlg = (CMFCApplication1Dlg*)pParam) {
// do some work
// ...
pMainDlg->AddStringToListbox("hello world");
}
return 0;
}
I initially suggested PostThreadMessage because you'll eventually run into problems by using SendMessage directly. The GDI doesn't (or didn't used to handle threads) and the paint messages etc run in the wrong thread.
Wow thanks, I read msdn article https://msdn.microsoft.com/en-us/library/69644x60.aspx on worker threads and then read your very accurate description.
I have better understanding now, will implement the example you gave and return with feedback.
Thanks again.
This worked ::SendMessage(m_list.m_hWnd, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)str);
I was able to add text item into list box.
Will try with thread now and update here, thanks.