home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / protview / demowinx / data.3 / shape / samples / MFC / SHAPDEMO / SHAPDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-28  |  5.6 KB  |  209 lines

  1. // ShapDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ShapDemo.h"
  6. #include "ShapDlg.h"
  7. #include "Shape3D.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. #define TIMER_ID 4321
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CShapDlg dialog
  19.  
  20. CShapDlg::CShapDlg(CWnd* pParent /*=NULL*/)
  21.     : CDialog(CShapDlg::IDD, pParent)
  22. {
  23.     //{{AFX_DATA_INIT(CShapDlg)
  24.         // NOTE: the ClassWizard will add member initialization here
  25.     //}}AFX_DATA_INIT
  26.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  27.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  28. }
  29.  
  30. void CShapDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32.     CDialog::DoDataExchange(pDX);
  33.     //{{AFX_DATA_MAP(CShapDlg)
  34.         // NOTE: the ClassWizard will add DDX and DDV calls here
  35.     //}}AFX_DATA_MAP
  36. }
  37.  
  38. BEGIN_MESSAGE_MAP(CShapDlg, CDialog)
  39.     //{{AFX_MSG_MAP(CShapDlg)
  40.     ON_WM_PAINT()
  41.     ON_WM_QUERYDRAGICON()
  42.     ON_BN_CLICKED(IDC_HORIZONTAL, OnHorizontal)
  43.     ON_BN_CLICKED(IDC_ROTATE, OnRotate)
  44.     ON_BN_CLICKED(IDC_STOPGO, OnStopgo)
  45.     ON_BN_CLICKED(IDC_SYMMETRICAL, OnSymmetrical)
  46.     ON_BN_CLICKED(IDC_TRANSPARENT, OnTransparent)
  47.     ON_BN_CLICKED(IDC_VERTICAL, OnVertical)
  48.     ON_WM_DESTROY()
  49.     ON_WM_TIMER()
  50.     //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CShapDlg message handlers
  55.  
  56. BOOL CShapDlg::OnInitDialog()
  57. {
  58.     CDialog::OnInitDialog();
  59.  
  60.     // Set the icon for this dialog.  The framework does this automatically
  61.     //  when the application's main window is not a dialog
  62.     SetIcon(m_hIcon, TRUE);            // Set big icon
  63.     SetIcon(m_hIcon, FALSE);        // Set small icon
  64.     
  65.     // TODO: Add extra initialization here
  66.     m_uTimer = 0;
  67.     SetTimer(TIMER_ID, 1000, NULL);
  68.     
  69.     return TRUE;  // return TRUE  unless you set the focus to a control
  70. }
  71.  
  72. // If you add a minimize button to your dialog, you will need the code below
  73. //  to draw the icon.  For MFC applications using the document/view model,
  74. //  this is automatically done for you by the framework.
  75.  
  76. void CShapDlg::OnPaint() 
  77. {
  78.     if (IsIconic())
  79.     {
  80.         CPaintDC dc(this); // device context for painting
  81.  
  82.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  83.  
  84.         // Center icon in client rectangle
  85.         int cxIcon = GetSystemMetrics(SM_CXICON);
  86.         int cyIcon = GetSystemMetrics(SM_CYICON);
  87.         CRect rect;
  88.         GetClientRect(&rect);
  89.         int x = (rect.Width() - cxIcon + 1) / 2;
  90.         int y = (rect.Height() - cyIcon + 1) / 2;
  91.  
  92.         // Draw the icon
  93.         dc.DrawIcon(x, y, m_hIcon);
  94.     }
  95.     else
  96.     {
  97.         CDialog::OnPaint();
  98.     }
  99. }
  100.  
  101. // The system calls this to obtain the cursor to display while the user drags
  102. //  the minimized window.
  103. HCURSOR CShapDlg::OnQueryDragIcon()
  104. {
  105.     return (HCURSOR) m_hIcon;
  106. }
  107.  
  108. void CShapDlg::OnHorizontal() 
  109. {
  110.     BOOL fCheck = ((CButton*)GetDlgItem(IDC_HORIZONTAL))->GetCheck();
  111.     RECT r;
  112.     int  iWidth = 0;
  113.  
  114.     GetDlgItem(IDC_SHAPE1)->GetClientRect(&r);
  115.     if(fCheck) 
  116.         iWidth = r.right >> 2;
  117.     ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetShiftShapeLeft(iWidth);
  118.  
  119.     GetDlgItem(IDC_SHAPE2)->GetClientRect(&r);
  120.     if(fCheck) 
  121.         iWidth = r.right >> 2;
  122.     ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetShiftShapeLeft(iWidth);
  123. }
  124.  
  125. void CShapDlg::OnRotate() 
  126. {
  127.     BOOL fCheck = ((CButton*)GetDlgItem(IDC_ROTATE))->GetCheck();
  128.     
  129.     ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetRotateSide(fCheck);
  130.     ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetRotateSide(fCheck);
  131.     ((CShape3D*)GetDlgItem(IDC_SHAPE3))->SetRotateSide(fCheck);
  132.     ((CShape3D*)GetDlgItem(IDC_SHAPE4))->SetRotateSide(fCheck);
  133. }
  134.  
  135. void CShapDlg::OnStopgo() 
  136. {
  137.     //---------------------------------------
  138.     // start or kill timer
  139.     if(KillTimer(TIMER_ID))
  140.     {
  141.         ((CShape3D*)GetDlgItem(IDC_STOPGOSHAPE))->SetBackColor(0x00ff00ff);
  142.         SetDlgItemText(IDC_STOPGO, "Go");
  143.     }
  144.     else
  145.     {
  146.         SetTimer(TIMER_ID, 1000, NULL);
  147.         ((CShape3D*)GetDlgItem(IDC_STOPGOSHAPE))->SetBackColor(RGB(255,0,0));
  148.         SetDlgItemText(IDC_STOPGO, "Stop");
  149.     }
  150. }
  151.  
  152. void CShapDlg::OnSymmetrical() 
  153. {
  154.     BOOL fCheck = ((CButton*)GetDlgItem(IDC_SYMMETRICAL))->GetCheck();
  155.     
  156.     ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetSymmetrical(fCheck);
  157.     ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetSymmetrical(fCheck);
  158.     ((CShape3D*)GetDlgItem(IDC_SHAPE3))->SetSymmetrical(fCheck);
  159.     ((CShape3D*)GetDlgItem(IDC_SHAPE4))->SetSymmetrical(fCheck);
  160.  
  161.     GetDlgItem(IDC_HORIZONTAL)->EnableWindow(!fCheck);
  162.     GetDlgItem(IDC_VERTICAL)->EnableWindow(!fCheck);
  163. }
  164.  
  165. void CShapDlg::OnTransparent() 
  166. {
  167.     BOOL fCheck = ((CButton*)GetDlgItem(IDC_TRANSPARENT))->GetCheck();
  168.     
  169.     ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetTransparent(fCheck);
  170.     ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetTransparent(fCheck);
  171.     ((CShape3D*)GetDlgItem(IDC_SHAPE3))->SetTransparent(fCheck);
  172.     ((CShape3D*)GetDlgItem(IDC_SHAPE4))->SetTransparent(fCheck);
  173. }
  174.  
  175. void CShapDlg::OnVertical() 
  176. {
  177.     BOOL fCheck = ((CButton*)GetDlgItem(IDC_VERTICAL))->GetCheck();
  178.     RECT r;
  179.     int  iHeight = 0;
  180.  
  181.     GetDlgItem(IDC_SHAPE1)->GetClientRect(&r);
  182.     if(fCheck) 
  183.         iHeight = r.bottom >> 2;
  184.     ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetShiftShapeUp(iHeight);
  185.  
  186.     GetDlgItem(IDC_SHAPE2)->GetClientRect(&r);
  187.     if(fCheck) 
  188.         iHeight = r.bottom >> 2;
  189.     ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetShiftShapeUp(iHeight);
  190. }
  191.  
  192. void CShapDlg::OnDestroy() 
  193. {
  194.     KillTimer(TIMER_ID);
  195.     CDialog::OnDestroy();
  196. }
  197.  
  198. void CShapDlg::OnTimer(UINT nIDEvent) 
  199. {
  200.     CDialog::OnTimer(nIDEvent);
  201.     if(nIDEvent != TIMER_ID) return;
  202.     //--------------------------------
  203.     // create loop of m_uTimer ==> 0..8
  204.     if(++m_uTimer > 8) m_uTimer = 0;
  205.     //--------------------------------
  206.     ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetShape(m_uTimer);
  207.     ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetShape(m_uTimer);
  208. }
  209.