Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

call a function continuously till a button on dialog box is clicked

Posted on 2004-04-28
4
Medium Priority
?
254 Views
Last Modified: 2013-11-20
Hi,
 I want a call a function continuously till a button is clicked.
created a dialog resource having a listbox and a button.
as soon as the dialog opens start calling function
return from the function should be placed in list box.
this should continue untill button on dialog is clicked.

I tried putting function in a loop but it freezes the dialog untill the loop is completed.

Iam new to vc++. help me.please

Thanks
Sahaj

0
Comment
Question by:su_us_76
4 Comments
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 750 total points
ID: 10942696
A simple way is to use a timer.

In your OnInitDialog have a line
SetTimer(1, 100, NULL);
this should generate a timer event 10 times a second (note it doesn't mean 10 timer events in one second if the routine takes longer than 0.1 seconds or the system is busy then you will get less timer events).
map the WM_TIMER message (class wizard).
In that call your function.
For your button provide a handler with the line
KillTimer(1);
this is to stop the timer.

0
 
LVL 14

Expert Comment

by:wayside
ID: 10942870
You could create a thread which will run a loop that calls your function, and post an event back to the dialog when you want to add something in the listbox. You can use a global variable set when the button is pressed to break out of the loop and exit the thread.
0
 

Author Comment

by:su_us_76
ID: 11118952
Thanks  Andy.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question