WTL中菜单栏及工具栏项状态改变应注意的地方

时间:2023-02-11 07:50:13

WTL中菜单栏项和工具栏按钮的状态可通过UISetCheck(int ITEM_ID, int STATE)进行设置

需要注意的是要将需要改变状态的控件ID添加到UI更新映射中

/* MainFrame.h */

class CMainFrame : public CFrameWindowImpl<CMainFrame>,

                   public CUpdateUI<CMainFrame>,

                   public CIdleHandler {

    public:

    .....

    virtual BOOL OnIdle();

 

    BEGIN_UPDATE_UI_MAP(CMainFrame)

        UPDATE_ELEMENT(ID_XXX, UPDUI_XXXX)

        ....

    END_UPDATE_UI_MAP()

    .....

} 

 

/* MainFrame.cpp */

BOOL CMainFrame::OnIdle() {

    UIUpdateToolBar();

    return FALSE;

}

 

LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {

    ......

    UISetCheck(ID_XXX, 1);

    ......

    return 0;

}