1、为什么在第二个函数蹦出个断点
2、我函数用的不对?
3、不要推荐我使用其他函数,我就想弄明白这个
class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
afx_msg void OnLButtonDown(UINT,CPoint);
afx_msg void OnRButtonDown(UINT,CPoint);
CStatic a,b; CWinThread * pa;
CWinThread * pb;
DECLARE_MESSAGE_MAP()
};CMainWindow::CMainWindow ()
{
Create(0,L"");
CRect r(10,10,110,210);
a.Create (L"1",WS_CHILD|WS_VISIBLE|SS_LEFT,r,this,1111);
r.left =10;r.top =220;r.right = 210;r.bottom= 310;
b.Create (L"1",WS_CHILD|WS_VISIBLE|SS_LEFT,r,this,2222);
}
UINT ThreadFucn1(LPVOID pParam)
{
UINT A;
static CStatic * c = (CStatic*)pParam;
for(int i = 0; i<= 10000; i++)
{
if( i == 200 )
AfxEndThread(A);
::Sleep (50);
wchar_t n[100];
::ZeroMemory (n,200);
wsprintf(n,L"%d",i);
c->SetWindowTextW (n);
}
return 789;
}
UINT ThreadFucn2(LPVOID pParam)
{
UINT A;
static CStatic * c = (CStatic*)pParam;
for(int i = 0; i<= 10000; i++)
{
if( i == 200 )
AfxEndThread(A);//奇怪了,程序运行到200的时候会在这蹦出个断点。
::Sleep (50);
wchar_t n[100];
::ZeroMemory (n,200);
wsprintf(n,L"%d",i);
c->SetWindowTextW (n);
}
return 0;
}
void CMainWindow::OnLButtonDown (UINT,CPoint)
{
pa = AfxBeginThread(ThreadFucn1,&a);
pb = AfxBeginThread(ThreadFucn2,&b);
}
2、我函数用的不对?
3、不要推荐我使用其他函数,我就想弄明白这个
class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
afx_msg void OnLButtonDown(UINT,CPoint);
afx_msg void OnRButtonDown(UINT,CPoint);
CStatic a,b; CWinThread * pa;
CWinThread * pb;
DECLARE_MESSAGE_MAP()
};CMainWindow::CMainWindow ()
{
Create(0,L"");
CRect r(10,10,110,210);
a.Create (L"1",WS_CHILD|WS_VISIBLE|SS_LEFT,r,this,1111);
r.left =10;r.top =220;r.right = 210;r.bottom= 310;
b.Create (L"1",WS_CHILD|WS_VISIBLE|SS_LEFT,r,this,2222);
}
UINT ThreadFucn1(LPVOID pParam)
{
UINT A;
static CStatic * c = (CStatic*)pParam;
for(int i = 0; i<= 10000; i++)
{
if( i == 200 )
AfxEndThread(A);
::Sleep (50);
wchar_t n[100];
::ZeroMemory (n,200);
wsprintf(n,L"%d",i);
c->SetWindowTextW (n);
}
return 789;
}
UINT ThreadFucn2(LPVOID pParam)
{
UINT A;
static CStatic * c = (CStatic*)pParam;
for(int i = 0; i<= 10000; i++)
{
if( i == 200 )
AfxEndThread(A);//奇怪了,程序运行到200的时候会在这蹦出个断点。
::Sleep (50);
wchar_t n[100];
::ZeroMemory (n,200);
wsprintf(n,L"%d",i);
c->SetWindowTextW (n);
}
return 0;
}
void CMainWindow::OnLButtonDown (UINT,CPoint)
{
pa = AfxBeginThread(ThreadFucn1,&a);
pb = AfxBeginThread(ThreadFucn2,&b);
}
对吗?
直接wchar_t n[100]={0};
行不
wchar_t n[100];
for(int i = 0; i<= 10000; i++)
{
::ZeroMemory (n,sizeof(wchar_t));
if( i == 200 )
AfxEndThread(A);//奇怪了,程序运行到200的时候会在这蹦出个断点。
::Sleep (50);
wsprintf(n,L"%d",i);
}