怎么确定从WinThread继承的类已经启动完毕,可以给他发消息了(160分求解,还有一个帖子在基础版了)
elabs 2003-11-06 09:22:51 另一个帖子在这了
http://expert.csdn.net/Expert/topic/2433/2433839.xml?temp=.2540552
我有一个CRequestManager 类定义如下
class CRequestManager : public CWinThread
{
DECLARE_DYNCREATE(CRequestManager)
CRequestManager();
protected:
virtual ~CRequestManager();
// Generated message map functions
//{{AFX_MSG(CRequestManager)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
void onResponse(WPARAM wParam, LPARAM lParam);
};
在类里边有相应的自定义的消息响应宏和函数。
BEGIN_MESSAGE_MAP(CRequestManager, CWinThread)
//{{AFX_MSG_MAP(CRequestManager)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_THREAD_MESSAGE( DEV_RESPONSE_COMPLETE, onResponse )
END_MESSAGE_MAP()
void CRequestManager::onResponse(WPARAM wParam, LPARAM lParam)
{
}
在主程序中要启动这个线程类,然后给他发消息,却发现有时候会消息发送失败
CRequestManager* m_pCRequestManager;
CRuntimeClass* pCRequestManager = RUNTIME_CLASS( CRequestManager ) ;
if( ::lstrcmp( pCRequestManager->m_lpszClassName , "CRequestManager" ) )
{
return WFS_ERR_INTERNAL_ERROR;
}
m_pCRequestManager =
(CRequestManager*)::AfxBeginThread(pCRequestManager ) ;
//这里发送消息有时候会失败,如果加上延时则没有问题,那现在我想知道到底什么时候才可以往这个线程中发消息。
m_pCRequestManager->PostThreadMessage(DEV_RESPONSE_COMPLETE, (UINT)1234, 0)