locked
How to gray the top menu? (not disable) RRS feed

  • Question

  • Hi there,

    I can disable the whole menu by the following code, nothing happen when I click the top menu. But the top menu will not be grayed.  But I do can gray a submenu by EnableMenuItem.

    I use Visual Studio 2008, and Windows CE 5.0 (x86).

    	if(m_pMenu != NULL)
    	{
    	   for(UINT i = 0; i < m_pMenu->GetMenuItemCount (); ++i)
    	   m_pMenu->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED);
    	}

    Anybody know why? Thanks


    Circle

    Monday, November 12, 2012 9:20 AM

Answers

  • In MFC Feature Pack the menus are not CMenu derived, they are CMFCMenuBar derived. This is not a menu it is more a special button bar. Therefore the menu commands will not work. I'd say iti s not possible to disable the main menu item in a CMFCMenuBar menu without making changes in CMFCMenuBar or the inherited classes.

    I was fiddelning some time ago with the Theme Manager around to have themed dialog window frames. The problem is the documentation is cr** (means not good) and you have to investigate the source code line by line with the debugger. I'd not invest too much time in a gray menu item.

    Your other problem with flickering is an other story. I guess the flickering is resulted from the background repaint. You may have to use a memory DC and copy everything to your device DC during background repaint. Emulators (I guess you meant a Virtual Machine) is not always 100% the copy of the reality. Also real PCs with different hardware sometimes behave not identical.

    Here some articles:

    http://www.codeproject.com/Articles/12870/Don-t-Flicker-Double-Buffer

    http://www.codeproject.com/Articles/33/Flicker-Free-Drawing-In-MFC

    http://www.codeproject.com/Articles/4199/Further-discussions-on-flicker-free-drawing

    Tuesday, November 13, 2012 12:32 PM

All replies

  • If you want to disable the "top level" menu item you can use the EnableMenuItem function too.

    This piece of code diables the "top level" menu item #1 (count begins with zero:

       HMENU m;
       BOOL b;
       
       m=GetMenu(hWnd);
       b=EnableMenuItem(m, 1, MF_BYPOSITION | MF_GRAYED);  
    If you have i.e. the top level menu items "File" - "Edit" - "Help", than this code piece disables the "Edit" menu item"
    Monday, November 12, 2012 2:07 PM
  • Hi,

    Thanks Bordon.

    Sorry I might didn't make myself clear. My code works fine to disable the top menu, and of course, the submenu. But the top menu can't be grayed. That's what bothered me, why EnableMenuItem can gray the submenu(disabled of course), but can't gray the top menu? It only disables the top menu.

    Can you help me with this? Thanks,

    Circle

    Monday, November 12, 2012 5:23 PM
  • What type of MFC program did you create? MFC SDI, MDI ,with MFC Feature pack styles. Please be more specific. I'd say graying the a top level menu item should not be a problem. Also a try would be combining MF_GRAYED and MF_DISABLED
    Tuesday, November 13, 2012 5:23 AM
  • Hi,

    It is a SDI application with MFC Feature pack styles.

    I tried MF_GRAYED and MF_DISABLED but still it can't gray the top menu.

    BTW, my code flickers when execute BitBlt function. but the same .exe file doesn't flicker in the emulator. 

    So anything might be wrong?


    Circle

    Tuesday, November 13, 2012 12:00 PM
  • In MFC Feature Pack the menus are not CMenu derived, they are CMFCMenuBar derived. This is not a menu it is more a special button bar. Therefore the menu commands will not work. I'd say iti s not possible to disable the main menu item in a CMFCMenuBar menu without making changes in CMFCMenuBar or the inherited classes.

    I was fiddelning some time ago with the Theme Manager around to have themed dialog window frames. The problem is the documentation is cr** (means not good) and you have to investigate the source code line by line with the debugger. I'd not invest too much time in a gray menu item.

    Your other problem with flickering is an other story. I guess the flickering is resulted from the background repaint. You may have to use a memory DC and copy everything to your device DC during background repaint. Emulators (I guess you meant a Virtual Machine) is not always 100% the copy of the reality. Also real PCs with different hardware sometimes behave not identical.

    Here some articles:

    http://www.codeproject.com/Articles/12870/Don-t-Flicker-Double-Buffer

    http://www.codeproject.com/Articles/33/Flicker-Free-Drawing-In-MFC

    http://www.codeproject.com/Articles/4199/Further-discussions-on-flicker-free-drawing

    Tuesday, November 13, 2012 12:32 PM