CMainFrame里创建的线程函数怎么获取视图里的资源
CMainFrame里创建的线程函数如何获取视图里的资源
如题,在CMainFrame类里创建一个线程:
void CMainFrame::OnBatchExec()
{
// TODO: Add your command handler code here
CWinThread *pThread;
pThread=AfxBeginThread(ExecThread,this);
}
线程函数的实现方法如下:
UINT ExecThread(LPVOID lParam)
{
CMainFrame * pMain=(CMainFrame *)lParam;
CEdit& edit = pMain->GetView()->GetEditCtrl();
return 0;
}
执行后发现edit 的值为空,并未获取到资源,请问是何种原因呢
------最佳解决方案--------------------
一般是用发消息的方式给view的!
再说,你里面没有设置edit值的语句啊?
------其他解决方案--------------------
MFC类非线程安全,改用HWND窗口句柄吧~
------其他解决方案--------------------
能稍微说的具体一点吗
------其他解决方案--------------------
盼赐教
------其他解决方案--------------------
就是直接将View类的窗口句柄HWND传递给线程,在线程函数中发送自定义消息到View类,在View类的自定义消息响应函数中区更新信息
------其他解决方案--------------------
CEdit& edit = pMain->GetView()->GetEditCtrl();
这里面的内容都看不见啊。
------其他解决方案--------------------
这是个输入框
------其他解决方案--------------------
long i,len=edit.GetLineCount();
for (i=0; i<len; i++) {
leng = edit.LineLength(edit.LineIndex(i));
if (leng != 0) {
edit.GetLine(i,(LPTSTR)cText,MAX_LENGTH);
cText[leng] = '\0';
str.Format(cText);
str.TrimLeft();
str.TrimRight();
……
}
如题,在CMainFrame类里创建一个线程:
void CMainFrame::OnBatchExec()
{
// TODO: Add your command handler code here
CWinThread *pThread;
pThread=AfxBeginThread(ExecThread,this);
}
线程函数的实现方法如下:
UINT ExecThread(LPVOID lParam)
{
CMainFrame * pMain=(CMainFrame *)lParam;
CEdit& edit = pMain->GetView()->GetEditCtrl();
return 0;
}
执行后发现edit 的值为空,并未获取到资源,请问是何种原因呢
------最佳解决方案--------------------
一般是用发消息的方式给view的!
再说,你里面没有设置edit值的语句啊?
------其他解决方案--------------------
MFC类非线程安全,改用HWND窗口句柄吧~
------其他解决方案--------------------
能稍微说的具体一点吗
------其他解决方案--------------------
盼赐教
------其他解决方案--------------------
就是直接将View类的窗口句柄HWND传递给线程,在线程函数中发送自定义消息到View类,在View类的自定义消息响应函数中区更新信息
------其他解决方案--------------------
CEdit& edit = pMain->GetView()->GetEditCtrl();
这里面的内容都看不见啊。
------其他解决方案--------------------
这是个输入框
------其他解决方案--------------------
long i,len=edit.GetLineCount();
for (i=0; i<len; i++) {
leng = edit.LineLength(edit.LineIndex(i));
if (leng != 0) {
edit.GetLine(i,(LPTSTR)cText,MAX_LENGTH);
cText[leng] = '\0';
str.Format(cText);
str.TrimLeft();
str.TrimRight();
……
}