CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2012
    Location
    India
    Posts
    193

    Menubar / Toolbar problem

    Hi .. I need to activate and deactivate Menubar and Toolbar time to time.
    I have written code :

    CWnd * pFrame = (CWnd *)AfxGetMainWnd();
    CMenu * menu = pFrame->GetMenu();

    for (int mq = 0;mq < menu->GetMenuItemCount();mq++)
    menu->EnableMenuItem(mq,MF_BYPOSITION|MF_GRAYED);

    pFrame->DrawMenuBar();

    I just change attibute MF_GRAYED to MF_ENABLED as required.

    This works fine with MenuBar but there is a problem with ToolBar .

    Toolbar Enable/Disable doesnot happen properly.

    PL Guide

    Thanking you ...

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Menubar / Toolbar problem

    There is an ON_UPDATE_COMMAND_UI mechanism in MFC to enable/disable menu items as well as toolbar buttons
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2012
    Location
    India
    Posts
    193

    Re: Menubar / Toolbar problem

    Victor Sir , I am using ON_UPDATECOMMAND_UI to Enable/Disable Menu Items .

    Here , I have a Replay Old Files option in my software. While Replaying the old file , I wish to disable the whole MenuBar and ToolBar . Once Replay is over , the user presses Escape and he is back to the routine software.

    So I call DrawMenuBar function with attributes MF_GRAYED and MF_ENABLED.

    Sometimes this works fine.

    Sometimes , the MenuBar is active but Toolbar remains inactive.(Though Toolbar IDS are same as MenuItem ids). Sometimes the MenuBar is disabled but Toolbar remains enabled.

    So I am confused.

    PL guide.Thanking you ...

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Menubar / Toolbar problem

    Quote Originally Posted by new_2012 View Post
    [...]
    So I call DrawMenuBar function with attributes MF_GRAYED and MF_ENABLED.
    [...]
    Confused...
    How did you that?
    Both CWnd:: DrawMenuBar and :: DrawMenuBar functions take no arguments.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Jan 2012
    Location
    India
    Posts
    193

    Re: Menubar / Toolbar problem

    ovidiucucu sir , I set Menu Item property to either MF_ENABLED or MF_GRAYED , and then call DrawMenuBar ..

    Sometimes It takes proper attributes and sometimes it does not ..

    So I am confused

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Menubar / Toolbar problem

    Is this confusing, too?
    Quote Originally Posted by VictorN View Post
    There is an ON_UPDATE_COMMAND_UI mechanism in MFC to enable/disable menu items as well as toolbar buttons
    I see it neat and clear.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

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