SDK的环境在winmain里声明了一个DialogBox(NULL,"box",NULL,(DLGPROC)DlgProc);
弹出一个对话框,对话矿里有一个button和一个static,定义为IDC—OK,IDC—OUT,
在case IDC_OK:下起create一个thread,在这个thread里调用一个函数down();而我想根据down()里面的某些条件语句在static里显示不同的内容,当然,每次初始化时都晴空了static,只是不知道怎么把这两者联合在一起啊,就是在down()里怎么声明dialog的句并,帮忙啊!!!100分,100分

解决方案 »

  1.   

    线程定义一般模式如下:.h文件
    =====================
    class CRawThread
    {
    private:
    ...
    public:
    ...
    friend unsigned __stdcall _raw_thread_function(void *param);
    //将线程函数定义为这个类的友元函数,避免线程内部访问类的私有元素的时候出现错误。
    };.cpp文件
    ====================
    #include <process.h>   //记得这一行...unsigned __stdcall _raw_thread_function(void *param)
    {
    CRawThread *pThis = (CRawThread *)param;  //这里将参数转换为原来的类型
            ...
    //------------------------------------------------------------------------
    while(1)
    {
    if(WaitForSingleObject(pThis->m_hExitThread, 0) == WAIT_OBJECT_0)
    {
    ResetEvent(pThis->m_hExitThread);
    goto EXIT_THREAD_0;
    }
                    ...
    Sleep(30);
    }
    //------------------------------------------------------------------------
    EXIT_THREAD_0:
            ...
    SetEvent(pThis->m_hExitThreadOk);
    _endthreadex(0); return 0;
    }BOOL CRawThread::StartThread()
    {
    if(m_hThread == NULL){
    //如果线程没有启动,启动线程
    m_hThread = (HANDLE)_beginthreadex(
    NULL,
    0,
    _raw_thread_function, 
    this,  //这里传递参数 
    0,
    &m_uThreadId);
    return (m_hThread != NULL);
    }
    return TRUE;
    }你在定义线程的时候可以带参数,最简单就是把句柄作为参数就可以了,你看看上面定义线程时候是怎么传递参数的,希望你看懂了。
      

  2.   

    two methods. the first : your define a custom message, when you want to update static control caption, send this message to the dialog, of course your dialog need to handle the message
    second:
    pass HWND of the static control to the thread, use SetWindowText to change it directly.
      

  3.   

    把变量放在APP里,这样,所有的文档都能访问。
      

  4.   

    最最最最简单的办法:BOOL  CMyDialog::OnOK()
    {
    _beginthread(MyThread,0,this); // 将DIALOG对象传入线程函数
    }void MyThread(void *p)
    {
    CMyDialog *pDlg = (CMyDialog *)p;
    down(pDlg->hWnd); // pDlg->hWnd 就是你想要的DIALOG句柄了
    }
      

  5.   

    呵呵,谢谢啊,终于解决了,是hdlg的重复问题,重新定义了一个参数就ok了
    谢谢oldworm和masterz的详细解释啊,对了masterz,前个问题还没有解决,还有什么可能吗??也谢谢与人码头哦