home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / etcha / etcha.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  4.6 KB  |  218 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1999 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12. #include "resource.h"
  13.  
  14. // Define a window class derived from CFrameWnd
  15. class CMainWindow : public CFrameWnd
  16. {
  17. private:
  18.     CPoint m_line[2], m_SaveLine[1000];
  19.     int m_nPoint;
  20. //    CMemoryState vv;
  21.  
  22. public:
  23.     CMainWindow();
  24.  
  25.     //{{AFX_MSG( CMainWindow )
  26.     afx_msg void OnFileNew();
  27.     afx_msg void OnHelpAbout();
  28.     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  29.     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  30.     afx_msg void OnPaint();
  31.     afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  32.     //}}AFX_MSG
  33.  
  34.     DECLARE_MESSAGE_MAP()
  35. };
  36.  
  37. class CAboutDlg : public CDialog
  38. {
  39. public:
  40.     CAboutDlg( UINT uiResourceID ) : CDialog( uiResourceID )    {}
  41.  
  42.     //{{AFX_MSG( CAboutDlg )
  43.     afx_msg void OnOK();
  44.     virtual BOOL OnInitDialog();
  45.     //}}AFX_MSG
  46.  
  47.     DECLARE_MESSAGE_MAP()
  48. };
  49.  
  50. // Define an application class derived from CWinApp
  51. class CEtchaApp : public CWinApp
  52. {
  53. public:
  54.     virtual BOOL InitInstance();
  55.  
  56.     //{{AFX_MSG(CCtrldemoApp)
  57.     //}}AFX_MSG
  58.     DECLARE_MESSAGE_MAP()
  59. };                  
  60.  
  61. //////////////////////////////////////////////////////////////////////////
  62. //  Implementation
  63. //////////////////////////////////////////////////////////////////////////
  64.  
  65. BEGIN_MESSAGE_MAP(CEtchaApp, CWinApp)
  66.     //{{AFX_MSG_MAP(CEtchaApp)
  67.     //}}AFX_MSG_MAP
  68.     // Standard file based document commands
  69.     ON_COMMAND(ID_FILE_EXIT, CWinApp::OnAppExit)
  70. END_MESSAGE_MAP()
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CAboutDlg message handlers
  74.  
  75. BOOL CAboutDlg::OnInitDialog() 
  76. {
  77.     CDialog::OnInitDialog();
  78.     CenterWindow();    
  79.     return TRUE; 
  80. }
  81.  
  82. // Create the application's main window and perform initialization chores
  83. BOOL CEtchaApp::InitInstance()
  84. {
  85.     m_pMainWnd = new CMainWindow();
  86.     m_pMainWnd->ShowWindow( m_nCmdShow );
  87.     m_pMainWnd->UpdateWindow();
  88.  
  89.     return (TRUE);
  90. }
  91.  
  92. // CEtchaApp's contructor initializes and runs the app
  93. CEtchaApp goDlgFRApp;
  94.  
  95. CMainWindow::CMainWindow()
  96. {
  97.     LoadFrame(IDR_MAINFRAME);
  98.  
  99.     // For MFCCE 2.0 and earlier, a command bar was created during
  100.     // the CFrameWnd creation. For MFCCE 2.01 and later, a command bar 
  101.     // is automatically created for you during the call to AddAdornments().
  102.     AddAdornments(0);
  103.  
  104.     m_nPoint = 0;
  105. }
  106.  
  107. // CMainWindow message map:
  108. BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
  109.     //{{AFX_MSG_MAP( CMainWindow )
  110.     ON_COMMAND(ID_FILE_NEW, OnFileNew)
  111.     ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
  112.     ON_WM_LBUTTONDOWN()
  113.     ON_WM_MOUSEMOVE()
  114.     ON_WM_PAINT()
  115.     ON_WM_LBUTTONUP()
  116.     //}}AFX_MSG_MAP
  117. END_MESSAGE_MAP()
  118.  
  119. void CMainWindow::OnFileNew() 
  120. {
  121.     m_nPoint = 0;
  122.  
  123.     CRect rect;
  124.     GetClientRect(&rect);
  125.     InvalidateRect(rect);
  126. }
  127.  
  128. void CMainWindow::OnHelpAbout() 
  129. {
  130.     CAboutDlg about(IDD_ABOUT);
  131.     about.DoModal();
  132. }
  133.  
  134. void CMainWindow::OnLButtonDown(UINT nFlags, CPoint point) 
  135. {
  136.     m_line[0] = point;
  137.     m_SaveLine[m_nPoint] = point;
  138.     m_nPoint++;
  139.     if (m_nPoint >= 1000)
  140.     {
  141.         m_nPoint = 0;
  142.     }
  143.  
  144.     CFrameWnd::OnLButtonDown(nFlags, point);
  145. }
  146.  
  147. void CMainWindow::OnMouseMove(UINT nFlags, CPoint point) 
  148. {
  149.     // Check that the LButton is down
  150.     if (nFlags & MK_LBUTTON)
  151.     {
  152.         CDC* pDC = GetDC();
  153.         m_line[1] = point;
  154.         if (m_line[0] != m_line[1])
  155.         {
  156.             pDC->Polyline(m_line, 2);
  157.             m_SaveLine[m_nPoint] = point;
  158.             m_nPoint++;
  159.             if (m_nPoint >= 1000)
  160.             {
  161.                 m_nPoint = 0;
  162.             }
  163.         }
  164.         m_line[0] = m_line[1];
  165.         ReleaseDC(pDC);
  166.     }
  167.     
  168.     CFrameWnd::OnMouseMove(nFlags, point);
  169. }
  170.  
  171. BEGIN_MESSAGE_MAP( CAboutDlg, CDialog )
  172.     //{{AFX_MSG_MAP( CAboutDlg )
  173.     ON_COMMAND(IDOK, OnOK)
  174.     //}}AFX_MSG_MAP
  175. END_MESSAGE_MAP()
  176.  
  177. void CAboutDlg::OnOK()
  178. {
  179.     // Just wish to close dialog box, so treat as a cancel
  180.     CDialog::OnCancel();
  181. }
  182.  
  183.  
  184.  
  185. void CMainWindow::OnPaint() 
  186. {
  187.     CPaintDC dc(this); // device context for painting
  188.     
  189.     int i = 0;
  190.     CPoint pZero(0,0);
  191.     while(i < m_nPoint)
  192.     {
  193.         int k = 0, m = i;
  194.         while(m_SaveLine[i] != pZero && i < m_nPoint)
  195.         {
  196.             i++;
  197.             k++;
  198.         }
  199.         i++;
  200.         dc.Polyline(&(m_SaveLine[m]), k);
  201.     }
  202.     // Do not call CFrameWnd ::OnPaint() for painting messages
  203. }
  204.  
  205. void CMainWindow::OnLButtonUp(UINT nFlags, CPoint point) 
  206. {
  207.     CPoint pointTmp(0,0);
  208.  
  209.     m_SaveLine[m_nPoint] = pointTmp;
  210.     m_nPoint++;
  211.     if (m_nPoint >= 1000)
  212.     {
  213.         m_nPoint = 0;
  214.     }
  215.  
  216.     CFrameWnd ::OnLButtonUp(nFlags, point);
  217. }
  218.