IconProgressAppDlg.cpp
上传用户:nhyuejuan
上传日期:2013-12-02
资源大小:171k
文件大小:4k
源码类别:

状态条

开发平台:

Visual C++

  1. // IconProgressAppDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "IconProgressApp.h"
  5. #include "IconProgressAppDlg.h"
  6. #include "math.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CIconProgressAppDlg dialog
  14. CIconProgressAppDlg::CIconProgressAppDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CIconProgressAppDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CIconProgressAppDlg)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  21. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  22. }
  23. void CIconProgressAppDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CIconProgressAppDlg)
  27. // NOTE: the ClassWizard will add DDX and DDV calls here
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CIconProgressAppDlg, CDialog)
  31. //{{AFX_MSG_MAP(CIconProgressAppDlg)
  32. ON_WM_PAINT()
  33. ON_WM_QUERYDRAGICON()
  34. ON_WM_TIMER()
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CIconProgressAppDlg message handlers
  39. BOOL CIconProgressAppDlg::OnInitDialog()
  40. {
  41. CDialog::OnInitDialog();
  42. icon_progress1.Attach(IDC_ICON_PROGRESS1, this, IDI_ICON2, 18, 4);
  43. icon_progress1.SetRange(0, 100);
  44. icon_progress1.SetPos(0);
  45. icon_progress2.Attach(IDC_ICON_PROGRESS2, this, IDI_ICON3, 4, RGB(255, 128, 128));
  46. icon_progress2.SetRange(-100, 200);
  47. icon_progress2.SetIconChange(IDI_ICON4, 0);
  48. icon_progress2.SetIconChange(IDI_ICON5, 100);
  49. icon_progress2.SetPos(-100);
  50. icon_progress3.Attach(IDC_ICON_PROGRESS3, this, IDI_ICON1, 8, RGB(0, 96, 96));
  51. icon_progress3.SetRange(100, 200);
  52. icon_progress3.SetPos(100);
  53. icon_progress4.Attach(IDC_ICON_PROGRESS4, this, IDI_ICON6, 24);
  54. icon_progress4.SetRange(0, 100);
  55. icon_progress4.SetPos(0);
  56. SetTimer(0, 50, 0);
  57. // Set the icon for this dialog.  The framework does this automatically
  58. //  when the application's main window is not a dialog
  59. SetIcon(m_hIcon, TRUE); // Set big icon
  60. SetIcon(m_hIcon, FALSE); // Set small icon
  61. return TRUE;
  62. }
  63. // If you add a minimize button to your dialog, you will need the code below
  64. //  to draw the icon.  For MFC applications using the document/view model,
  65. //  this is automatically done for you by the framework.
  66. void CIconProgressAppDlg::OnPaint() 
  67. {
  68. if (IsIconic())
  69. {
  70. CPaintDC dc(this); // device context for painting
  71. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  72. // Center icon in client rectangle
  73. int cxIcon = GetSystemMetrics(SM_CXICON);
  74. int cyIcon = GetSystemMetrics(SM_CYICON);
  75. CRect rect;
  76. GetClientRect(&rect);
  77. int x = (rect.Width() - cxIcon + 1) / 2;
  78. int y = (rect.Height() - cyIcon + 1) / 2;
  79. // Draw the icon
  80. dc.DrawIcon(x, y, m_hIcon);
  81. }
  82. else
  83. {
  84. CDialog::OnPaint();
  85. }
  86. }
  87. // The system calls this to obtain the cursor to display while the user drags
  88. //  the minimized window.
  89. HCURSOR CIconProgressAppDlg::OnQueryDragIcon()
  90. {
  91. return (HCURSOR) m_hIcon;
  92. }
  93. void CIconProgressAppDlg::OnTimer(UINT nIDEvent) 
  94. {
  95. static int position1 = 0;
  96. static int position2 = -100;
  97. static double index  = 0;
  98. int position3;
  99. switch (nIDEvent)
  100. {
  101. case 0:
  102. {
  103. position1 += 1;
  104. icon_progress1.SetPos(position1);
  105. icon_progress4.SetPos(100 - position1 + 20);
  106. position1 %= 100;
  107. position2 += 5;
  108. icon_progress2.SetPos(position2);
  109. if (position2 == 200)
  110. {
  111. position2 = -100;
  112. }
  113. index++;
  114. position3  = (int)(100.0 * sin(index * (3.1415927 / 50)));
  115. if (position3 == 99)
  116. {
  117. position3 = 100;
  118. }
  119. position3 += 100;
  120. icon_progress3.SetPos(position3);
  121. if (index == 50)
  122. {
  123. index = 0;
  124. }
  125. break;
  126. }
  127. }
  128. CDialog::OnTimer(nIDEvent);
  129. }