Click to See Complete Forum and Search --> : Thread and SendMessage


SSP
May 21st, 1999, 01:07 AM
In the MFC app(Class Doc,View,Mainframe,App) I have my class A. Class A is a member object of the View class.

classCProcServView: public CListView
{
public:
A m_Process;
}


From the View class, I call a function in class A.

void CProcServView::OnStart()
{
m_Process.StartAllProcesses();
}


In Class A::StartAllProcesses, I create a thread.

BOOL A::StartAllProcesses()
{
CWinThread *pCreateThread;
pCreateThread = AfxBeginThread((AFX_THREADPROC) ProcessKillingThread, (LPVOID)this);
}


Being the thread, I call SendMessage to MFC app. But to do that, I do the following -

DWORD ProcessKillingThread(LPVOID lpDummy)
{
CProcServApp* pApp = (CProcServApp*)AfxGetApp();
CWnd* pWnd = (CWnd*)pApp->m_pMainWnd;
::SendMessage(pWnd->m_hWnd, WM_UPDATELIST, 0,0);
}

But, (CWnd*)pApp->m_pMainWnd shows up as NULL.

Any idea, how to go from here ?

-Thanks,

sally
May 21st, 1999, 08:34 AM
You should never, and I repeat never, use SendMessage
from within a thread. Use PostMessage, otherwise you
might lock up your application.

When your thread gets started, pass it a HWND and use that
to POST a message back to the application.

Sally

Sally
May 21st, 1999, 08:34 AM
You should never, and I repeat never, use SendMessage
from within a thread. Use PostMessage, otherwise you
might lock up your application.

When your thread gets started, pass it a HWND and use that
to POST a message back to the application.

Sally

SSP
May 21st, 1999, 08:40 AM
Thanks for your advice Sally! I figured out the hard way. Its working now.
You are right, a handle has to be passed to the thread to PostMessage.
Thanks!