Главная страница | назад





Article #15148: Disable toolbar buttons with Command Enablers

 Question and Answer Database
FAQ148C.txt Disable toolbar buttons with Command Enablers
Category :OWL
Platform :All
Product :BC++ 5.x
Question:
Is it possible to use OWL command enabling to disable toolbar
buttons?
Answer:
You can use the same CommandEnabler function for menus and
buttongadgets. You are being passed both TButtonGadgetEnabler
references and TMenuItemEnabler references, and your call to
Enabler.Enable( false )will work on both. If for some reason
you have to distinguish between the two then you could use
dynamic_cast and conditionally disable only the tool bar button
or the menu item.
The following disables only the controlbar button, not the menu
item for a particular command:
void MyClient::CeFileNew(TCommandEnabler &tce )
{
try
{
// from a toolbar button?
dynamic_cast< TButtonGadgetEnabler&>( tce );
}
catch( Bad_cast& b )
{
// not for a toolbar, do nothing
return;
}
// disable if it is for a toolbar button
tce.Enable( false );
}
Bad_cast is thrown when a cast of a reference type fails.
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99