home *** CD-ROM | disk | FTP | other *** search
- /*
- Program to illustrate simple MDI windows
- */
- #include <owl\mdi.rh>
- #include <owl\applicat.h>
- #include <owl\framewin.h>
- #include <owl\mdi.h>
- #include <owl\static.h>
- #include <owl\edit.h>
- #include <owl\scroller.h>
- #include "mdi1.h"
- #include <stdio.h>
- #include <string.h>
-
- const MaxWords = 100;
- const WordsPerLine = 12;
- const NumWords = 10;
- char* Words[NumWords] = { "The ", "friend ", "saw ", "the ",
- "girl ", "drink ", "milk ", "boy ",
- "cake ", "bread " };
-
- BOOL ExpressClose = FALSE;
- int NumMDIChild = 0;
- int HighMDIindex = 0;
-
- class TWinApp : public TApplication
- {
- public:
- TWinApp() : TApplication() {}
-
- protected:
- virtual void InitMainWindow();
- };
-
- class TAppMDIChild : public TMDIChild
- {
- public:
- // pointer to the edit box control
- TEdit* TextBox;
- TStatic* TextTxt;
-
- TAppMDIChild(TMDIClient& parent, int ChildNum);
-
- protected:
-
- // handle closing the MDI child window
- virtual BOOL CanClose();
- };
-
- class TAppMDIClient : public TMDIClient
- {
- public:
-
- TAppMDIClient() : TMDIClient() {}
-
- protected:
-
- // create a new child
- virtual TMDIChild* InitChild();
-
- // close all MDI children
- virtual BOOL CloseChildren();
-
- // handle the command for counting the MDI children
- void CMCountChildren();
-
- // handle closing the MDI frame window
- virtual BOOL CanClose();
-
- // declare response table
- DECLARE_RESPONSE_TABLE(TAppMDIClient);
- };
-
- DEFINE_RESPONSE_TABLE1(TAppMDIClient, TMDIClient)
- EV_COMMAND(CM_COUNTCHILDREN, CMCountChildren),
- END_RESPONSE_TABLE;
-
- TAppMDIChild::TAppMDIChild(TMDIClient& parent, int ChildNum)
- : TMDIChild(parent),
- TFrameWindow(&parent),
- TWindow(&parent)
- {
- char s[1024];
-
- // set the scrollers in the window
- Attr.Style |= WS_VSCROLL | WS_HSCROLL;
- // create the TScroller instance
- Scroller = new TScroller(this, 200, 15, 10, 50);
-
- // set MDI child window title
- sprintf(s, "%s%i", "MDI Child #", ChildNum);
- Title = _fstrdup(s);
-
- // randomize the seed for the random-number generator
- randomize();
-
- // assign a null string to the variable s
- strcpy(s, "");
- // build the list of random words
- for (int i = 0; i < MaxWords; i++) {
- if (i > 0 && i % WordsPerLine == 0)
- strcat(s, "\r\n");
- strcat(s, Words[random(NumWords)]);
- }
- // create a static text object in the child window if the
- // ChildNum variable stores an odd number. Otherwise,
- // create an edit box control
- if (ChildNum % 2 == 0) {
- // create the edit box
- TextBox = new TEdit(this, ID_TEXT_EDIT, s,
- 10, 10, 300, 400, 0, TRUE);
- // remove borders and scroll bars
- TextBox->Attr.Style &= ~WS_BORDER;
- TextBox->Attr.Style &= ~WS_VSCROLL;
- TextBox->Attr.Style &= ~WS_HSCROLL;
- }
- else
- // create static text
- TextTxt = new TStatic(this, -1, s, 10, 10, 300, 400, strlen(s));
- }
-
- BOOL TAppMDIChild::CanClose()
- {
- // return TRUE if the ExpressClose member of the
- // parent MDI frame window is TRUE
- if (ExpressClose == TRUE) {
- NumMDIChild--;
- return TRUE;
- }
- else
- // prompt the user and return the prompt result
- if (MessageBox("Close this MDI window?",
- "Query", MB_YESNO | MB_ICONQUESTION) == IDYES) {
- NumMDIChild--;
- return TRUE;
- }
- else
- return FALSE;
- }
-
- TMDIChild* TAppMDIClient::InitChild()
- {
- ++NumMDIChild;
- return new TAppMDIChild(*this, ++HighMDIindex);
- }
-
- BOOL TAppMDIClient::CloseChildren()
- {
- BOOL result;
- // set the ExpressClose flag
- ExpressClose = TRUE;
- // invoke the parent class CloseChildren() member function
- result = TMDIClient::CloseChildren();
- // clear the ExpressClose flag
- ExpressClose = FALSE;
- NumMDIChild = 0;
- HighMDIindex = 0;
- return result;
- }
-
- // display a message box that shows the number of children
- void TAppMDIClient::CMCountChildren()
- {
- char msgStr[81];
-
- sprintf(msgStr, "There are %i MDI child windows", NumMDIChild);
- MessageBox(msgStr, "Information", MB_OK | MB_ICONINFORMATION);
- }
-
- BOOL TAppMDIClient::CanClose()
- {
- return MessageBox("Close this application?",
- "Query", MB_YESNO | MB_ICONQUESTION) == IDYES;
- }
-
- void TWinApp::InitMainWindow()
- {
- MainWindow = new TMDIFrame("Simple MDI Text Viewer",
- TResId(IDM_COMMANDS),
- *new TAppMDIClient);
- }
-
- int OwlMain(int /* argc */, char** /*argv[] */)
- {
- TWinApp app;
- return app.Run();
- }
-
-