用
threads=AfxBeginThread(RUNTIME_CLASS(CMyThread));
在主线程中开启一个新的UI线程。在CMyThread中创建并且显示一个无模式对话框,
但是如何在主线程中或则其他的工作线程中来通知这个无模式对话框来“干活”呢?
我想用消息,但是不明白怎么发过去。没有这个无模式对话框的handle阿。
threads=AfxBeginThread(RUNTIME_CLASS(CMyThread));
在主线程中开启一个新的UI线程。在CMyThread中创建并且显示一个无模式对话框,
但是如何在主线程中或则其他的工作线程中来通知这个无模式对话框来“干活”呢?
我想用消息,但是不明白怎么发过去。没有这个无模式对话框的handle阿。
解决方案 »
- 求助:已有c语言写的源程序,怎么用MFC编写界面?
- 求助!!!棘手的问题,做的一个画板程序在win2000及以上的OS上没有问题,win98,win me全都有问题。
- 画图时如何实现所谓的异步?(我听别人说的,不明白)功能就是把上次的图形替换,不是刷新Invalidate
- 分割符
- ftp client一问。在线给分。第一个回答出来的60分以上
- How to在对话框里加滚动条?
- 一个数据组建线程、一个数据发送线程,怎么合理设计线程同步?
- 推荐一些学习win32sdk的书。
- 关于用nmake来makefile的问题
- createDIBsection()是什么函数??
- 单文档视图的菜单如何隐藏?如何隐藏后再通过快捷键显示出来? (2)
- 有关鼠标事件的问题!
DWORD idThread, // thread identifier
UINT Msg, // message to post
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
CWinThread* AfxBeginThread( CRuntimeClass* pThreadClass, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );可以::PostThreadMessage(pWinThread->m_nThreadId,msg,wParam,lParam)
应该用哪一个呢?
我在msdn里面找到了。
CWinThread::PostThreadMessage
BOOL PostThreadMessage( UINT message , WPARAM wParam, LPARAM lParam );Return ValueNonzero if successful; otherwise 0.ParametersmessageID of the user-defined message.wParamFirst message parameter.lParamSecond message parameter.ResCalled to post a user-defined message to another CWinThread object. The posted message is mapped to the proper message handler by the message map macro ON_THREAD_MESSAGE.谢谢大家。
不过还有一个问题请教---我呆会儿会加分的---就是:
如何在主线程里面向这个UI线程传递参数?
CWinThread* AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );CWinThread* AfxBeginThread( CRuntimeClass* pThreadClass, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );创建工作线程的时候是可以的。
但是不知道UI线程可不可以。
或者如何在UI线程里面获取主线程中的数据?
m_pSockListenThread=(CSockListenThread *)AfxBeginThread(RUNTIME_CLASS(CSockListenThread));//发消息,Para1携带参数
m_pSockListenThread->PostThreadMessage(WM_STARTLISTEN,Para1,NULL);
//UI县城的定义
class CSockListenThread : public CWinThread
{
DECLARE_DYNCREATE(CSockListenThread)
protected:
CSockListenThread(); // protected constructor used by dynamic creation
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSockListenThread)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL// Implementation
protected:
virtual ~CSockListenThread(); // Generated message map functions
//{{AFX_MSG(CSockListenThread)
// NOTE - the ClassWizard will add and remove member functions here.
afx_msg void OnEndSockThread(WPARAM wParam,LPARAM lParam);
//用来接收消息WM_STARTLISTEN
afx_msg BOOL OnStartListen(WPARAM wParam,LPARAM lParam
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};//消息的映射:
BEGIN_MESSAGE_MAP(CSockListenThread, CWinThread)
//{{AFX_MSG_MAP(CSockListenThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_THREAD_MESSAGE(WM_ENDSOCKTHREAD,OnEndSockThread)
//OnStartListen是消息WM_STARTLISTEN的处理函数
ON_THREAD_MESSAGE(WM_STARTLISTEN,OnStartListen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//消息处理函数
BOOL CSockListenThread::OnStartListen(WPARAM wParam,LPARAM lParam)
{
//wParam即为携带的参数
return TRUE;
}