我建了一个基于对话框的MFC EXE(VC6.0),有一个按钮,一个复选框。
想要实现:我点击按钮,启动一个线程,在线程函数内选中复选框(即复选框前出现对勾)。
代码如下:
头文件:
class CMyDlg : public CDialog
{
public:
CMyDlg(CWnd* pParent = NULL); // standard constructor
static UINT ThreadProc(LPVOID pParam);//我定义的线程函数
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
protected:
HICON m_hIcon; // Generated message map functions
//{{AFX_MSG(CMyDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnButton1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};按下按钮启动线程:
void CMyDlg::OnButton1() 
{
AfxBeginThread(ThreadProc,NULL,THREAD_PRIORITY_ABOVE_NORMAL,0,0);
}线程函数:
UINT CMyDlg::ThreadProc(LPVOID pParam)
{
CButton* pButton=(CButton*)GetDlgItem(IDC_CHECK1);
pButton->SetCheck(1);//将复选框设置为选中状态
return 0;
}编译出错:error C2352: 'CWnd::GetDlgItem' : illegal call of non-static member function。到底是什么问题?该如何修改代码呢?