Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

30 Experts available now in Live!

Get 1:1 Help Now