DlgProBar.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // DlgProBar.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "SATHelper.h"
  5. #include "DlgProBar.h"
  6. #include "afxdialogex.h"
  7. #include "IMGCommon.h"
  8. #include "SATClient.h"
  9. // CDlgProBar 对话框
  10. Image* CDlgProBar::m_spImg = NULL;
  11. BOOL CDlgProBar::m_sbRuning = TRUE;
  12. Brush *CDlgProBar::m_pBrush = NULL;
  13. extern CDlgProBar* g_pDlgProBar;
  14. IMPLEMENT_DYNAMIC(CDlgProBar, CDialogEx)
  15. CDlgProBar::CDlgProBar(CWnd* pParent /*=NULL*/)
  16. : CDialogEx(IDD_DLG_PROBAR, pParent)
  17. {
  18. m_ulTimeCount = 0;
  19. m_nFrameCount = 0;
  20. m_nCurFrameIndex = 0;
  21. m_pPropertyItem = NULL;
  22. }
  23. CDlgProBar::~CDlgProBar()
  24. {
  25. }
  26. void CDlgProBar::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialogEx::DoDataExchange(pDX);
  29. }
  30. BEGIN_MESSAGE_MAP(CDlgProBar, CDialogEx)
  31. ON_MESSAGE(WM_STOPTHREAD, &CDlgProBar::StopThread)
  32. ON_WM_TIMER()
  33. END_MESSAGE_MAP()
  34. // CDlgProBar 消息处理程序
  35. BOOL CDlgProBar::OnInitDialog()
  36. {
  37. CDialogEx::OnInitDialog();
  38. // TODO: 在此添加额外的初始化
  39. m_sbRuning = TRUE;
  40. if ( m_spImg )
  41. delete m_spImg;
  42. m_spImg = NULL;
  43. m_spImg = IMGCommon::LoadImgFromResource(NULL, MAKEINTRESOURCE(GIF_PROBAR), _T("GIF"));
  44. #if 1
  45. // 获取gif里的维度个数(gif就一个维度);
  46. UINT nCount = m_spImg->GetFrameDimensionsCount();
  47. // 获得维度的GUID列表;
  48. GUID* pDimensionsIDs = (GUID*)new GUID[nCount];
  49. m_spImg->GetFrameDimensionsList(pDimensionsIDs, nCount);
  50. // 获得指定的维度的帧数;
  51. //WCHAR strGUID[39] = { 0 };
  52. //StringFromGUID2(pDimensionsIDs[0], strGUID, 39);
  53. m_nFrameCount = m_spImg->GetFrameCount(&pDimensionsIDs[0]);
  54. delete[] pDimensionsIDs;
  55. // 获得每帧之间的时间间隔;
  56. int size = m_spImg->GetPropertyItemSize(PropertyTagFrameDelay); // 获取时间间隔属性item;
  57. m_pPropertyItem = new byte[size];
  58. PropertyItem* pItem = (PropertyItem*)m_pPropertyItem;
  59. m_spImg->GetPropertyItem(PropertyTagFrameDelay, size, pItem);
  60. CClientDC dc(this);
  61. Graphics gc(dc);
  62. gc.DrawImage(m_spImg, 0, 0, m_spImg->GetWidth(), m_spImg->GetHeight());
  63. // 超时值;
  64. m_ulTimeCount = GetTickCount64();
  65. SetTimer(0, 0, NULL);
  66. #endif
  67. MoveWindow(0, 0, m_spImg->GetWidth(), m_spImg->GetHeight());
  68. CenterWindow();
  69. return TRUE; // return TRUE unless you set the focus to a control
  70. // 异常: OCX 属性页应返回 FALSE
  71. }
  72. LRESULT CDlgProBar::StopThread(WPARAM wp, LPARAM lp)
  73. {
  74. m_sbRuning = FALSE;
  75. return 0;
  76. }
  77. void CDlgProBar::OnCancel()
  78. {
  79. g_pDlgProBar = NULL;
  80. // TODO: 在此添加专用代码和/或调用基类
  81. CDialogEx::OnCancel();
  82. }
  83. void CDlgProBar::OnOK()
  84. {
  85. // TODO: 在此添加专用代码和/或调用基类
  86. //CDialogEx::OnOK();
  87. }
  88. DWORD g_dwTimeOut = 30000;
  89. void CDlgProBar::OnTimer(UINT_PTR nIDEvent)
  90. {
  91. // TODO: 在此添加消息处理程序代码和/或调用默认值
  92. if ( nIDEvent == 0 ) {
  93. KillTimer(0);
  94. // 是否超时;
  95. if (GetTickCount64() - m_ulTimeCount > g_dwTimeOut) {
  96. m_sbRuning = FALSE;
  97. if (m_spImg)
  98. delete m_spImg;
  99. m_spImg = NULL;
  100. if (m_pPropertyItem)
  101. delete[]m_pPropertyItem;
  102. m_pPropertyItem = NULL;
  103. CSATClient::GetInstance()->Stop();
  104. //AfxMessageBox(_T("连接超时!"));
  105. PostMessage(WM_CLOSE);
  106. return;
  107. }
  108. GUID guid = FrameDimensionTime;
  109. CClientDC dc(this);
  110. Graphics gc(dc);
  111. gc.DrawImage(m_spImg, 0, 0, m_spImg->GetWidth(), m_spImg->GetHeight());
  112. // 选择要显示的帧;
  113. m_spImg->SelectActiveFrame(&guid, m_nCurFrameIndex++);
  114. if (m_nCurFrameIndex == m_nFrameCount)
  115. {
  116. m_nCurFrameIndex = 0;
  117. }
  118. PropertyItem* pItem = (PropertyItem*)m_pPropertyItem;
  119. long pause = ((long*)pItem->value)[m_nCurFrameIndex] * 1000;
  120. pause = pause ? pause : 39;
  121. if (m_sbRuning) {
  122. SetTimer(0, pause, NULL);
  123. }
  124. else {
  125. if (m_spImg)
  126. delete m_spImg;
  127. m_spImg = NULL;
  128. if (m_pPropertyItem)
  129. delete[]m_pPropertyItem;
  130. m_pPropertyItem = NULL;
  131. PostMessage(WM_CLOSE);
  132. }
  133. }
  134. CDialogEx::OnTimer(nIDEvent);
  135. }