PRODUCT : Borland C++ NUMBER : 1746 VERSION : 4.0 OS : WIN DATE : December 8, 1993 PAGE : 1/8 TITLE : Shrinktoclient parameter in OWL II // How does the Client Frame architecture of OWL 2.0 work? What // affect does the shrinktoclient parameter of the TFrameWindow // constructor have when trying to size the main window for an // application? // Basically shrinktoclient controls whether the client window // will size to its frame(TFrameWindow) or the frame window // will size to the client. The shrinktoclient parameter of // TFrameWindow will only affect the size of main window. In // order to control the location of the main window the OWL // code MUST adjust the location of the main window at the // scope of the TFrameWindow or TFrameWindow derived class. // This is done by using the TFrameWindow data member Attr.X, // and Attr.Y. // The following code shows how the location and size of // an OWL 2.0 main window can be set using shrinktoclient // set to TRUE and set to FALSE. // When compiling with _SHRINKTOCLIENT_ defined the size // specified in the derived TWindow(client) window will // be used for the to size the derived TFrameWindow(frame // window). // When compiling with _SHINKTOCLIENT_ not defined the // size specified in the TFrameWindow window will be used // to size the client window. // For a demonstration of using a derived TFrameWindow with // shrinktoclient TRUE compile the following code with // this command-line: /* BCC -WE -ml -D_SHRINKTOCLIENT_ position.cpp owlwl.lib bidsl.lib */ // For a demonstration of using a derived TFrameWindow with // shrinktoclient FALSE compile the following code with // this command-line: /* BCC -WE -ml position.cpp owlwl.lib bidsl.lib */ // NOTE: Provide a definition file with STACKSIZE 8192. PRODUCT : Borland C++ NUMBER : 1746 VERSION : 4.0 OS : WIN DATE : December 8, 1993 PAGE : 2/8 TITLE : Shrinktoclient parameter in OWL II // // Owl // #include #include #include #include #include // // Run-Time Library // #include // // Warning control // #pragma option -w-par #define APPLICATION_NAME "POSITION" #ifdef _SHRINKTOCLIENT_ #define SHRINKTOCLIENT TRUE #else #define SHRINKTOCLIENT FALSE #endif // // Derived Client Window // class TDerivedWindow : public TWindow { public: TDerivedWindow(TWindow *parent); void EvSize(UINT sizeType, TSize &size); DECLARE_RESPONSE_TABLE(TDerivedWindow); }; DEFINE_RESPONSE_TABLE1(TDerivedWindow, TWindow) EV_WM_SIZE, END_RESPONSE_TABLE; PRODUCT : Borland C++ NUMBER : 1746 VERSION : 4.0 OS : WIN DATE : December 8, 1993 PAGE : 3/8 TITLE : Shrinktoclient parameter in OWL II // // Contructor // Derived Client Window // TDerivedWindow::TDerivedWindow(TWindow *parent) : TWindow(parent) { // // These sizes will be used for the MainWindow provided // the TFrameWindow option shrinktoclient is true. When // a client window is used in a frame window that does not // have the shrinktoclient flag set, the client window will // resize to the frame window. When a client window is used // in a frame window that has the shrinktoclient flag set // the frame window will shrink to the client windows size // #ifdef _SHRINKTOCLIENT_ Attr.W = 300; Attr.H = 150; #endif } // // Size method of the derived TWindow // void TDerivedWindow::EvSize(UINT sizeType, TSize &size) { char OutputBuffer[256]; TRect FrameRect; TEXTMETRIC tm; // Get the frame windows rectangle Parent->GetWindowRect(FrameRect); // Get the client windows rectangle(client rectangle) TRect ClientRect = GetClientRect(); TWindowDC wdc(HWindow); // Get hieght of text character wdc.GetTextMetrics(tm); PRODUCT : Borland C++ NUMBER : 1746 VERSION : 4.0 OS : WIN DATE : December 8, 1993 PAGE : 4/8 TITLE : Shrinktoclient parameter in OWL II // Set the background color to the window background color wdc.SetBkColor(TColor(GetSysColor(COLOR_WINDOW))); sprintf(OutputBuffer, "FRAME @ X:[%+03d] Y:[%+03d]", FrameRect.left, FrameRect.top); // Write text out. wdc.ExtTextOut(0,0, ETO_CLIPPED | ETO_OPAQUE, &ClientRect, OutputBuffer, strlen(OutputBuffer)); sprintf(OutputBuffer, "CLIENT SIZE W:[%+03d] H:[%+03d]", ClientRect.right - ClientRect.left, ClientRect.bottom - ClientRect.top); // Adjust the clipping rectangle to be next line ClientRect.top += tm.tmHeight; // Write text out wdc.ExtTextOut(0,ClientRect.top, ETO_CLIPPED | ETO_OPAQUE, &ClientRect, OutputBuffer, strlen(OutputBuffer) ); sprintf(OutputBuffer, "FRAME SIZE W:[%+03d] H:[%+03d]", FrameRect.right - FrameRect.left, FrameRect.bottom - FrameRect.top); // Adjust the clipping rectangle to be next line ClientRect.top += tm.tmHeight; // Write text out. wdc.ExtTextOut(0,ClientRect.top, ETO_CLIPPED | ETO_OPAQUE, &ClientRect, OutputBuffer, strlen(OutputBuffer) ); } PRODUCT : Borland C++ NUMBER : 1746 VERSION : 4.0 OS : WIN DATE : December 8, 1993 PAGE : 5/8 TITLE : Shrinktoclient parameter in OWL II // // Derived Frame Window // class TDerivedFrameWindow : public TFrameWindow { public: TDerivedFrameWindow(TWindow *parent, char *title, TWindow *client); void EvMove(TPoint &org); DECLARE_RESPONSE_TABLE(TDerivedFrameWindow); }; DEFINE_RESPONSE_TABLE1(TDerivedFrameWindow, TFrameWindow) EV_WM_MOVE, END_RESPONSE_TABLE; // // Constructor // Derived Frame Window TDerivedFrameWindow::TDerivedFrameWindow(TWindow *parent, char *title, TWindow *client) : TFrameWindow(parent, title, client, SHRINKTOCLIENT) { #ifndef _SHRINKTOCLIENT_ // These width and height values will Attr.H = 100; // be used for the main window width Attr.W = 450; // and height only when the frame #endif // windows shrinktoclient flag // is not set. This will cause // the client to size to the frame. // // The location of the main window must be set/controlled // at the scope of the Frame Window. These assignments // will position the main window in the upper left hand // corner of the windows desktop. // PRODUCT : Borland C++ NUMBER : 1746 VERSION : 4.0 OS : WIN DATE : December 8, 1993 PAGE : 6/8 TITLE : Shrinktoclient parameter in OWL II #ifdef _SHRINKTOCLIENT_ Attr.X = 0; Attr.Y = 0; #else Attr.X = 20; Attr.Y = 20; #endif } // // Move method of the derived TFrameWindow // void TDerivedFrameWindow::EvMove(TPoint &org) { char OutputBuffer[256]; TRect FrameRect; TRect ClientRect; TEXTMETRIC tm; // Get the frame window rectangle GetWindowRect(FrameRect); // Get the client window rectangle(client rectangle) GetClientWindow()->GetClientRect(ClientRect); // Create a hdc from the client window handle TWindowDC wdc(GetClientWindow()->HWindow); // Get the text height wdc.GetTextMetrics(tm); // Set the background color to the window background color wdc.SetBkColor(TColor(GetSysColor(COLOR_WINDOW) ) ); sprintf(OutputBuffer, "FRAME @ X:[%+03d] Y:[%+03d]", FrameRect.left, FrameRect.top); wdc.ExtTextOut(0,0, ETO_CLIPPED | ETO_OPAQUE, &ClientRect, OutputBuffer, strlen(OutputBuffer) ); sprintf(OutputBuffer, PRODUCT : Borland C++ NUMBER : 1746 VERSION : 4.0 OS : WIN DATE : December 8, 1993 PAGE : 7/8 TITLE : Shrinktoclient parameter in OWL II "CLIENT SIZE W:[%+03d] H:[%+03d]", ClientRect.right - ClientRect.left, ClientRect.bottom - ClientRect.top); // Adjust the clipping rectangle to be next line ClientRect.top += tm.tmHeight; // Write the text out wdc.ExtTextOut(0,ClientRect.top, ETO_CLIPPED | ETO_OPAQUE, &ClientRect, OutputBuffer, strlen(OutputBuffer) ); sprintf(OutputBuffer, "FRAME SIZE W:[%+03d] H:[%+03d]", FrameRect.right - FrameRect.left, FrameRect.bottom - FrameRect.top); // Adjust the clipping rectangle to be next line ClientRect.top += tm.tmHeight; // Write the text out wdc.ExtTextOut(0,ClientRect.top, ETO_CLIPPED | ETO_OPAQUE, &ClientRect, OutputBuffer, strlen(OutputBuffer) ); } // // Derived Application Class // class TPosition : public TApplication { private: public: // Default constructor TPosition(void); // Create Main Window void InitMainWindow(void); }; PRODUCT : Borland C++ NUMBER : 1746 VERSION : 4.0 OS : WIN DATE : December 8, 1993 PAGE : 8/8 TITLE : Shrinktoclient parameter in OWL II // // Constructor // Derived Application Class // TPosition::TPosition(void) : TApplication(APPLICATION_NAME) { } // // Intialize Application Main Window // void TPosition::InitMainWindow(void) { TWindow *ClientWindowPtr; TFrameWindow *FrameWindowPtr; // Create client area. ClientWindowPtr = new TDerivedWindow(NULL); // Create frame window using client. FrameWindowPtr = new TDerivedFrameWindow(NULL, "Sample Main Window", ClientWindowPtr); // Assign main window MainWindow = FrameWindowPtr; } // // Owl Main // int OwlMain(int /* argc */, char *[]) { TPosition Application; return Application.Run(); } DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.