OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
When Is a Window Handle Valid?

Normally under Windows, a newly created interface element receives a WM_CREATE message from Windows, and responds to it by initializing itself.

ObjectWindows interface objects intercept the WM_CREATE message and call SetupWindow instead. SetupWindow is where you want to perform your own initialization.

If part of the interface object's initialization requires the interface element's window handle, you must perform that initialization after you call the base class's SetupWindow (for example, TFrameWindow::SetupWindow()) . Prior to the time you call the base class's SetupWindow, the window and its child windows have not been created, so HWindow is not valid and should not be used. You can easily test the validity of HWindow: if it has not been initialized, it is set to NULL. This example shows a typical call to SetupWindow:

class TMyWindow : public TFrameWindow
{
public:
TMyWindow(const char far* name) : TFrameWindow(name) {}
void SetupWindow();
};
void
TMyWindow::SetupWindow()
{
TFrameWindow::SetupWindow();
.
.
.
}

Although it might seem odd that you cannot perform all initialization in the interface object's constructor, there is a good reason: after an interface element is created, you cannot change many of its characteristics. Therefore, a two-stage initialization is required: before and after the interface element is created.

The interface object's constructor is the place for initialization before the element is created, and SetupWindow is the place for initialization after the element is created. You can think of SetupWindow as the second part of the constructor.

See Also