how to loop a command & let the dialog still appear after pressing OK

i' currently using visual C++ 6.0. i'm doing a program using dialog based (EXE). i try to loop a command using if and sleep, but it only run once. how to loop it? i have tried to place the command under IDOK and declare new function in the Dlg class. i also face a problem when pressing OK. the dialog close straight away. how to let the dialog still appear if i press OK, but close when i press exit. thanks for your advice.
deric19Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nietodCommented:
You need to write a loop.  c++ primarily supports 3 types of loops.  the "while" and "do" loops are usually used in cases where an action should repeat until some condition is true.  For example, you might want to print printing an error message until the error condition is cleared.  The "for" loop is usually used when you need to perform an action a certain number of times.  Like if you need to print out all the names in a list, for example.

That is about as much as I can tell you without more details from you.  What is the action yoe want to repeat?  how do you know when to stop?  why were you using sleep? etc.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aperdonCommented:
while and do should not be used in an GUI application.
better use a timer instead.

about EndDialog. You should override this virtual function.
0
nietodCommented:
>> while and do should not be used in an GUI application.
>> better use a timer instead.
That is absurd!  I can't image writting any program without loops.  And how do you use a timer in windows without a loop?  You need to get messages repeatedly.

>> about EndDialog. You should override
>> this virtual function.
What virtual function?  This isn't the MFC topic area and deric19 hasn't mentioned MFC.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

aperdonCommented:
well well nietod.

what i meant is that it isnot wise to use a loop which takes a long time in a windows program, since no one can get the cpu meanwhile.

but ofcours you r the expert.....
0
nietodCommented:
There is no indication that this loop takes a long time.  But if it does, the best solution is often to create a 2nd thread to do the processing, or if multi-threadig is not an option, use a peekmessage loop to handle message processing during the processing.  A timer should only be used if the processing has relatively low "prority" as the messages are not going to occur frequently (so a time consuming operation would become even more time consuming).
0
aperdonCommented:
He said is going to sleep.
>>>i try to loop a command using if and sleep,

For me not a wise option.
0
nietodCommented:
No, sleeping for long periods would not be wise.  Its not clear why he is using sleep though.
0
aperdonCommented:
I think he uses sleep to execute the commands each several seconds. For this normally a timer is used.
0
nietodCommented:
Perhaps, but he also says he is trying to use a "if" to loop.  I wouldn't try to read too much into those comments.

denic, are we going to hear from you?
0
deric19Author Commented:
thanks guys for your comment. i used while instead of if, it works. i just can't imagine why if can't be used like i used to do in C++.
0
nietodCommented:
"if" can't be used to make a loop.  Not in C or C++ or probably in any language.

How were you using it?
0
deric19Author Commented:
if the condition you set haven't meet, it will continue looping. that's what i've been used in c++ programming.
0
nietodCommented:
No, not unless you have a "break" in the "if" and the "if" is enclosed in a loop.  (so the "if" doesn't loop, it ends the loop)

Show us the code you were using.
0
aperdonCommented:
>>if the condition you set haven't meet, it will continue looping. that's what i've been used in c++ programming.

for me this sounds like repeat-until, which is not in C(++)
0
nietodCommented:
repeat-until is pascal (and probably others) but C/C++ has do...while which is equivalent (except the end condition is opposite).

However, I can't believe that he is confussing a do loop (or other loop) with an "if".
0
aperdonCommented:
i think he is completety confused
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.