GetDlgItem(IDC_EDIT1)->SetWindowText("1");解决办法
GetDlgItem(IDC_EDIT1)->SetWindowText("1");
我想在线程中调用这样的函数,貌似不行,但是用AfxMessageBox就行。
------解决方案--------------------
1.worker线程 不要做 界面的 事情,发消息给 主窗口
2.给worker线程 传的参数,最好不是MFC 类,传HWND
------解决方案--------------------
------解决方案--------------------
CWnd* pWnd = obj->GetDlgItem(IDC_EDIT1);
if(pWnd != NULL && pWnd->IsWindow())
pWnd->SetWindowText("你好啊"):
你的原因:控件被删除了,但你还在访问。
------解决方案--------------------
MFC不支持多线程操作UI。
只能在新线程里向某个窗体发送命令消息,然后在窗体里处理消息。消息的参数倒是可以全局。
CTestDlg obj;
UINT ThreadProc(LPVOID pParam)
{
//AfxMessageBox("1");
obj.GetDlgItem(IDC_EDIT1)->SetWindowText("1");
return 1;
}
void CTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
AfxBeginThread(ThreadProc,NULL);
GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
}
我想在线程中调用这样的函数,貌似不行,但是用AfxMessageBox就行。
------解决方案--------------------
1.worker线程 不要做 界面的 事情,发消息给 主窗口
2.给worker线程 传的参数,最好不是MFC 类,传HWND
------解决方案--------------------
AfxBeginThread(ThreadProc, this); //传递CTestDlg对象指针作为参数
UINT ThreadProc(LPVOID pParam)
{
CTestDlg *obj - (CTestDlg *)pParam;
//AfxMessageBox("1");
obj->GetDlgItem(IDC_EDIT1)->SetWindowText("1");
return 1;
}
------解决方案--------------------
CWnd* pWnd = obj->GetDlgItem(IDC_EDIT1);
if(pWnd != NULL && pWnd->IsWindow())
pWnd->SetWindowText("你好啊"):
你的原因:控件被删除了,但你还在访问。
------解决方案--------------------
MFC不支持多线程操作UI。
只能在新线程里向某个窗体发送命令消息,然后在窗体里处理消息。消息的参数倒是可以全局。