如何随时刷新功能区 UI?

How can I refresh for Ribbon UI at any time?

我创建了一个 MFC SDI 应用程序。

应用程序有 CMFCRibbonEdit UI 以恒定速率刷新。

但是,我无法通过 ON_UPDATE_COMMAND_UI 进行恒定速率刷新。

我长得像下面这样

如何按我的速率(100 毫秒)刷新 UI?

示例代码:

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);
    }
}

成功!

谢谢你,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);
}