强制ListBox更新

时间:2014-07-23 14:02:40

标签: c++ user-interface listbox

我正在使用C ++和MFC,我有一个ListBox绑定到一个变量,当我运行一个函数时,我将更新:

void CFileSelection::OnBnClickedFiletousb()
{

m_LogC.AddString(_T("Starting move to USB, Please Wait..."));
UpdateData(FALSE);

// Code to move files from disk to USB

m_LogC.AddString(_T("Move to USB Successful."));

}

但是,尽管使用了UpdateData,但ListBox在完成任务之前不会填充任何一个字符串。有没有办法让它在执行其余代码之前更新屏幕?

1 个答案:

答案 0 :(得分:1)

更改列表框中的文本后使用此功能。您的问题是其他调用阻止了MessageThread,但您可以使用此强制进行更新。

void ProcessWindowMessages()
{
    MSG msg;

    while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))  // let them see the message before we go into longer term wait
    {
        TranslateMessage(&msg);                         // translate it
        DispatchMessage(&msg);                          // and let windows dispatch it to WinProc
    }
}

或者您也可以致电

yourlistboxVariable->UpdateWindow();
相关问题