home *** CD-ROM | disk | FTP | other *** search
- #include <owl\applicat.h>
- #include <owl\dc.h>
- #include <owl\framewin.h>
- #include <owl\scroller.h>
- #include <owl\window.h>
- #include <owl\window.rh>
- #include <stdio.h>
-
- #include "window2.h"
-
- const MAX_LINES = 30;
-
- class TMyWindow : public TWindow
- {
- public:
- TMyWindow(TWindow *parent = 0);
- ~TMyWindow();
-
- protected:
- virtual void SetupWindow();
-
- BOOL CanClose();
-
- void CmExit();
- void CmHeight8();
- void CmHeight10();
- void CmHeight14();
- void CmHeight20();
- void CmHeight26();
- void EvKeyDown(UINT, UINT, UINT);
- void EvLButtonDown(UINT, TPoint &);
-
- void Paint(TDC &, BOOL, TRect &);
-
- private:
- TFont *pFont;
-
- void NewFont(int);
-
- DECLARE_RESPONSE_TABLE(TMyWindow);
- };
- DEFINE_RESPONSE_TABLE1(TMyWindow, TWindow)
- EV_WM_KEYDOWN,
- EV_WM_LBUTTONDOWN,
- EV_COMMAND(CM_EXIT, CmExit),
- EV_COMMAND(CM_HEIGHT8, CmHeight8),
- EV_COMMAND(CM_HEIGHT10, CmHeight10),
- EV_COMMAND(CM_HEIGHT14, CmHeight14),
- EV_COMMAND(CM_HEIGHT20, CmHeight20),
- EV_COMMAND(CM_HEIGHT26, CmHeight26),
- END_RESPONSE_TABLE;
-
- class TMyApp : public TApplication
- {
- public:
- TMyApp() : TApplication() {}
-
- void InitMainWindow()
- {
- SetMainWindow(new TFrameWindow( 0,
- "A Simple Read-Only Text Window",
- new TMyWindow ));
- GetMainWindow()->AssignMenu("EXITMENU");
- }
- };
-
- TMyWindow::TMyWindow(TWindow *parent)
- {
- Init(parent, 0, 0);
- Attr.Style |= WS_VSCROLL | WS_HSCROLL; // Add scroll bars
- pFont = NULL;
- }
-
- TMyWindow::~TMyWindow()
- {
- if (pFont)
- delete pFont;
- }
-
- void TMyWindow::SetupWindow()
- {
- TWindow::SetupWindow();
-
- // Set up the scroller and font. Note that
- // dummy values of 7 and 16 are used for the
- // scroll bar's units, but they'll be reset
- // as soon as the font is set.
- //
- Scroller = new TScroller(this, 7, 16, 20, MAX_LINES - 1);
- NewFont(8); // Initialize our font
- }
-
- BOOL TMyWindow::CanClose()
- {
- return IDYES == MessageBox("Want to close this application?",
- "Query",
- MB_YESNO | MB_ICONQUESTION );
- }
-
- void TMyWindow::CmExit()
- {
- SendMessage(WM_CLOSE);
- }
-
- void TMyWindow::CmHeight8()
- {
- NewFont(8);
- }
-
- void TMyWindow::CmHeight10()
- {
- NewFont(10);
- }
-
- void TMyWindow::CmHeight14()
- {
- NewFont(14);
- }
-
- void TMyWindow::CmHeight20()
- {
- NewFont(20);
- }
-
- void TMyWindow::CmHeight26()
- {
- NewFont(26);
- }
-
- void TMyWindow::EvKeyDown( UINT key,
- UINT /*repeatCount*/,
- UINT /*flags*/ )
- {
- if (Scroller) // Can't scroll if it ain't there!
- switch (key)
- {
- case VK_HOME:
- Scroller->VScroll(SB_TOP, 0);
- break;
- case VK_END:
- Scroller->VScroll(SB_BOTTOM, 0);
- break;
- case VK_PRIOR:
- Scroller->VScroll(SB_PAGEUP, 0);
- break;
- case VK_NEXT:
- Scroller->VScroll(SB_PAGEDOWN, 0);
- break;
- case VK_UP:
- Scroller->VScroll(SB_LINEUP, 0);
- break;
- case VK_DOWN:
- Scroller->VScroll(SB_LINEDOWN, 0);
- break;
- }
- }
-
- void TMyWindow::EvLButtonDown(UINT, TPoint &)
- {
- MessageBox( "You clicked the left button!",
- "Mouse Click Event",
- MB_OK );
- }
-
- void TMyWindow::Paint(TDC &dc, BOOL /*erase*/, TRect &/*rect*/)
- {
- char s[81];
- BOOL ok = TRUE;
- int y = 0;
-
- for (int i = 0; i < MAX_LINES && ok; ++i)
- {
- if (pFont)
- dc.SelectObject(*pFont);
- sprintf(s, "This is line number %d", i);
- ok = dc.TextOut(0, y, s);
- y += dc.GetTextExtent(s, lstrlen(s)).cy;
- if (pFont)
- dc.RestoreFont();
- }
- }
-
- void TMyWindow::NewFont(int nHeight)
- {
- if (pFont)
- delete pFont;
- pFont = new TFont("Arial", nHeight);
-
- // Now reset the the scroller's units
- if (pFont && Scroller)
- {
- TClientDC dc(*this);
- TEXTMETRIC tm;
-
- dc.SelectObject(*pFont);
- dc.GetTextMetrics(tm);
- dc.RestoreFont();
-
- Scroller->SetUnits( tm.tmAveCharWidth,
- tm.tmHeight + tm.tmExternalLeading );
-
- Invalidate();
- }
- }
-
- int OwlMain(int, char *[])
- {
- return TMyApp().Run();
- }
-