I create a MFC SDI Application.
The application has CMFCRibbonEdit UI that refresh by constant rate.
But, I can't do my constant rate refresh by ON_UPDATE_COMMAND_UI.
I look like the following.
How can I refresh the UI by my rate (100ms) ?
Sample Code:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
....
m_wndRibbonBar.Create(this);
m_wndRibbonBar.LoadFromResource(IDR_RIBBON);
CMFCRibbonCategory* pCategoryTest = m_wndRibbonBar.AddCategory(L"TEST CAT", IDB_WRITESMALL, IDB_WRITELARGE);
CMFCRibbonPanel* pPanelTest = pCategoryTest->AddPanel(L"Test Panel");
pEdit_ = new CMFCRibbonEdit(ID_EDIT_1, 120, L"test");
pPanelTest->Add(pEdit_);
....
// data refresh by constant rate (100ms)
worker_ = std::thread([&] {
while (1)
{
count_ += 0.1f;
Sleep(100);
}
});
....
}
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
ON_WM_CREATE()
ON_WM_SETFOCUS()
ON_UPDATE_COMMAND_UI(ID_EDIT_1, &CMainFrame::UpdateCommandUI)
END_MESSAGE_MAP()
void CMainFrame::UpdateCommandUI(CCmdUI* pCmdUI)
{
if (pCmdUI->m_nID == ID_EDIT_1)
{
CString str;
str.Format(L"%f", count_);
pEdit_->SetEditText(str);
}
}
Success!
Thank you, IInspectable!
CMainFrame::~CMainFrame()
{
//KillTimer(TEST_TIMER_ID);
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
....
// Create CMFCRibbonEdit
....
// Delete worker thread
//worker_ = std::thread([&] {
....
// Setup Timer by 100ms
SetTimer(TEST_TIMER_ID, 100, NULL);
return 0;
}
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
ON_WM_CREATE()
ON_WM_SETFOCUS()
ON_WM_TIMER()
END_MESSAGE_MAP()
void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == TEST_TIMER_ID)
{
count_ += 0.1f;
CString str;
str.Format(L"%f", count_);
pEdit_->SetEditText(str);
}
CFrameWndEx::OnTimer(nIDEvent);
}