home *** CD-ROM | disk | FTP | other *** search
- /*
- Program to demonstrate MDI windows with controls
- */
- #include <owl\mdi.rh>
- #include <owl\applicat.h>
- #include <owl\framewin.h>
- #include <owl\button.h>
- #include <owl\edit.h>
- #include <owl\checkbox.h>
- #include <owl\scroller.h>
- #include <owl\mdi.h>
- #include "mdi2.h"
- #include <stdio.h>
- #include <string.h>
-
- // declare constants for sizing and spacing the controls
- // in the MDI child window
- const Wbtn = 50 * 3;
- const Hbtn = 30;
- const BtnHorzSpacing = 20;
- const BtnVertSpacing = 10;
- const Wchk = 200 * 3;
- const Hchk = 20;
- const ChkVertSpacing = 10;
- const Wbox = 400 * 3;
- const Hbox = 200 * 3;
-
- // declare the constants for the random text that appears
- // in the MDI child window
- const MaxWords = 200;
- const WordsPerLine = 10;
- const NumWords = 10;
- const BufferSize = 1024;
- char AppBuffer[BufferSize];
- 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:
-
-
- TAppMDIChild(TMDIClient& parent, int ChildNum);
-
- protected:
-
- TEdit* TextBox;
- TCheckBox* CanCloseChk;
-
- // handle the UpperCase button
- void HandleUpperCaseBtn()
- { CMUpperCase(); }
-
- // handle the LowerCase button
- void HandleLowerCaseBtn()
- { CMLowerCase(); }
-
- // handle clear the active MDI child
- void CMClear()
- { TextBox->Clear(); }
-
- // handle converting the text of the active
- // MDI child to uppercase
- void CMUpperCase();
-
- // handle converting the text of the active
- // MDI child to lowercase
- void CMLowerCase();
-
- // handle resetting the text of the active MDI child
- void CMReset();
-
- // reset the text in an MDI child window
- void InitText();
-
- // handle closing the MDI child window
- virtual BOOL CanClose();
-
- // declare response table
- DECLARE_RESPONSE_TABLE(TAppMDIChild);
- };
-
- DEFINE_RESPONSE_TABLE1(TAppMDIChild, TMDIChild)
- EV_COMMAND(ID_UPPERCASE_BTN, HandleUpperCaseBtn),
- EV_COMMAND(ID_LOWERCASE_BTN, HandleLowerCaseBtn),
- EV_COMMAND(CM_CLEAR, CMClear),
- EV_COMMAND(CM_UPPERCASE, CMUpperCase),
- EV_COMMAND(CM_LOWERCASE, CMLowerCase),
- EV_COMMAND(CM_RESET, CMReset),
- END_RESPONSE_TABLE;
-
- 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[41];
- int x0 = 10;
- int y0 = 10;
- int x = x0;
- int y = y0;
-
- // 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", "Child #", ChildNum);
- Title = _fstrdup(s);
-
- // create the push button controls
- new TButton(this, ID_UPPERCASE_BTN, "->UpperCase",
- x, y, Wbtn, Hbtn, TRUE);
- x += Wbtn + BtnHorzSpacing;
- new TButton(this, ID_LOWERCASE_BTN, "->LowerCase",
- x, y, Wbtn, Hbtn, FALSE);
-
- x = x0;
- y += Hbtn + BtnVertSpacing;
- CanCloseChk = new TCheckBox(this, ID_CANCLOSE_CHK, "Can Close",
- x, y, Wchk, Hchk, NULL);
- y += Hchk + ChkVertSpacing;
- InitText();
- // create the edit box
- TextBox = new TEdit(this, ID_TEXT_EDIT, AppBuffer,
- x, y, Wbox, Hbox, 0, TRUE);
- // remove borders and scroll bars
- TextBox->Attr.Style &= ~WS_BORDER;
- TextBox->Attr.Style &= ~WS_VSCROLL;
- TextBox->Attr.Style &= ~WS_HSCROLL;
- }
-
- void TAppMDIChild::CMUpperCase()
- {
- TextBox->GetText(AppBuffer, BufferSize);
- strupr(AppBuffer);
- TextBox->SetText(AppBuffer);
- }
-
- void TAppMDIChild::CMLowerCase()
- {
- TextBox->GetText(AppBuffer, BufferSize);
- strlwr(AppBuffer);
- TextBox->SetText(AppBuffer);
- }
-
- void TAppMDIChild::CMReset()
- {
- InitText();
- TextBox->SetText(AppBuffer);
- }
-
- BOOL TAppMDIChild::CanClose()
- {
- // return TRUE if the ExpressClose member of the
- // parent MDI frame window is TRUE
- if (ExpressClose == TRUE) {
- NumMDIChild--;
- return TRUE;
- }
- else
- // do not close the MDi child window if the Can Close is not checked
- if (CanCloseChk->GetCheck() == BF_UNCHECKED)
- return FALSE;
- else {
- NumMDIChild--;
- return TRUE;
- }
- }
-
- void TAppMDIChild::InitText()
- {
- // randomize the seed for the random-number generator
- randomize();
-
- // assign a null string to the buffer
- AppBuffer[0] = '\0';
- // build the list of random words
- for (int i = 0;
- i < MaxWords && strlen(AppBuffer) <= (BufferSize - 10);
- i++) {
- if (i > 0 && i % WordsPerLine == 0)
- strcat(AppBuffer, "\r\n");
- strcat(AppBuffer, Words[random(NumWords)]);
- }
- }
-
- 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 children", 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 (version 2)",
- TResId(IDM_COMMANDS),
- *new TAppMDIClient);
- }
-
- int OwlMain(int /* argc */, char** /*argv[] */)
- {
- TWinApp app;
- return app.Run();
- }
-
-