home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / window1.cpp < prev    next >
C/C++ Source or Header  |  1994-05-26  |  2KB  |  86 lines

  1. #include <owl\applicat.h>
  2. #include <owl\dc.h>
  3. #include <owl\framewin.h>
  4. #include <owl\window.h>
  5. #include <owl\window.rh>
  6. #include <stdio.h>
  7.  
  8. const MAX_LINES = 30;
  9.  
  10. class TMyWindow : public TWindow
  11. {
  12. public:
  13.    TMyWindow(TWindow *parent = 0);
  14.  
  15. protected:
  16.    BOOL CanClose();
  17.  
  18.    void CmExit();
  19.    void EvLButtonDown(UINT, TPoint &);
  20.  
  21.    void Paint(TDC &, BOOL, TRect &);
  22.  
  23.    DECLARE_RESPONSE_TABLE(TMyWindow);
  24. };
  25. DEFINE_RESPONSE_TABLE1(TMyWindow, TWindow)
  26.    EV_WM_LBUTTONDOWN,
  27.    EV_COMMAND(CM_EXIT, CmExit),
  28. END_RESPONSE_TABLE;
  29.  
  30. class TMyApp : public TApplication
  31. {
  32. public:
  33.    TMyApp() : TApplication() {}
  34.  
  35.    void InitMainWindow()
  36.       {
  37.       SetMainWindow(new TFrameWindow(  0,
  38.                            "A Simple Read-Only Text Window",
  39.                            new TMyWindow ));
  40.       GetMainWindow()->AssignMenu("EXITMENU");
  41.       }
  42. };
  43.  
  44. TMyWindow::TMyWindow(TWindow *parent)
  45. {
  46.    Init(parent, 0, 0);
  47. }
  48.  
  49. BOOL TMyWindow::CanClose()
  50. {
  51.    return IDYES == MessageBox("Want to close this application?",
  52.                               "Query",
  53.                               MB_YESNO | MB_ICONQUESTION );
  54. }
  55.  
  56. void TMyWindow::CmExit()
  57. {
  58.    SendMessage(WM_CLOSE);
  59. }
  60.  
  61. void TMyWindow::EvLButtonDown(UINT, TPoint &)
  62. {
  63.    MessageBox( "You clicked the left button!",
  64.                "Mouse Click Event",
  65.                MB_OK );
  66. }
  67.  
  68. void TMyWindow::Paint(TDC &dc, BOOL /*erase*/, TRect &/*rect*/)
  69. {
  70.    char s[81];
  71.    BOOL ok = TRUE;
  72.    int y = 0;
  73.  
  74.    for (int i = 0; i < MAX_LINES && ok; ++i)
  75.       {
  76.       sprintf(s, "This is line number %d", i);
  77.       ok = dc.TextOut(0, y, s);
  78.       y += dc.GetTextExtent(s, lstrlen(s)).cy;
  79.       }
  80. }
  81.  
  82. int OwlMain(int, char *[])
  83. {
  84.    return TMyApp().Run();
  85. }
  86.