Hack Forums
[C] Update list box from thread (MFC VS2013 C++) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Update list box from thread (MFC VS2013 C++) (/showthread.php?tid=5853448)



Update list box from thread (MFC VS2013 C++) - stdio - Jun 24, 2018

Hello HF,
I would like to update my listbox from a thread, but it is not possible directly so I have to use SendMessage()
Code
void CCMFCApplication1Dlg::OnBnClickedButton1()
{
    AfxBeginThread(MyThreadProc, this);//start thread
}

UINT MyThreadProc(void *pParam)
{
        CString h=L"SomeText";
    CCMFCApplication1Dlg* pThis= (CCMFCApplication1Dlg*)pParam;
        pThis->SendMessage(LB_ADDSTRING, (WPARAM)&h);
    return 0;
}
Please guide me whats the next step, I am sure I need to peek this message from main thread but have no Idea which function to use.
Any help is appreciated.
Thanks


RE: Update list box from thread (MFC VS2013 C++) - ZwClose - Jun 24, 2018

Allocate memory on the heap[not the stack], then pass by reference to your thread using 'pParam'


RE: Update list box from thread (MFC VS2013 C++) - HFDone - Jun 24, 2018

im using win32 api not mfc but you can try http://forums.codeguru.com/showthread.php?549233-add-to-listbox-thread