OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
About the Column Header Control

The TColumnHeader class creates a horizontal window that is used above columns of text or numbers, containing titles for each column.

The right panel of the Windows 95 Explorer, for example, uses this type of window for file name, size, and type. Column Header windows are generally used over a List Window window.

A header window contains parts called header items. The user can adjust the width of each item. Items can also behave like push buttons: clicking on the Size item in the Windows 95 Explorer, for example, sorts the files by size. Each item can have a string, a bit-mapped image, and a 32-bit application-defined value associated with it.

The native control for Windows 95 is the Header Window common control.

Creating a Column Header Control

To create a Column Header Control, simply create a TColumnHeader object within the constructor of the parent object specifying the parent and the id of the control. For example,

TMyWindow::TMyWindow() {
// ...
TColumnHeader* hdrCtl = new TColumnHeader(this, ID_XX);
}

When constructed within the constructor of the parent object, it is not necessary to invoke the Create method of the TColumnHeader object. The AutoCreate feature of ObjectWindows will ensure that the control is created once the parent object is created. However, if you are constructing the TColumnHeader object after its parent has been created, you will also need to invoke it's Create method.

Note
Although you can specify the screen coordinates of the control, these parameters are typically left out in favour of the Layout capabilities of the TColumnHeader object; as described in Sizing and Positioning a Column Header Control.

Adding items to a Column Header Control

Once the control has been created, you can add items using the Add or Insert methods of the TColumnHeader class.

The THdrItem class holds information about an item of a Column Header Control. To add/insert an item you must first construct a THdrItem instance. After initializing the THdrItem instance, you can invoke the Add or Insert method of the TColumnHeader object.

For example:

THdrItem item("&Name of Employee");
hdrCtl->Add(item);

Responding to Column Header Control Notification Messages

The Column Header Control sends notification messages to its parent window whenever the user manipulates the Column Header Control. For example, if the user clicks an item, the control sends a HDN_ITEMCLICK notification message. ObjectWindows provides several macros which can be used in the definition of a Message Response Table, allowing a member function to be invoked when particular notification messages are received by the parent. The following list shows the macros pertinent to the Column Header Control:

EV_HDN_BEGINTRACK(id, method) // User starts dragging divider
EV_HDN_DIVIDERDBLCLICK(id, method) // User double clicked divider
EV_HDN_ENDTRACK(id, method) // User ends drag operation
EV_HDN_ITEMCHANGED(id,method) // Attribute of an item changed
EV_HDN_ITEMCHANGING(id,method) // Attribute about to change
EV_HDN_ITEMCLICK(id, method) // User clicked on item
EV_HDN_TRACK(id, method) // User dragged a divider
#define EV_HDN_ENDTRACK(id, method)
void method(THdrNotify&)
Definition commctrl.h:1217
#define EV_HDN_BEGINTRACK(id, method)
bool method(THdrNotify&)
Definition commctrl.h:1202
#define EV_HDN_ITEMCHANGED(id, method)
void method(THdrNotify&)
Definition commctrl.h:1240
#define EV_HDN_ITEMCHANGING(id, method)
void method(THdrNotify&)
Definition commctrl.h:1245
#define EV_HDN_DIVIDERDBLCLICK(id, method)
void method(THdrNotify&)
Definition commctrl.h:1207
#define EV_HDN_TRACK(id, method)
bool method(THdrNotify&)
Definition commctrl.h:1260
#define EV_HDN_ITEMCLICK(id, method)
void method(THdrNotify&)
Definition commctrl.h:1250

Sizing and Positioning a Column Header Control

A Column Header Control is typically docked to the upper side of its parent's client area. The control provides an API which allows the control to specify a desired size and position within the boundary of a specified rectangle. The bool Layout(TRect& boundingRect, WINDOWPOS& winPos) method can be used to retrieve the appropriate size and position values in a WINDOWPOS structure. The overloaded bool Layout(uint swpFlags = 0) method provides an higher abstraction of this API: the desired size of the control is retrieved by specifying the client area of its parent as the bounding rectangle and the control is then repositioned accordingly. The swpFlags are used when the call SetWindowPos is used to reposition the control.