• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

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.
0
deric19
Asked:
deric19
  • 8
  • 6
  • 2
1 Solution
 
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now