home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MESSAGE / TEST.CPP < prev    next >
C/C++ Source or Header  |  1996-01-01  |  4KB  |  190 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //   チュートリアル アプリケーション -- step04.cpp
  4. //----------------------------------------------------------------------------
  5. #include <owl\owlpch.h>
  6. #include <owl\applicat.h>
  7. #include <owl\framewin.h>
  8. #include <owl\dc.h>
  9. #include <stdio.h>
  10. #include <dos.h>
  11.  
  12. #include "message.h"
  13.  
  14. static    TMessageWindow    *MessageOut ;
  15. static    TFrameWindow    *MainW ;
  16.  
  17. class TMyWindow : public TWindow {
  18.   public:
  19.     TMyWindow(TWindow *parent = 0);
  20.  
  21.     int    shiftstat ;
  22.     int    line, col ;
  23.  
  24.   protected:
  25.     // TWindow のメンバー関数をオーバーライドする
  26.     // BOOL CanClose();
  27.  
  28.     // メッセージ応答関数
  29.     void EvLButtonDown(UINT, TPoint&);
  30.     void EvRButtonDown(UINT, TPoint&);
  31.     void EvMouseMove(UINT, TPoint&);
  32.     void EvLButtonUp(UINT, TPoint&);
  33.     void EvChar( UINT key, UINT count, UINT flags );
  34.     void EvKeyDown( UINT key, UINT count, UINT flags );
  35.     void EvKeyUp( UINT key, UINT count, UINT flags );
  36.  
  37.     DECLARE_RESPONSE_TABLE(TMyWindow);
  38. };
  39.  
  40. DEFINE_RESPONSE_TABLE1(TMyWindow, TWindow)
  41.   EV_WM_LBUTTONDOWN,
  42.   EV_WM_RBUTTONDOWN,
  43.   EV_WM_MOUSEMOVE,
  44.   EV_WM_LBUTTONUP,
  45.   EV_WM_CHAR,
  46.   EV_WM_KEYDOWN,
  47.   EV_WM_KEYUP,
  48.   EV_WM_DROPFILES,
  49. END_RESPONSE_TABLE;
  50.  
  51. TMyWindow::TMyWindow(TWindow *parent)
  52. {
  53.   Init(parent, 0, 0);
  54.   shiftstat = 0;
  55.   line = 0;
  56.   col = 0;
  57. }
  58.  
  59.  
  60. /*
  61. BOOL TMyWindow::CanClose()
  62. {
  63.   return MessageBox("保存しますか?", "内容が変更されています",
  64.                     MB_YESNO | MB_ICONQUESTION) == IDNO;
  65. }
  66. */
  67.  
  68.  
  69. void TMyWindow::EvChar( UINT key, UINT, UINT flags )
  70. {
  71.     TClientDC    dc(*this);
  72.     char    str[64] ;
  73.  
  74.     wsprintf( str, "C %X %X %d", key, flags, shiftstat );
  75.     dc.TextOut( col * 80, line * 16, str );
  76.     line++ ;
  77.     if ( line == 32 )
  78.     {
  79.         line = 0 ;
  80.         col ++ ;
  81.         if ( col == 8 )
  82.         {
  83.             col = 0 ;
  84.         }
  85.     }
  86.     if ( key == ' ' )
  87.         CanClose();
  88. }
  89.  
  90. void TMyWindow::EvKeyDown( UINT key, UINT count, UINT flags )
  91. {
  92.     // shift
  93.     if ( key == 0x10 )
  94.         shiftstat |= 1 ;
  95.     // ctrl
  96.     if ( key == 0x11 )
  97.         shiftstat |= 2 ;
  98.     // function key
  99.     *MessageOut << "key : " << (int)key << "\n" ;
  100. }
  101.  
  102. void TMyWindow::EvKeyUp( UINT key, UINT, UINT )
  103. {
  104.     // shift
  105.     if ( key == 0x10 )
  106.         shiftstat &= 0xfe ;
  107.     // ctrl
  108.     if ( key == 0x11 )
  109.         shiftstat &= 0xfd ;
  110. }
  111.  
  112. void TMyWindow::EvLButtonDown(UINT, TPoint&)
  113. {
  114. //    TClientDC    dc(*this);
  115. //    char    str[64] ;
  116. //    long    l = (unsigned long)this ;
  117. //    wsprintf( str, "this : %lX : %X %X", l, FP_SEG( this ), FP_OFF( this ) );
  118. //    dc.TextOut( col * 80, line * 16, str );
  119. }
  120.  
  121.  
  122. void TMyWindow::EvRButtonDown(UINT, TPoint&)
  123. {
  124.     *MessageOut << this << " : RButtonDown\n" ;
  125.      Invalidate();
  126. }
  127.  
  128. void TMyWindow::EvMouseMove(UINT, TPoint&)
  129. {
  130. }
  131.  
  132. void TMyWindow::EvLButtonUp(UINT, TPoint&)
  133. {
  134. }
  135.  
  136. class TMyApp : public TApplication {
  137.   public:
  138.       TMyWindow    *MainWindow ;
  139.     TMyApp() : TApplication() {}
  140.  
  141.   protected:
  142.  
  143.     void InitMainWindow();
  144.     void InitInstance();
  145.     void EvDropFiles( TDropInfo );
  146.     DECLARE_RESPONSE_TABLE(TMyApp);
  147. };
  148.  
  149. DEFINE_RESPONSE_TABLE1(TMyApp, TApplication)
  150.   EV_WM_DROPFILES,
  151. END_RESPONSE_TABLE;
  152.  
  153.  
  154. void TMyApp::InitMainWindow()
  155. {
  156.     MainWindow = new TMyWindow ;
  157.     SetMainWindow( new TFrameWindow(0, "グラフ", MainWindow ));
  158.     MainW = GetMainWindow();
  159. }
  160.  
  161. void TMyApp::InitInstance()
  162. {
  163.     TApplication::InitInstance();
  164.     GetMainWindow()->DragAcceptFiles(TRUE);
  165.     MessageOut = new TMessageWindow( "message window", 100 );
  166.     MessageOut->GetWindowPtr()->Create();
  167. }
  168.  
  169. void TMyApp::EvDropFiles( TDropInfo info )
  170. {
  171.     TClientDC    dc(*MainWindow);
  172.     char    str[64] ;
  173.     char    file[128] ;
  174.     
  175.     dc.GetTextFace( 256, str );
  176.     wsprintf( "font : %s\n", str );
  177.     dc.TextOut( MainWindow->col * 80, MainWindow->line * 16, str );
  178.     MainWindow->line ++ ;
  179.  
  180.     info.DragQueryFile( 0, file, 128 );
  181.     wsprintf( str, "drop:%s", file );
  182.     dc.TextOut( MainWindow->col * 80, MainWindow->line * 16, str );
  183.     MainWindow->line ++ ;
  184. }
  185.  
  186. int OwlMain(int /*argc*/, char* /*argv*/ [])
  187. {
  188.   return TMyApp().Run();
  189. }
  190.