How to show the list items one by one when the function is running

159 views Asked by At

My list control item will only be shown up when the function was stopped. I need to show the list control item one by one when the function is running.

Another function continually passes values to HRESULT function() until data processing is done.

//function to show the list item
HRESULT function(datetime, strNumOfGroup, strDisributionRegion, strSpeed){

  m_count = m_hyperTerminal.GetItemCount();

  items = m_hyperTerminal.InsertItem(m_count, datetime);// Five columns in the list control

  m_hyperTerminal.SetItemText(items, 1, strNumOfGroup);
  m_hyperTerminal.SetItemText(items, 2, strCompactness);
  m_hyperTerminal.SetItemText(items, 3, strDistributionRegion);
  m_hyperTerminal.SetItemText(items, 4, strSpeed);
}
1

There are 1 answers

0
Barmak Shemirani On

This is animation and it generally needs a second thread to update the display.

However using a second thread might be overkill. You may call SetTimer to update the window at fixed intervals. Then catch WM_TIMER messages, in OnTimer do all the updates in OnTimer. Once you are finished with the animation, call KillTimer

Example:

BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
    ...
    ON_WM_TIMER()
END_MESSAGE_MAP()

BOOL CMyDialog::OnInitDialog()
{
    BOOL res = CDialog::OnInitDialog();
    ...
    SetTimer(1, 1000, NULL);
    return res;
}

void CMyDialog::OnTimer(UINT_PTR nid)
{
    CDialog::OnTimer(nid);
    if(nid == 1)
    {
        static int n = 0;
        if(n == 0) m_hyperTerminal.SetItemText(0, 1, L"strNumOfGroup");
        if(n == 1) m_hyperTerminal.SetItemText(0, 2, L"strCompactness");
        if(n == 2) m_hyperTerminal.SetItemText(0, 3, L"strDistributionRegion");
        if(n == 3) m_hyperTerminal.SetItemText(0, 4, L"strSpeed");
        n++;
        if(n > 4)
            KillTimer(1);
    }
}