CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    12

    Disable Toolbar Button

    I am attempting to temporarily disable a toolbar button from within my application.
    I tried this...

    CToolBarCtrl& toolbar = m_wndToolBar.GetToolBarCtrl();
    toolbar.EnableButton(ID_NEXT, FALSE);



    However, it only disables the button while still within the scope of that function.
    As soon as that function returns the button is enabled again.
    I am sure that I am missing something simple, but I can't figure out what exactly.
    What do I need to do to force the button to be disabled until I actually want
    it enabled again?
    Please help!!!

    Thanks,
    Kyle


  2. #2
    Join Date
    May 1999
    Posts
    28

    Re: Disable Toolbar Button

    Why not just use:

    m_wndToolBar.EnableButton(ID_NEXT, FALSE);



    I don't know if this is the case, but maybe your local variable "toolbar" is out of scope once the function completes.

    Chris R. Wheeler, MCP
    Pensacola Christian College
    Desktop Programmer
    [email protected]

  3. #3
    Join Date
    May 1999
    Posts
    12

    Re: Disable Toolbar Button

    Chris,
    Thank you for your response. I apologize if my questions seem
    a bit dense, but I don't deal with the ToolBar very often.

    m_wndToolBar is a CToolBar object and EnableButton is not a member of it.
    I used the GetToolBarCtrl function to get a reference to the CToolBarCtrl.
    EnableButton is a member of CToolBarCtrl.

    Since GetToolBarCtrl returns a reference the m_wndToolBar object
    is the fact that the CToolBarCtrl is out of scope an issue? I thought
    that by referencing the underlying control I didn't have to have the
    CToolBarCtrl defined.

    I tried defining toolbar as a CToolBarCtrl object in the header
    and then using the GetToolBarCtrl to reference the CToolBar
    object, but I ended up with the same result.

    Am I missing something fundamental about this control?

    Thanks,
    Kyle


  4. #4
    Join Date
    May 1999
    Posts
    28

    Re: Disable Toolbar Button

    Maybe you've solved this since I was out all weekend, but I'll suggest this anyway. Create a Message Handler in your mainframe for the button's command ID. Use UPDATE_COMMAND_UI. Then, in the handler, put this:
    pCmdUI->Enable(TRUE);


    That will enable the button so that it isn't gray and can be clicked on. You then have to create a message handler for the COMMAND of that button.

    Chris R. Wheeler, MCP
    Pensacola Christian College
    Desktop Programmer
    [email protected]

  5. #5
    Join Date
    May 1999
    Posts
    12

    Re: Disable Toolbar Button

    Thanks Chris.

    I will paste in what I ended up doing, just in case someone else is trying
    to accomplish this and reads this conversation.

    First added a handler for the ON_UPDATE_COMMAND_UI in the MainFrame class
    ON_UPDATE_COMMAND_UI(ID_FIRST, UpdateRequery)



    Then, I added the actual function. Since I wanted the button enabled while there was
    a valid database connection and disabled when they had disconnected I just used the
    IsOpen function in CDatabase to determine whether the buttons Enable status
    should be TRUE or FALSE.

    void CMainFrame::UpdateRequery(CCmdUI* pCmdUI)
    {
    pCmdUI->Enable(m_db.IsOpen());

    }



    Then, when I close the database (menu option) I just make sure
    to update the FrameWnd.

    m_db.Close();
    m_wndToolBar.OnUpdateCmdUI(this, TRUE);




    Thats it. The actual function mapped to ID_FIRST is actually in the View class,
    but enabling or disabling the button in the FrameWnd class prevents that message altogether.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured