在工具栏按下的状态由一个变量控制,但是这个变量在程序运行过程中有可能发生变化我想在变量改变时候,工具栏状态也跟着改变,请教大家了。

解决方案 »

  1.   

    在MainFrm类中,为你所需要的工具栏中的选项ID添加OnUpdate消息,即使传送这个变量的值给他。这样就可以实现了。
      

  2.   

    你使用的是啥开发工具?
    点开类视图,找到MainFrm类
    添加事件,选择UPDATE_COMMAND_UI,添加消息处理函数。
    函数格式如下:
    void CMainFrame::OnUpdateCaseSave(CCmdUI *pCmdUI)
    {
    // TODO: 在此添加命令更新用户界面处理程序代码
    pCmdUI->Enable(m_bSave);
    }
    其中pCmdUI->Enable(TRUE或者FALSE)
    就是控制这个工具栏选项是否可选
      

  3.   

    // 管理按钮的状态
    void CstudyToolDlg::SetButtonState(void)
    {
    if(m_IsStudy==false)
    {
    m_startButton.EnableWindow(TRUE);
    m_endButton.EnableWindow(FALSE);
    m_operationButton.EnableWindow(TRUE);
    }
    else
    {
    m_startButton.EnableWindow(FALSE);
    m_endButton.EnableWindow(TRUE);
    m_operationButton.EnableWindow(FALSE);
    }
    }
    参考以上代码,在需要修改按钮状态时,调用SetButtonState函数。其中m_startButton、m_endButton、m_operationButton都关联一个按钮。
      

  4.   

    不好意思,我把Run给重写了,就出了问题,为什么会这样
    int CmApp::Run() 
    {
    MSG msg; 
    while(1)  

    if(PeekMessage(&msg, NULL,0,0,PM_REMOVE))

    if(msg.message==WM_QUIT)

    return msg.wParam; 

    else if(!TranslateAccelerator(msg.hwnd,m_hAccelTable,&msg))

    TranslateMessage(&msg); 
    DispatchMessage(&msg); 


    else 

    // process the player 
    if(!CCustomPlayer::Instance().Process(m_Config)) 

    PostQuitMessage(0); 



    return msg.wParam;