我用AfxBeginThread(RUNTIME_CLASS(CUIThread),(LPVOID*)this)错误:none of the 2 overloads can convert parameter1 from type 'struct CRuntimeClass *'
还有线程传递信息给主进程,怎么写?postMessage吗
m_pWinThread = AfxBeginThread((AFX_THREADPROC)CEngineConverter::CoverterProcess, (LPVOID)this);或m_pWinThread = AfxBeginThread((CRuntimeClass*)CEngineConverter::CoverterProcess, (LPVOID)this); 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 );对于界面线程 pfnThreadProc Points to the controlling function for the worker thread. Cannot be NULL. This function must be declared as follows: UINT __cdecl MyControllingFunction( LPVOID pParam );pThreadClass The RUNTIME_CLASS of an object derived from CWinThread.
m_pWinThread = AfxBeginThread((AFX_THREADPROC)CEngineConverter::CoverterProcess, (LPVOID)this);或m_pWinThread = AfxBeginThread((CRuntimeClass*)CEngineConverter::CoverterProcess, (LPVOID)this); 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 );对于界面线程 pfnThreadProc Points to the controlling function for the worker thread. Cannot be NULL. This function must be declared as follows: UINT __cdecl MyControllingFunction( LPVOID pParam );pThreadClass The RUNTIME_CLASS of an object derived from CWinThread.
m_pWinThread = AfxBeginThread((AFX_THREADPROC)CEngineConverter::CoverterProcess, (LPVOID)this);或m_pWinThread = AfxBeginThread((CRuntimeClass*)CEngineConverter::CoverterProcess, (LPVOID)this);
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
);对于界面线程
pfnThreadProc
Points to the controlling function for the worker thread. Cannot be NULL. This function must be declared as follows: UINT __cdecl MyControllingFunction( LPVOID pParam );pThreadClass
The RUNTIME_CLASS of an object derived from CWinThread.
m_pWinThread = AfxBeginThread((AFX_THREADPROC)CEngineConverter::CoverterProcess, (LPVOID)this);或m_pWinThread = AfxBeginThread((CRuntimeClass*)CEngineConverter::CoverterProcess, (LPVOID)this);
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
);对于界面线程
pfnThreadProc
Points to the controlling function for the worker thread. Cannot be NULL. This function must be declared as follows: UINT __cdecl MyControllingFunction( LPVOID pParam );pThreadClass
The RUNTIME_CLASS of an object derived from CWinThread.
UI线程不是这样创建的。
创建UI线程用的是这个:CWinThread* AfxBeginThread( CRuntimeClass* pThreadClass, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );
返回值就是你的UI线程。你要获取UI线程的值就可以通过返回值来获取。
你要将一些值传进去也是通过返回值来传进去
可以用PostMessage来发送消息等通知主线程
{
char sz[260];
int n;
}MSG_INFO;
如果你想给线程传递参数,可以在CUIThread类里面定义一些public成员变量,创建线程时指定CREATE_SUSPENDED标志,创建之后给public变量赋值,然后再ResumeThread让线程开始运行。
线程可以给主窗口发送消息来回传信息,或者将对象指针传给线程,线程直接修改对象中的数据。
把this传入线程就可以了。2、还有如何从界面线程回传信息?动态的.其中有个变量。
用::SendMessage()往主线程发消息。