|
-
May 21st, 1999, 01:07 AM
#1
Thread and SendMessage
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,
-
May 21st, 1999, 08:34 AM
#2
Re: Thread and SendMessage
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
-
May 21st, 1999, 08:40 AM
#3
Re: Thread and SendMessage
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|