我将 C++ 与 MFC 一起使用,并且我有一个 ListBox 绑定(bind)到一个变量,我在运行一个函数时正在更新该变量:
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 在完成其任务之前不会填充任何一个字符串。有没有办法让它在执行其余代码之前更新屏幕?
最佳答案
在更改列表框上的文本后使用此函数。您的问题是其他调用阻止了 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();
关于c++ - 强制列表框更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24912617/