Messages From ListBoxes

Introduction

One of the frequently used shortcuts associted with listboxes is the left button double click. If your listbox is contained in a dialog, that normally handles the operation even thought the double click occurs in the listbox. OWL disables any of the messages other than the TListBox messages, so your message will never get to the dialog box. The only way to add this type of message is to create your own Listbox class with the messages you want activated.

Implementation of a New ListBox Class

First use class expert to create a new Listbox class. This process is the same as that used to create a new dialog class.The main difference is that you select TListbox as your base class and you don't associated the class with an ID. Class expert creates a skeleton class with one constructor.

//{{TListBox = MListBox}}
class MListBox : public TListBox {
public:
    MListBox (TWindow* parent, int id, int x, int y, int w, int h, TModule* module = 0);
    virtual ~MListBox ();

};    //{{MListBox}}

You must add the following constructor which is frequently used by dialog boxes.

    MListBox (TWindow* parent, int id,TModule* module = 0);

This constructor can be created by simply copying the given constructor, deleting the four ints following id from the signature line and the call to the TListBox constructor.

MListBox::MListBox (TWindow* parent, int id, TModule* module):
    TListBox(parent, id, module)
{
    // INSERT>> Your constructor code here.

}

Add Handlers

To add a message handler from the list of windows messages first find the message. In this case left button double clicked is a basic windows message. Next use the right button menu to add a handler.

Once Class Expert has created the handler, you simply pass the message to the dialog box which is the list boxes parent.

void MListBox::EvLButtonDblClk (uint modKeys, TPoint& point)
{
    TListBox::EvLButtonDblClk(modKeys, point);

    // INSERT>> Your code here.
   Parent->SendMessage(WM_LBUTTONDBLCLK);
}

Add Message Handler to Parent

Once you have created a listbox with right button (or any other message) enabled, you must handle the message being sent by the list box. In this case we first replace the constructor call to TListBox in our dialog constructor with a call to the constructor for MListBox.

MagValList::MagValList (const OrderedMList &l,MagValListXfer *tb,TWindow* parent, TResId resId, TModule* module):
    TDialog(parent, resId, module),_mess(l)
{
//{{MagValListXFER_USE}}
    _mList = new MListBox(this, IDC_MLIST);

    SetTransferBuffer(tb);
//{{MagValListXFER_USE_END}}

    // INSERT>> Your constructor code here.

}

Next create the same handler for the dialog box that you did for the list box using Class Expert ( as above ). Then add your code to the handler.