home *** CD-ROM | disk | FTP | other *** search
- // ShapDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "ShapDemo.h"
- #include "ShapDlg.h"
- #include "Shape3D.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define TIMER_ID 4321
-
- /////////////////////////////////////////////////////////////////////////////
- // CShapDlg dialog
-
- CShapDlg::CShapDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CShapDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CShapDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void CShapDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CShapDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CShapDlg, CDialog)
- //{{AFX_MSG_MAP(CShapDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_HORIZONTAL, OnHorizontal)
- ON_BN_CLICKED(IDC_ROTATE, OnRotate)
- ON_BN_CLICKED(IDC_STOPGO, OnStopgo)
- ON_BN_CLICKED(IDC_SYMMETRICAL, OnSymmetrical)
- ON_BN_CLICKED(IDC_TRANSPARENT, OnTransparent)
- ON_BN_CLICKED(IDC_VERTICAL, OnVertical)
- ON_WM_DESTROY()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CShapDlg message handlers
-
- BOOL CShapDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
- m_uTimer = 0;
- SetTimer(TIMER_ID, 1000, NULL);
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
-
- void CShapDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CShapDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- void CShapDlg::OnHorizontal()
- {
- BOOL fCheck = ((CButton*)GetDlgItem(IDC_HORIZONTAL))->GetCheck();
- RECT r;
- int iWidth = 0;
-
- GetDlgItem(IDC_SHAPE1)->GetClientRect(&r);
- if(fCheck)
- iWidth = r.right >> 2;
- ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetShiftShapeLeft(iWidth);
-
- GetDlgItem(IDC_SHAPE2)->GetClientRect(&r);
- if(fCheck)
- iWidth = r.right >> 2;
- ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetShiftShapeLeft(iWidth);
- }
-
- void CShapDlg::OnRotate()
- {
- BOOL fCheck = ((CButton*)GetDlgItem(IDC_ROTATE))->GetCheck();
-
- ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetRotateSide(fCheck);
- ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetRotateSide(fCheck);
- ((CShape3D*)GetDlgItem(IDC_SHAPE3))->SetRotateSide(fCheck);
- ((CShape3D*)GetDlgItem(IDC_SHAPE4))->SetRotateSide(fCheck);
- }
-
- void CShapDlg::OnStopgo()
- {
- //---------------------------------------
- // start or kill timer
- if(KillTimer(TIMER_ID))
- {
- ((CShape3D*)GetDlgItem(IDC_STOPGOSHAPE))->SetBackColor(0x00ff00ff);
- SetDlgItemText(IDC_STOPGO, "Go");
- }
- else
- {
- SetTimer(TIMER_ID, 1000, NULL);
- ((CShape3D*)GetDlgItem(IDC_STOPGOSHAPE))->SetBackColor(RGB(255,0,0));
- SetDlgItemText(IDC_STOPGO, "Stop");
- }
- }
-
- void CShapDlg::OnSymmetrical()
- {
- BOOL fCheck = ((CButton*)GetDlgItem(IDC_SYMMETRICAL))->GetCheck();
-
- ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetSymmetrical(fCheck);
- ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetSymmetrical(fCheck);
- ((CShape3D*)GetDlgItem(IDC_SHAPE3))->SetSymmetrical(fCheck);
- ((CShape3D*)GetDlgItem(IDC_SHAPE4))->SetSymmetrical(fCheck);
-
- GetDlgItem(IDC_HORIZONTAL)->EnableWindow(!fCheck);
- GetDlgItem(IDC_VERTICAL)->EnableWindow(!fCheck);
- }
-
- void CShapDlg::OnTransparent()
- {
- BOOL fCheck = ((CButton*)GetDlgItem(IDC_TRANSPARENT))->GetCheck();
-
- ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetTransparent(fCheck);
- ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetTransparent(fCheck);
- ((CShape3D*)GetDlgItem(IDC_SHAPE3))->SetTransparent(fCheck);
- ((CShape3D*)GetDlgItem(IDC_SHAPE4))->SetTransparent(fCheck);
- }
-
- void CShapDlg::OnVertical()
- {
- BOOL fCheck = ((CButton*)GetDlgItem(IDC_VERTICAL))->GetCheck();
- RECT r;
- int iHeight = 0;
-
- GetDlgItem(IDC_SHAPE1)->GetClientRect(&r);
- if(fCheck)
- iHeight = r.bottom >> 2;
- ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetShiftShapeUp(iHeight);
-
- GetDlgItem(IDC_SHAPE2)->GetClientRect(&r);
- if(fCheck)
- iHeight = r.bottom >> 2;
- ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetShiftShapeUp(iHeight);
- }
-
- void CShapDlg::OnDestroy()
- {
- KillTimer(TIMER_ID);
- CDialog::OnDestroy();
- }
-
- void CShapDlg::OnTimer(UINT nIDEvent)
- {
- CDialog::OnTimer(nIDEvent);
- if(nIDEvent != TIMER_ID) return;
- //--------------------------------
- // create loop of m_uTimer ==> 0..8
- if(++m_uTimer > 8) m_uTimer = 0;
- //--------------------------------
- ((CShape3D*)GetDlgItem(IDC_SHAPE1))->SetShape(m_uTimer);
- ((CShape3D*)GetDlgItem(IDC_SHAPE2))->SetShape(m_uTimer);
- }
-