Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: c++ and ... Pin
mostafa_h13-Dec-07 23:15
mostafa_h13-Dec-07 23:15 
GeneralRe: c++ and ... Pin
toxcct13-Dec-07 23:40
toxcct13-Dec-07 23:40 
GeneralRe: c++ and ... [modified] Pin
Nelek14-Dec-07 0:09
protectorNelek14-Dec-07 0:09 
GeneralRe: c++ and ... Pin
toxcct14-Dec-07 0:40
toxcct14-Dec-07 0:40 
JokeRe: c++ and ... Pin
Nelek14-Dec-07 0:42
protectorNelek14-Dec-07 0:42 
GeneralRe: c++ and ... Pin
toxcct14-Dec-07 0:47
toxcct14-Dec-07 0:47 
GeneralRe: c++ and ... Pin
mostafa_h14-Dec-07 5:18
mostafa_h14-Dec-07 5:18 
QuestionHow to end a thread Pin
Chen-XuNuo13-Dec-07 19:07
Chen-XuNuo13-Dec-07 19:07 
I am doing a TankGame program,and I write a CBullet class.I write a thread function to make it move when it is created:

UINT BulletGo(LPVOID pParam)
{
CBullet* bullet=(CBullet*)pParam;
while(TRUE)
{
switch(bullet->m_bCanGo.GetDirection())
{
case UP:
bullet->GoUp();
break;
case DOWN:
bullet->GoDown();
break;
case LEFT:
bullet->GoLeft();
break;
case RIGHT:
bullet->GoRight();
break;
}
if(!bullet->m_bCanGo)
break;
else
bullet->MoveWindow(bullet->GetPosition().x,
bullet->GetPosition().y,
bullet->GetThisRect().Height(),
bullet->GetThisRec().Width());
Sleep(30);
}
return 0;
}

int CBullet::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatic::OnCreate(lpCreateStruct) == -1)
return -1;

m_bCanGo=TRUE;
m_pThread=AfxBeginThread(BulletGo,this); //begin thread

return 0;
}

BOOL CBullet::GoDown()
{
if((m_ptPosition.y+m_rtThis.Height())>m_rtParent.bottom)
{
m_ptPosition.y+=2;
m_bCanGo=TRUE;
return TRUE;
}
else
{
this->DestroyWindow();
m_bCreated=FALSE;
m_bCanGo=FALSE;
return FALSE;
}
}

When the bullet go down and hit the bottom of client rect the program apprear errors.Why...Don't the "break" in the BulletGo() end the thread?
AnswerRe: How to end a thread Pin
Llasus13-Dec-07 19:21
Llasus13-Dec-07 19:21 
GeneralRe: How to end a thread Pin
Chen-XuNuo14-Dec-07 4:32
Chen-XuNuo14-Dec-07 4:32 
AnswerRe: How to end a thread Pin
Mark Salsbery13-Dec-07 19:23
Mark Salsbery13-Dec-07 19:23 
GeneralRe: How to end a thread Pin
Chen-XuNuo14-Dec-07 4:34
Chen-XuNuo14-Dec-07 4:34 
GeneralRe: How to end a thread Pin
Mark Salsbery14-Dec-07 4:58
Mark Salsbery14-Dec-07 4:58 
GeneralRe: How to end a thread Pin
Chen-XuNuo14-Dec-07 18:03
Chen-XuNuo14-Dec-07 18:03 
GeneralRe: How to end a thread Pin
Mark Salsbery15-Dec-07 7:45
Mark Salsbery15-Dec-07 7:45 
GeneralRe: How to end a thread Pin
Chen-XuNuo14-Dec-07 18:15
Chen-XuNuo14-Dec-07 18:15 
GeneralRe: How to end a thread Pin
Mark Salsbery15-Dec-07 7:33
Mark Salsbery15-Dec-07 7:33 
GeneralRe: How to end a thread Pin
Chen-XuNuo15-Dec-07 3:14
Chen-XuNuo15-Dec-07 3:14 
GeneralRe: How to end a thread Pin
Mark Salsbery15-Dec-07 7:31
Mark Salsbery15-Dec-07 7:31 
GeneralRe: How to end a thread Pin
Chen-XuNuo15-Dec-07 14:52
Chen-XuNuo15-Dec-07 14:52 
AnswerRe: How to end a thread Pin
Cedric Moonen13-Dec-07 20:26
Cedric Moonen13-Dec-07 20:26 
GeneralRe: How to end a thread Pin
Mark Salsbery13-Dec-07 20:38
Mark Salsbery13-Dec-07 20:38 
GeneralRe: How to end a thread Pin
Chen-XuNuo14-Dec-07 4:40
Chen-XuNuo14-Dec-07 4:40 
GeneralC2365 error Pin
subramanyeswari13-Dec-07 18:54
subramanyeswari13-Dec-07 18:54 
GeneralRe: C2365 error Pin
Mark Salsbery13-Dec-07 19:13
Mark Salsbery13-Dec-07 19:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.