Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

edit box: displaying status info

Status
Not open for further replies.

goju

Programmer
Sep 25, 2001
6
US
I want to continuously update status information in the edit box. Below is a sample program:
(void)CTestDlg::OnTestButton()
{
int i;
time_t first, second;

m_ReceivedString = "Testing...";
UpdateData(FALSE);
(void)time(&first);
(void)time(&second);
while(difftime(second, first) < 2.0) // 2 seconds delay
(void)time(&second);

for(i=0; i<5; i++)
{
if(i==0)
{
m_ReceivedString = &quot;Zero&quot;;
UpdateData(FALSE);
}
if(i==1)
{
m_ReceivedString = &quot;One&quot;;
UpdateData(FALSE);
}
if(i==2)
{
m_ReceivedString = &quot;Two&quot;;
UpdateData(FALSE);
}
if(i==3)
{
m_ReceivedString = &quot;Three&quot;;
UpdateData(FALSE);
}
if(i==4)
{
m_ReceivedString = &quot;Four&quot;;
UpdateData(FALSE);
}
(void)time(&first);
(void)time(&second);
while(difftime(second,first) < 2.0) // 2 sec delay
(void)time(&second);
}
}
When running this program,
I wanted the following to be displayed in the edit box:
Testing...
followed by
One
followed by
Two
followed by
Three
followed by
Four

When running the program, only the last line
Four
is displayed.
What needs to be done to get all 5 lines to be displayed
one after the other?
 

Use Sleep() as your delay function. You don't have a delay with the while loop you have.

The Sleep function suspends the execution of the current thread for a specified interval.

VOID Sleep(
DWORD dwMilliseconds // sleep time in milliseconds
);

Try this out, I shortened your code for ya too:

int index;
char* NumStr[] = {&quot;zero&quot;,&quot;one&quot;,&quot;two&quot;,&quot;three&quot;,&quot;four&quot;};

for(index = 0; index <= 4;index++){
m_ReceivedString = NumStr[index];
UpdateData(FALSE);
Sleep(2000);
}


Brother C
 
Brother C,
I tried your version of my program and it works exactly as
mine does. It only displays the last string (&quot;Four&quot;)in the edit box. I looked at the edit box properties and tried
numerous combinations, but they all gave me the same result.
This program executes when a pushbutton is selected. If you
have other ideas or suggestions, I would like to hear from you.
Thanks for your time,
goju
 
Add an UpdateWindow() function to issue an WM_PAINT message

int index;
char* NumStr[] = {&quot;Testing...&quot;,&quot;zero&quot;,&quot;one&quot;,&quot;two&quot;,&quot;three&quot;,&quot;four&quot;};

for(index = 0; index <= 5;index++){
m_Value = NumStr[index];
UpdateData(FALSE);
UpdateWindow();
Sleep(2000);
}
 
Hi jfhuang,
My program is working fine now. Thank you for your help.
goju
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top