Solved

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

Posted on 2004-04-28
4
214 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 44

Accepted Solution

by:
AndyAinscow earned 250 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now