mfc项目窗口中有一个edit control控件我现在建好了一个工作线程用来时时接受udp数据,怎么建立ui线程来显示这些数据呢,对ui线程的概念都不是很懂,大概是用来画ui的一个线程
在一个控件上显示一个数据用什么函数呢,就用SetWindowText可以吗??
对vc不熟悉感觉用起来很费力。

解决方案 »

  1.   

    AfxBeginThread();
     
    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 
    );
     The first form of AfxBeginThread creates a worker thread. The second form creates a user-interface thread. 
      

  2.   

    我创建UINT   show_udp_name(LPVOID   lparam) 
    {
     GetDlgItem(IDC_EDIT2)->SetWindowText(sData2);
    }这样一个函数然后再通过线程来执行,可以吗???sData2是通过另一个工作线程得到的,现在这个函数也报错error C2660: “GetDlgItem”: 函数不接受 1 个参数为什么???SetWindowText只能显示一个常量吗??
      

  3.   

    线程函数是全局的或者是静态的, GetDlgItem是窗口的成员函数,需要对象来引用,可以在创建线程的时候把类的对象指针传进去。但是最好也不要这样做,在线程中直接操作界面可能引用出错。正确的做法应该是向窗口发送消息,带上参数,然后在窗口消息响应函数中去设置edit的内容,这样是安全的。
    UI 线程有一个消息队列,线程从消息队列中取出消息传递给窗口的过程函数去执行。