还有如何从界面线程回传信息?动态的.其中有个变量。

解决方案 »

  1.   

    传入界面的this指针,再界面代码中添加函数,再线程中就可以调用函数了,想干嘛就干嘛。
      

  2.   

    我用AfxBeginThread(RUNTIME_CLASS(CUIThread),(LPVOID*)this)错误:none of the 2 overloads can convert parameter1 from type 'struct CRuntimeClass *'
      

  3.   

    还有线程传递信息给主进程,怎么写?postMessage吗
      

  4.   


    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.
      

  5.   


    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.
      

  6.   


    UI线程不是这样创建的。
    创建UI线程用的是这个:CWinThread* AfxBeginThread( CRuntimeClass* pThreadClass, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );
    返回值就是你的UI线程。你要获取UI线程的值就可以通过返回值来获取。
    你要将一些值传进去也是通过返回值来传进去
      

  7.   

    CRuntimeClass 线程函数进行类型转换..
    可以用PostMessage来发送消息等通知主线程
      

  8.   

    变量有一个 字符串和 一个 int
      

  9.   

    用一个结构体类型转换作为消息的参数WPARAM,接收到消息后强制类型转换回来typedef struct
    {
      char sz[260];
      int n;
    }MSG_INFO;
      

  10.   

    用一个数据结构作为消息的参数进行强制转换后发送给主线程,数据结构你可以自己DIY,放字符或是int都行
      

  11.   

    为什么要传进程句柄?程序中创建的所有线程都属于同一进程,可以用GetCurrentProcess来获取进程句柄,或者直接用(HANDLE)-1。
    如果你想给线程传递参数,可以在CUIThread类里面定义一些public成员变量,创建线程时指定CREATE_SUSPENDED标志,创建之后给public变量赋值,然后再ResumeThread让线程开始运行。
    线程可以给主窗口发送消息来回传信息,或者将对象指针传给线程,线程直接修改对象中的数据。
      

  12.   

    1、创建界面线程的问题,如何把进程的句柄传入线程?
    把this传入线程就可以了。2、还有如何从界面线程回传信息?动态的.其中有个变量。
    用::SendMessage()往主线程发消息。
      

  13.   

    可以用PostMessage来发送消息等通知主线程