May 08, 2024, 01:37:57 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


EnableMenuItem question

Started by Bruce Peaslee, May 28, 2006, 10:21:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

May 28, 2006, 10:21:05 AM Last Edit: May 28, 2006, 10:41:51 AM by peaslee
When I open a file, I want to gray our the File|Open menu item so the user cannot select it again by accident. I declare a menu member variable in my window class and the menu operates just fine. But this doesn't work:


MainWindow::OpenFile(), void
{
string sFileName = "";

sFileName = FileRequest("Select Database",this,true,"(*.mdb)|*.mdb","",0,GetStartPath());
if (sFileName <> "")
{
menu.EnableMenuItem(FILE_OPEN, AMF_GRAYED);

}
}


EDIT:

Never mind. I found the answer by reading posts in the forumÂÃ,  :P


MainWindow::OpenFile(), void
{
string sFileName = "";

sFileName = FileRequest("Select Database",this,true,"(*.mdb)|*.mdb","",0,GetStartPath());
if (sFileName <> "")
{
menu.Attach(hmenu);
menu.EnableMenuItem(FILE_OPEN, 0);
menu.Detach();

}
}
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

If you created the menu and attached it to the window using win.SetMenu(menu.Detach()) then you'll need to reattach it temporarily to make modifications.  It is not necessary to keep a CMenu varaible around anyway.  Also EnableMenuItem is a true/false thing.

The easiest way to do this is in response to the OnMenuInit message. 

MainWindow::OnMenuInit(unsigned int hMenu),int
{
       CMenu m;
        m.Attach(hMenu);
        m.EnableMenuItem(FILE_OPEN, m_sFileName == "");
        m.Detach();
}

But that is if you want to keep it disabled until the file is closed, assuming you have a string member of m_sFileName of course.  If you just want to disable it while processing a long file then you can do:

menu.Attach(GetMenu());
menu.EnableMenuItem(FILE_OPEN, FALSE);
menu.Detach();

Ionic Wind Support Team

Bruce Peaslee

I eventually figured out the true/false thingÂÃ,  :D

The first way is much cleaner. It also is good to note the GetMenu() method in the second example.

Thanks a lot.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles