CMyThread是CWinThread的派生类
// MyThread.h : header file
//在线程定义p_listbox,指向主窗口的ListBox控件
CWnd* m_thread_wnd;
CMyThread* m_thread;
CListBox* p_listbox;
// MyThread.cpp : implementation file
//在线程直接调用主窗口的控件
// m_thread_wnd->GetActiveWindow()->MessageBox("ll");//正确
// m_thread_wnd->GetParent()->MessageBox("ll"); //错误
// m_thread->GetMainWnd()->MessageBox("ll"); //错误
// m_thread->m_pActiveWnd->MessageBox("ll"); //错误
// m_thread->m_pMainWnd->MessageBox("ll"); //错误
// m_thread->m_pMainWnd->SetDlgItemText(IDC_STATIC,"a"); //错误
// p_listbox->GetDlgItem(IDC_LISTBOX); //错误
// p_listbox->InsertString(0,"abc"); //错误
// m_thread=AfxGetThread(); //没用
// m_thread_wnd=AfxGetMainWnd()->p_listbox->GetDlgItem(IDC_LISTBOX); //不能这样
// m_thread_wnd->MessageBox("ll"); //正确
// m_thread_wnd->SetDlgItemText(IDC_STATIC,"a"); //正确
// m_pMainWnd->SetDlgItemText(IDC_STATIC,"a");//正确,等于m_thread_wnd->SetDlgItemText(IDC_STATIC,"a");
//m_pMainWnd是默认成员
// p_listbox->InsertString(0,"a");//== p_listbox=(CListBox*)m_pMainWnd->GetDlgItem(IDC_LISTBOX);
//若是在非模态对话框直接调用主窗口的控件
GetParent()->SetDlgItemText(IDC_AMXX,__szPath);