Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 185
has22 challenge 11 94
post4 challenge 28 100
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 253
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 …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

772 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