IonicWind Software

Aurora Compiler => GUI => Topic started by: Bruce Peaslee on May 28, 2006, 10:21:05 AM

Title: EnableMenuItem question
Post by: Bruce Peaslee on May 28, 2006, 10:21:05 AM
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();

}
}
Title: Re: EnableMenuItem question
Post by: Ionic Wind Support Team on May 28, 2006, 10:44:48 AM
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();

Title: Re: EnableMenuItem question
Post by: Bruce Peaslee on May 28, 2006, 11:10:27 AM
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.