AntBon
asked on
Application->Terminate() ???
Hello i am using Borland Builder 4 and have a problem with 'Application->Terminate()'
I have written some code (i have shown an excerp below). I am trying to terminate the application when a count is equal to 15. At the moment it doesn't work, i have debugged the code, and i have SEEN it perform the Application->Terminate() function, when i have stepped through it, but the program just continues on.
How can this be ? - What am i doing wrong.
Please help
thanx
if (RoadSign[i] == HotSpotNum)
{
sndPlaySound(String("Corre ct"+String ( Response)+String(".wav")). c_str(),SN D_SYNC);
HotSpotList->HotSpot[HotSp otNum->Mak eCold();
if (i == 8)
{
HotSpotList = new THotSpotList(this,String(" 2ndroad.bm p"),3);
Canvas->Draw(0,0,HotSpotLi st->bmpBac kground);
}
else if (i == 15) //Terminate
{
Application->Terminate();
}
//Next sign to guess
sndPlaySound(String(HotSpo tList->Hot Spot[RoadS ign[++i]]- >GetText() +
String(".wav")).c_str(),SN D_SYNC);
}
I have written some code (i have shown an excerp below). I am trying to terminate the application when a count is equal to 15. At the moment it doesn't work, i have debugged the code, and i have SEEN it perform the Application->Terminate() function, when i have stepped through it, but the program just continues on.
How can this be ? - What am i doing wrong.
Please help
thanx
if (RoadSign[i] == HotSpotNum)
{
sndPlaySound(String("Corre
HotSpotList->HotSpot[HotSp
if (i == 8)
{
HotSpotList = new THotSpotList(this,String("
Canvas->Draw(0,0,HotSpotLi
}
else if (i == 15) //Terminate
{
Application->Terminate();
}
//Next sign to guess
sndPlaySound(String(HotSpo
String(".wav")).c_str(),SN
}
I would guess that teh Terminate() function simply calls PostQuitMessage(). this will post a WM_QUIT to your message queue. This will cause the application to termiante its message loop and then proceeed tot eh end of WinMain() in order to terminate the application. But the termination happens later, when this message is read from the queue. You need to return to the message loop in order for this to occur. There are ways to termiante the application immediately, like by callign TerminateProcess(), but that is usually not a good idea. If possible, you should terminate by ending the message loop and ending main.
ASKER
Can you possible show me what you mean. I think i understand, after the Terminate() function, i used to have a
Application->ProcessMessag es(), but this made no difference.
How can i return to the message loop then, so i can terminate from there.
thanks
Application->ProcessMessag
How can i return to the message loop then, so i can terminate from there.
thanks
The code that is calling
Application->Terminate()
is probably called from the message loop or from something that is called from the message loop. (Right? this code is probably (ultimately) called from a message, like a mouse press or a command, right) So you just need to return (and return and return if needed) to the message loop.
Note I am assuming that this is what Termiante() does, it is a reasonable assumption, but still an assumption.
Application->Terminate()
is probably called from the message loop or from something that is called from the message loop. (Right? this code is probably (ultimately) called from a message, like a mouse press or a command, right) So you just need to return (and return and return if needed) to the message loop.
Note I am assuming that this is what Termiante() does, it is a reasonable assumption, but still an assumption.
ASKER
Thanks you were correct, i simply added a return statement after the terminate() statement, and it works fine.
I am not used to Windows programming, i am doing a course - and have an assignment to hand it.
So i may be asking more questions later on ...Hope you dont mind
anyway thanks again
I am not used to Windows programming, i am doing a course - and have an assignment to hand it.
So i may be asking more questions later on ...Hope you dont mind
anyway thanks again
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.