DukeDlg.cpp
上传用户:do_tie
上传日期:2007-11-03
资源大小:1095k
文件大小:3k
- // DukeDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "GandyDraw.h"
- #include "DukeDlg.h"
- // CDukeDlg 对话框
- IMPLEMENT_DYNAMIC(CDukeDlg, CDialog)
- CDukeDlg::CDukeDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CDukeDlg::IDD, pParent)
- , m_bStarted(false)
- , m_iCurFrame(0)
- , m_iTimesPerSecond(0)
- , pSlider(NULL)
- {
- }
- CDukeDlg::~CDukeDlg()
- {
- for (int i = 0; i < 10; i++)
- {
- delete m_pBmp[i];
- }
- }
- void CDukeDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CDukeDlg, CDialog)
- ON_BN_CLICKED(IDC_ANI_STARTSTOP, &CDukeDlg::OnBnClickedAniStartstop)
- ON_WM_TIMER()
- ON_WM_HSCROLL()
- ON_EN_CHANGE(IDC_N, &CDukeDlg::OnEnChangeN)
- END_MESSAGE_MAP()
- // CDukeDlg 消息处理程序
- BOOL CDukeDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- pSlider = (CSliderCtrl *)GetDlgItem(IDC_SLIDER_N);
- pSlider->SetRange(1, 100);
- pSlider->SetPos(m_iTimesPerSecond);
- SetDlgItemInt(IDC_N, m_iTimesPerSecond);
- for (int i = 0; i < 10; i++) {
- m_pBmp[i] = new CBitmap;
- m_pBmp[i]->LoadBitmap(IDB_BITMAP1 + i);
- }
- m_pBmp[0]->GetBitmap(&bs);
- return TRUE; // return TRUE unless you set the focus to a control
- // 异常: OCX 属性页应返回 FALSE
- }
- void CDukeDlg::OnBnClickedAniStartstop()
- {
- if (m_bStarted) {
- KillTimer(1);
- m_bStarted = FALSE;
- SetDlgItemText(IDC_ANI_STARTSTOP, L"开始动画");
- }
- else {
- m_bStarted = TRUE;
- m_iCurFrame = 0;
- m_iTimesPerSecond = GetDlgItemInt(IDC_N);
- if (m_iTimesPerSecond <= 0) m_iTimesPerSecond = 1;
- else if (m_iTimesPerSecond > 100) m_iTimesPerSecond = 100;
- SetDlgItemInt(IDC_N, m_iTimesPerSecond);
- SetTimer(1, (UINT)(1000.0/m_iTimesPerSecond + 0.5), NULL);
- SetDlgItemText(IDC_ANI_STARTSTOP, L"停止动画");
- }
- }
- void CDukeDlg::OnTimer(UINT_PTR nIDEvent)
- {
- CDC *pDC = GetDlgItem(IDC_ANI)->GetDC();
- CDC dc;
- dc.CreateCompatibleDC(pDC);
- dc.SelectObject(m_pBmp[m_iCurFrame]);
- pDC->BitBlt(0, 0, bs.bmWidth, bs.bmHeight, &dc, 0, 0, SRCCOPY);
- m_iCurFrame++;
- m_iCurFrame %= 10;
- CDialog::OnTimer(nIDEvent);
- }
- void CDukeDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- SetDlgItemInt(IDC_N, pSlider->GetPos());
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void CDukeDlg::OnEnChangeN()
- {
- // TODO: 如果该控件是 RICHEDIT 控件,则它将不会
- // 发送该通知,除非重写 CDialog::OnInitDialog()
- // 函数并调用 CRichEditCtrl().SetEventMask(),
- // 同时将 ENM_CHANGE 标志“或”运算到掩码中。
- // TODO: 在此添加控件通知处理程序代码
- pSlider->SetPos(GetDlgItemInt(IDC_N));
- }