书上说把这段代码直接加在ch1view.cpp
#include"afxmt.h"
int m_count;
int m_data[5];
CCriticalSection critical;
//////////////////////////////////////////////////////////////////////////
class ch1View : public CView
{ UINT MyFunction1(LPVOID param)
{
critical.Lock();
for (int i=0;i<5;i++)
{
m_count++;
::Sleep(200);
m_data[i]=m_count;
}
critical.Unlock();
CString str;
str.Format("%d-%d-%d-%-%d",m_data[0],m_data[1],m_data[2],m_data[3],m_data[4]);
MessageBox((HWND) param,str,"1",MB_OK);
return 0;
}
UINT MyFunction2(LPVOID param)
{
for (int i=0;i<5;i++)
{
m_count++;
::Sleep(150);
m_data[i]=m_count;
}
CString str;
str.Format("%d-%d-%d-%d-%d",m_data[0],m_data[1],m_data[2],m_data[3],m_data[4]);
MessageBox((HWND)param,str,"2",MB_OK);
return 0;
}
是这样直接在view中添加吗?
//////////////////////////////////////////////////////////////////////////
下面是两个菜单处理程序
void CCh7_2View::OnCom()
{
// TODO: Add your command handler code here
m_count=0;
HWND hWnd=GetSafeHwnd();
AfxBeginThread(MyFunction2,hWnd);
AfxBeginThread(MyFunction2,hWnd);
}
void CCh7_2View::OnCri()
{
// TODO: Add your command handler code here
m_count=0;
HWND hWnd=GetSafeHwnd();
AfxBeginThread(MyFunction1,hWnd);
AfxBeginThread(MyFunction1,hWnd);
}
结果出现了很多错误:
error C2065: 'critical' : undeclared identifier
d:\ch72\ch72view.h(25) : error C2228: left of '.Lock' must have class/struct/union type
d:\ch72\ch72view.h(28) : error C2065: 'm_count' : undeclared identifier
d:\ch72\ch72view.h(30) : error C2065: 'm_data' : undeclared identifier
d:\ch72\ch72view.h(30) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(30) : error C2106: '=' : left operand must be l-value
d:\ch72\ch72view.h(32) : error C2228: left of '.Unlock' must have class/struct/union type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(35) : error C2660: 'MessageBoxA' : function does not take 4 parameters
d:\ch72\ch72view.h(44) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(44) : error C2106: '=' : left operand must be l-value
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(48) : error C2660: 'MessageBoxA' : function does not take 4 parameters
MainFrm.cpp
ch72Doc.cpp
ch72View.cpp
d:\ch72\ch72view.h(25) : error C2065: 'critical' : undeclared identifier
d:\ch72\ch72view.h(25) : error C2228: left of '.Lock' must have class/struct/union type
d:\ch72\ch72view.h(28) : error C2065: 'm_count' : undeclared identifier
d:\ch72\ch72view.h(30) : error C2065: 'm_data' : undeclared identifier
d:\ch72\ch72view.h(30) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(30) : error C2106: '=' : left operand must be l-value
d:\ch72\ch72view.h(32) : error C2228: left of '.Unlock' must have class/struct/union type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(34) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(35) : error C2660: 'MessageBoxA' : function does not take 4 parameters
d:\ch72\ch72view.h(44) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(44) : error C2106: '=' : left operand must be l-value
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(47) : error C2109: subscript requires array or pointer type
d:\ch72\ch72view.h(48) : error C2660: 'MessageBoxA' : function does not take 4 parameters
D:\ch72\ch72View.cpp(11) : error C2040: 'm_data' : 'int [5]' differs in levels of indirection from 'int'
D:\ch72\ch72View.cpp(12) : error C2371: 'critical' : redefinition; different basic types
D:\ch72\ch72View.cpp(115) : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
D:\ch72\ch72View.cpp(116) : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
D:\ch72\ch72View.cpp(124) : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
请大侠们指教,
先谢谢!