AnimationDlg.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:5k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // AnimationDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Animation.h"
  5. #include "AnimationDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAnimationDlg dialog
  13. CAnimationDlg::CAnimationDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CAnimationDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CAnimationDlg)
  17. m_nAnimationDelay = m_staticGear.GetAnimationDelay();
  18. m_nAnimationType = m_staticGear.GetAnimationType();
  19. m_nAnimationSteps = m_staticGear.GetAnimationSteps();
  20. //}}AFX_DATA_INIT
  21. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  22. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  23. }
  24. void CAnimationDlg::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CAnimationDlg)
  28. DDX_Control(pDX, IDC_EDIT_STEPS, m_editSteps);
  29. DDX_Control(pDX, IDC_EDIT_DELAY, m_editDelay);
  30. DDX_Control(pDX, IDC_BMP_GEAR, m_staticGear);
  31. DDX_Text(pDX, IDC_EDIT_DELAY, m_nAnimationDelay);
  32. DDV_MinMaxInt(pDX, m_nAnimationDelay, 1, 1000);
  33. DDX_Radio(pDX, IDC_RADIO_ANIMATION, m_nAnimationType);
  34. DDX_Text(pDX, IDC_EDIT_STEPS, m_nAnimationSteps);
  35. DDV_MinMaxInt(pDX, m_nAnimationSteps, 1, 100);
  36. DDX_Control(pDX, IDC_STATIC_DELAY, m_staticDelay);
  37. DDX_Control(pDX, IDC_STATIC_STEPS, m_staticSteps);
  38. //}}AFX_DATA_MAP
  39. }
  40. BEGIN_MESSAGE_MAP(CAnimationDlg, CDialog)
  41. //{{AFX_MSG_MAP(CAnimationDlg)
  42. ON_WM_SYSCOMMAND()
  43. ON_WM_PAINT()
  44. ON_WM_QUERYDRAGICON()
  45. ON_BN_CLICKED(IDC_ANIMATE, OnAnimate)
  46. ON_EN_CHANGE(IDC_EDIT_DELAY, OnChangeEditDelay)
  47. ON_EN_CHANGE(IDC_EDIT_STEPS, OnChangeEditSteps)
  48. //}}AFX_MSG_MAP
  49. ON_BN_CLICKED(IDC_RADIO_ANIMATION, OnBnClickedRadio)
  50. ON_BN_CLICKED(IDC_RADIO5, OnBnClickedRadio)
  51. ON_BN_CLICKED(IDC_RADIO4, OnBnClickedRadio)
  52. ON_BN_CLICKED(IDC_RADIO3, OnBnClickedRadio)
  53. ON_BN_CLICKED(IDC_RADIO2, OnBnClickedRadio)
  54. ON_BN_CLICKED(IDC_RADIO7, OnBnClickedRadio)
  55. ON_BN_CLICKED(IDC_RADIO6, OnBnClickedRadio)
  56. ON_BN_CLICKED(IDC_RADIO8, OnBnClickedRadio)
  57. ON_BN_CLICKED(IDC_RADIO9, OnBnClickedRadio)
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CAnimationDlg message handlers
  61. BOOL CAnimationDlg::OnInitDialog()
  62. {
  63. CDialog::OnInitDialog();
  64. // Add "About..." menu item to system menu.
  65. // IDM_ABOUTBOX must be in the system command range.
  66. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  67. ASSERT(IDM_ABOUTBOX < 0xF000);
  68. CMenu* pSysMenu = GetSystemMenu(FALSE);
  69. if (pSysMenu != NULL)
  70. {
  71. CString strAboutMenu;
  72. strAboutMenu.LoadString(IDS_ABOUTBOX);
  73. if (!strAboutMenu.IsEmpty())
  74. {
  75. pSysMenu->AppendMenu(MF_SEPARATOR);
  76. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  77. }
  78. }
  79. // Set the icon for this dialog.  The framework does this automatically
  80. //  when the application's main window is not a dialog
  81. SetIcon(m_hIcon, TRUE); // Set big icon
  82. SetIcon(m_hIcon, FALSE); // Set small icon
  83. return TRUE;  // return TRUE  unless you set the focus to a control
  84. }
  85. void CAnimationDlg::OnSysCommand(UINT nID, LPARAM lParam)
  86. {
  87. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  88. {
  89. CAboutDlg dlgAbout;
  90. dlgAbout.DoModal();
  91. }
  92. else
  93. {
  94. CDialog::OnSysCommand(nID, lParam);
  95. }
  96. }
  97. // If you add a minimize button to your dialog, you will need the code below
  98. //  to draw the icon.  For MFC applications using the document/view model,
  99. //  this is automatically done for you by the framework.
  100. void CAnimationDlg::OnPaint() 
  101. {
  102. if (IsIconic())
  103. {
  104. CPaintDC dc(this); // device context for painting
  105. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  106. // Center icon in client rectangle
  107. int cxIcon = GetSystemMetrics(SM_CXICON);
  108. int cyIcon = GetSystemMetrics(SM_CYICON);
  109. CRect rect;
  110. GetClientRect(&rect);
  111. int x = (rect.Width() - cxIcon + 1) / 2;
  112. int y = (rect.Height() - cyIcon + 1) / 2;
  113. // Draw the icon
  114. dc.DrawIcon(x, y, m_hIcon);
  115. }
  116. else
  117. {
  118. CDialog::OnPaint();
  119. }
  120. }
  121. // The system calls this to obtain the cursor to display while the user drags
  122. //  the minimized window.
  123. HCURSOR CAnimationDlg::OnQueryDragIcon()
  124. {
  125. return (HCURSOR) m_hIcon;
  126. }
  127. void CAnimationDlg::OnAnimate() 
  128. {
  129. UpdateData();
  130. // set animation properties
  131. m_staticGear.SetAnimationDelay(m_nAnimationDelay);
  132. m_staticGear.SetAnimationType(m_nAnimationType);
  133. m_staticGear.SetAnimationSteps(m_nAnimationSteps);
  134. // draw animation
  135. m_staticGear.Animate();
  136. }
  137. void CAnimationDlg::OnChangeEditDelay() 
  138. {
  139. UpdateData();
  140. if (m_nAnimationDelay < 1 || m_nAnimationDelay > 1000)
  141. {
  142. m_nAnimationDelay = m_staticGear.GetAnimationDelay();
  143. UpdateData(FALSE);
  144. m_editDelay.SetSel(0,-1);
  145. }
  146. }
  147. void CAnimationDlg::OnChangeEditSteps() 
  148. {
  149. UpdateData();
  150. if (m_nAnimationSteps < 1 || m_nAnimationSteps > 100)
  151. {
  152. m_nAnimationSteps = m_staticGear.GetAnimationSteps();
  153. UpdateData(FALSE);
  154. m_editSteps.SetSel(0,-1);
  155. }
  156. }
  157. void CAnimationDlg::OnBnClickedRadio()
  158. {
  159. UpdateData();
  160. m_editDelay.EnableWindow(m_nAnimationType <= 5);
  161. m_staticDelay.EnableWindow(m_nAnimationType <= 5);
  162. m_editSteps.EnableWindow(m_nAnimationType <= 5);
  163. m_staticSteps.EnableWindow(m_nAnimationType <= 5);
  164. }