OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Changing menu item text

You use the SetText function to specify the text of a menu item.

To change the text of a menu item,

  1. Add the command-enabling handler function and response table macro to your window class (as shown in Handling command-enablingmessages)." -# Define the handler function. -# In the handler function, call the TCommandEnabler::SetText() member function of the command-enabling object passed into the handler function. SetText takes a single parameter, a const far char*, and returns void. The character array parameter should contain the new text for the menu item. \note If you are setting the text for a menu item and turning on a check mark for that menu item in the same function, you must call SetText before you call TCommandEnabler::SetCheck(). Reversing this order removes the check mark. Suppose your application supports three different file formats: text, binary, and encrypted, and you want the File|Save menu item to reflect the format of the file being saved. Here is the sample class from \ref handlingcommandenablingmessages "Handling Command-Enabling Messages", modified with an enum type, TFormat, and a TFormat data member called Format: @code class TMyFrame : public TFrameWindow { public: TMyFrame(TWindow *parent = 0, char *title = 0); enum TFormat {Text, Binary, Encrypted}; protected: TFormat Format; void CmFileSave(); // This is the command-enabling handler function. void CeFileSave(TCommandEnabler& commandEnabler); DECLARE_RESPONSE_TABLE(TMyFrame); }; DEFINE_RESPONSE_TABLE(TMyFrame) EV_COMMAND(CM_FILESAVE, CmFileSave), EV_COMMAND_ENABLE(CM_FILESAVE, CeFileSave), END_RESPONSE_TABLE; void TMyFrame::CeFileSave(TCommandEnabler& ce) { switch(Format) { case Text: ce.SetText("Save as text file"); break; case Binary: ce.SetText("Save as binary file"); break; case Encrypted: ce.SetText("Save as encrypted file"); break; default: ce.SetText("Save"); } } \endcode @section seealso See Also - \ref enablinganddisablingcommanditems "Enabling and disabling command items" - \ref handlingcommandenablingmessages "Handling command-enabling messages" - \ref togglingcommanditems "Toggling command items"