OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Associating interface objects with controls

Because a dialog box is created from its resource, you do not use C++ code to specify what it looks like or the controls in it.

Although this use of the resource lets you create the dialog box visually, it makes it harder to manipulate the controls from your application. ObjectWindows overcomes this limitation by letting you associate (connect) controls in a dialog box with interface objects, allowing you to

  • Provide specialized responses to messages. For example, you might want an edit control that allows only digits to be entered, or you might want a button that changes styles when it is pressed.
  • Use member functions and data members to manipulate the control, which is easier and more object-oriented than using control messages.

Control objects

To associate a control object with a control element, you can define a pointer to a control object as a data member and construct a control object in the dialog box object's constructor. Control classes such as TButton have a constructor that takes a pointer to the parent window object and the control's resource identifier. In the following example, TTestDialog's constructor creates a TButton object from the resource ID_BUTTON:

TTestDialog::TTestDialog(TWindow* parent, const char* resID)
: TDialog(parent, resID), TWindow(parent)
{
new TButton(this, ID_BUTTON);
}

You can also define your own control class, derived from an existing control class (if you want to provide specialized behavior). In the following example, TBeepButton is a specialized TButton that overrides the default response to the BN_CLICKED notification code. A TBeepButton object is associated with the ID_BUTTON button resource.

class TBeepButton : public TButton
{
public:
TBeepButton(TWindow* parent, int resId):TButton(parent, resId) {}
void BNClicked(); // BN_CLICKED
};
void TBeepButton::BNClicked()
{
}
.
.
.
TBeepDialog::TBeepDialog(TWindow* parent, const char* name)
: TDialog(parent, name),
TWindow(parent)
{
}
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
#define END_RESPONSE_TABLE
Definition eventhan.h:466
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
#define EV_NOTIFY_AT_CHILD(notifyCode, method)
Response table entry for a child ID notification handled at the child.
Definition windowev.h:162

Unlike setting up a window object, which requires two steps (construction and creation), associating an interface object with an interface element requires only the construction step. This is because the interface element already exists: it is loaded from the dialog box resource. You just have to tell the constructor which control from the resource to use, using its resource identifier.

See Also