Handle UPDATE_COMMAND_UI for the menu item and
call
pCmdUI->Enable(FALSE);
Cheers
Check Abdoul
-----------------
"Gerhard" <ger...@ginko.de> wrote in message
news:39aa...@news.ginko.net...
> Hi,
>
> I have another problem in MFC.
> My goal is that one of the menus is disabled at startup and gets enabled
> after the initialization (which takes a while) is complete.
> To disable I checked "gray" in the Ressource Editor, now I'd like to
enable
> at the end of CWinApp::InitInstance().
>
> I do this with the following two simple code lines:
>
> CMenu *menu = m_pMainWnd->GetMenu();
> menu->EnableMenuItem(3, MF_ENABLED);
>
> I hope I got the flag right, I don't have any code or doc at my disposal
at
> the
> moment...
>
> This code does simply nothing. What's wrong?
> Thank you very much again
>
> Gerhard
>
>
>
>
Not sure, but try adding an MF_BYPOSITION (or MF_BYCOMMAND if that's what it is) to your
EnableMenuItem call. Like so...
menu->EnableMenuItem(3, MF_ENABLED|MF_BYPOSITION);
If that doesn't fix it post a follow-up, and I'll really get my hands dirty if that's what it takes.
HTH,
Jeff...
--
Please post all follow-ups to the newsgroup only.
Gerhard wrote in message <39aa...@news.ginko.net>...
> Not sure, but try adding an MF_BYPOSITION (or MF_BYCOMMAND if that's what it is) to your
> EnableMenuItem call. Like so...
>
> menu->EnableMenuItem(3, MF_ENABLED|MF_BYPOSITION);
Thank you, MF_BYPOSITION was indeed needed. Now the command basically works, the button is enabled but
remains grayed until clicking once on it. How to fix this?
I also tried the other way, using the UPDATE_COMMAND_UI message. Unfortunately this is called directly
after the app has been started, which is not my intention. Moreover this msg doesn't seem to work at all
for pop-up menus.
Thanks a lot!
Gerhard
This is a top-level item on the apps main menu right? Try something like this (from the end of a
standard MFC InitInstance)...
BOOL CNg81500App::InitInstance()
{
...
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
CMenu* pMenu = pMainFrame->GetMenu();
if (pMenu)
{
pMenu->EnableMenuItem(3, MF_ENABLED|MF_BYPOSITION);
pMainFrame->DrawMenuBar();
}
return TRUE;
}
Jeff...
--
Please post all follow-ups to the newsgroup only.
Gerhard Prilmeier wrote in message <39AB7C87...@ops.de>...
>
> pMainFrame->DrawMenuBar();
Yeah that's it! Thanks
Bye
Gerhard
The result was exactly nothing.
I also tried menu->ModifyMenu() which simply removed the menu item instead of graying it.
I also tried to remove the menu and re-insert it with the grayed flag. The result was the same as with
ModifyMenu().
Of course I used DrawMenuBar() as well.
If you are interested I'll send you my code, just tell me.
Thank you very much
Gerhard
Gerhard Prilmeier <gerhard....@ops.de> wrote:
Jim [VC/MFC MVP]
To send mail, change spam-me-not to msn
>I retrieved a pointer using GetMenu() etc., then I called
>menu->EnableMenuItem(0, MF_GRAYED | MF_BYPOSITION);
>
>The result was exactly nothing.
I think a little explanation is required here. Jim is of course right,
you need to use the UPDATE_COMMAND_UI mechanism. The issue is that
your call to EnableMenuItem _IS_ working, but as soon as MFC processes
the WM_INITPOPUPMENU message, its default behaviour is to enable any
menu item which has a handler, so all your good work is undone. You
need to go with the flow and use the MFC command ui updating
mechanism.
Oh, and DrawMenuBar only affects bar menus, hence the name.
--
Bob Moore [MVP]
http://www.mooremvp.freeserve.co.uk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Due to an unreasonable amount of queries, I no
longer answer unsolicited email questions. Sorry,
no exceptions.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bye
Gerhard