-
Pausing a function
You know, if you create a message box by AfxMessageBox(...)
function, you might aware of that, the function do not return until user clicks the appropriate button e.g. Cancel, OK, Yes, No... etc.
It seems the function waits until user presses a button instead of returning a value. A function completes execution usually in a few miliseconds. But its unusual for a function to wait for an unlimited time.
I have thought about it, but got no idea on how to do that.
Would you please share, if you have any idea.
-
psudocode:
function
{
show messagebox
if(yes)
return yes;
else if(no)
return no;
}
-
int main()
{
short paused;
//set it to be paused
paused=1;
while(paused==1)
code;
code;
code;
code;
//make sure u can unpause it
paused=0;
loop;
}
-
Sleep(time);
or the Wait* family
WaitForSingleObject(hEvent);
will wait until another thread fires the event referenced by hEvent.
-
Thank you very much SteveCRM, Mushroom Realm and CornedBee.
The thing I want to do is to avoid a function from returning a value untill the user clicks on the defined coordinates. I think CornedBee`s reply is the solution of my problem.
Would you please give some details on how to adaptate WaitForSingleObject(...) function to my code.
Again, thank you all for your replies.
-
Show me your code and I'll tell you how to implement it.
-
I don`t know how to write write that code, exactly. But when the function is called, it handles mouse-down messages and checks if the mouse-down point is in the specified area; if it is, the function returns true, if not, it continues handling messages and checking if the expression is true.
My limited knowledge in C++ doesn`t seem to be enough to code that function, but I need it very badly, to complete my project.
Would you please help.
Thanks in advance.
-
I don't think I really understand what you're trying to do, since the way I interpret your explanation it would be a completly senseless thing to do.