OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Step 6: Setting up the client window

An ObjectWindows SDI application can use a frame window that does not contain a client window.

Similarly, an ObjectWindows MDI application can use MDI child windows that do not contain a client window. Omitting the client window makes it harder to convert the application from one kind of frame to another-SDI, MDI, or decorated frame. It is also awkward when building OLE 2 applications.

For example, it is easier for a container's main window to make room for a server's tool bar if the container owns a client window. To take full advantage of the ObjectWindows OLE classes, your application must use a client window. For more information about using client windows, see the ObjectWindows Tutorial.

The following topics discuss setting up the Client Window.

  • Inheriting from OLE Classes
  • Delaying the Creation of the Client Window in SDI Applications
  • Creating ObjectComponents View and Document Objects

Inheriting from OLE Classes

ObjectWindows provide several classes that include default implementations for many OLE operations. To adapt an existing ObjectWindows program to OLE, change its derived classes to inherit from the OLE classes.

The TOleFrame and TOleMDIFrame classes both derive from decorated window classes. The OLE 2 user interface requires that containers be prepared to handle tool bars and status bars. Even if a container has no such decorations, servers might need to display their own in the container's window. The OLE window classes handle those negotiations for you. The following code shows how to change the declaration for a client window. Boldface type highlights the changes.

Before:

// Pre-OLE declaration of a client window
class TScribbleWindow : public TWindow {
// declarations
};
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492

After changing the declaration to derive from an OLE-enabled class:

// New declaration of the same window class
class TScribbleWindow : public TOleWindow
{
// declarations
};

Delaying the Creation of the Client Window in SDI Applications

ObjectWindows applications create their main window in the InitMainWindow method of the TApplication-derived class. Typically, SDI applications also create their initial client window in the InitMainWindow function. The following code shows the typical sequence.

void
TDrawApp::InitMainWindow()
{
// Construct the decorated frame window
TDecoratedFrame* frame = new TDecoratedFrame(0, "Drawing Pad",
new TDrawWindow(0), true);
// more declarations to init and set the main window
}

When used in the OLE frame and client classes, however, that sequence presents a timing problem for OLE. The OLE client window must be created after the OLE frame has initialized its variables pointing to ObjectComponents classes. To meet this requirement, an SDI OLE application should create only the frame window in the InitMainWindow function. Create the client window in the InitInstance method of your application class. Boldface type highlights the changes.

void
TDrawApp::InitMainWindow()
{
// construct the decorated frame window
TOleFrame* frame = new TOleFrame("Drawing Pad", 0, true);
// more declarations to init and set the main window
}
void
TDrawApp::InitInstance()
{
TApplication::InitInstance();
// create and set client window
GetMainWindow()->SetClientWindow(new TDrawWindow(0));
}

Creating ObjectComponents View and Document Objects

For every client window capable of having linked or embedded objects, you must create a TOcDocument object to manage the embedded OLE objects, and a OCF.HLPTOcView" object to manage the presentation of the OLE objects. The CreateOcView method from the TOleWindow class creates both the container document and the container view. Add a call to CreateOcView in the constructor of your TOleWindow-derived class.

// Pre-OLE declaration of a client window constructor
TScribbleWindow::TScribbleWindow(TWindow* parent, char far* filename)
: TWindow(parent, 0, 0)
{
}
// New declaration of client window constructor
TScribbleWindow::TScribbleWindow(TWindow* parent, char far* filename)
: TOleWindow(parent, 0)
{
// Create TOcDocument object to hold OLE parts
// and TOcView object to provide OLE services.
CreateOcView(0, false, 0);
}

Notice that unlike the TWindow constructor, the TOleWindow constructor does not require a title parameter. It is unnecessary because TOleWindow is always the client of a frame. TWindow, on the other hand, can be used as a non-client window-a pop-up, for example.