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).
  2. Define the handler function.
  3. 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 HandlingCommand-Enabling Messages, modified with an enum type, TFormat, and a TFormat data member called Format:
    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);
    };
    EV_COMMAND(CM_FILESAVE, CmFileSave),
    EV_COMMAND_ENABLE(CM_FILESAVE, CeFileSave),
    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");
    }
    }
    #define DECLARE_RESPONSE_TABLE(cls)
    Definition eventhan.h:436
    #define END_RESPONSE_TABLE
    Definition eventhan.h:466
    #define DEFINE_RESPONSE_TABLE(cls)
    Macro to define a response table for a class with no base response tables.
    Definition eventhan.h:479
    #define EV_COMMAND_ENABLE(id, method)
    Response table entry for enabling a command.
    Definition windowev.h:193
    #define EV_COMMAND(id, method)
    Response table entry for a menu/accelerator/push button message.
    Definition windowev.h:171

See Also