Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
5.9 KiB

  1. //--------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation, 1998 - 1999
  3. //
  4. // progress.cpp
  5. //
  6. // IR ProgressBar object.
  7. //
  8. //--------------------------------------------------------------------------
  9. #include <windows.h>
  10. #include <shlobj.h>
  11. #include <malloc.h>
  12. #include "ircamera.h"
  13. #include "progress.h"
  14. //--------------------------------------------------------------------------
  15. // CIrProgress::CIrProgress()
  16. //
  17. //--------------------------------------------------------------------------
  18. CIrProgress::CIrProgress() :
  19. m_hInstance(NULL),
  20. m_pPD(NULL)
  21. {
  22. }
  23. //--------------------------------------------------------------------------
  24. // CIrProgress::~CIrProgress()
  25. //
  26. //--------------------------------------------------------------------------
  27. CIrProgress::~CIrProgress()
  28. {
  29. if (m_pPD)
  30. {
  31. m_pPD->Release();
  32. m_pPD = NULL;
  33. }
  34. }
  35. //--------------------------------------------------------------------------
  36. // CIrProgress::Initialize()
  37. //
  38. //--------------------------------------------------------------------------
  39. HRESULT CIrProgress::Initialize( IN HINSTANCE hInstance,
  40. IN DWORD dwIdrAnimationAvi )
  41. {
  42. HRESULT hr;
  43. CHAR szStr[MAX_PATH];
  44. WCHAR wszStr[MAX_PATH];
  45. if (!hInstance)
  46. {
  47. return E_INVALIDARG;
  48. }
  49. m_hInstance = hInstance;
  50. //
  51. // Create a shell progress object to do the work for us.
  52. //
  53. hr = CoCreateInstance( CLSID_ProgressDialog,
  54. NULL,
  55. CLSCTX_INPROC_SERVER,
  56. IID_IProgressDialog,
  57. (void**)&m_pPD );
  58. if (FAILED(hr))
  59. {
  60. return hr;
  61. }
  62. //
  63. // Get the title string and place it on the progress dialog:
  64. //
  65. if (::LoadStringResource(m_hInstance,
  66. IDS_PROGRESS_TITLE,
  67. wszStr,
  68. MAX_PATH ))
  69. {
  70. hr = m_pPD->SetTitle(wszStr);
  71. }
  72. else
  73. {
  74. // Couldn't load string, default title...
  75. hr = m_pPD->SetTitle(L"Image Transfer Progress");
  76. }
  77. //
  78. // Setup the file transfer animation
  79. //
  80. hr = m_pPD->SetAnimation( m_hInstance, dwIdrAnimationAvi );
  81. if (FAILED(hr))
  82. {
  83. goto error;
  84. }
  85. //
  86. // Setup the cancel string (displayed when the cancel button
  87. // is pressed.
  88. //
  89. if (::LoadStringResource(m_hInstance,
  90. IDS_CANCEL_MSG,
  91. wszStr,
  92. MAX_PATH ))
  93. {
  94. hr = m_pPD->SetCancelMsg( wszStr, NULL );
  95. }
  96. else
  97. {
  98. // Couldn't load string, use default cancel message...
  99. hr = m_pPD->SetCancelMsg( L"Cleaning up...", NULL );
  100. }
  101. return hr;
  102. error:
  103. m_pPD->Release();
  104. m_pPD = NULL;
  105. m_hInstance = NULL;
  106. return hr;
  107. }
  108. //--------------------------------------------------------------------------
  109. // CIrProgress::SetText()
  110. //
  111. //--------------------------------------------------------------------------
  112. HRESULT CIrProgress::SetText( IN TCHAR *pText )
  113. {
  114. HRESULT hr = S_OK;
  115. if (m_pPD)
  116. {
  117. #ifdef UNICODE
  118. hr = m_pPD->SetLine( 1, pText, FALSE, NULL );
  119. #else
  120. WCHAR wszText[MAX_PATH];
  121. if (!MultiByteToWideChar( CP_ACP,
  122. 0,
  123. pText,
  124. 1+strlen(pText),
  125. wszText,
  126. MAX_PATH) )
  127. {
  128. hr = HRESULT_FROM_WIN32(::GetLastError());
  129. return hr;
  130. }
  131. hr = m_pPD->SetLine( 1, wszText, FALSE, NULL );
  132. #endif
  133. }
  134. return hr;
  135. }
  136. //--------------------------------------------------------------------------
  137. // CIrProgress::StartProgressDialog()
  138. //
  139. //--------------------------------------------------------------------------
  140. HRESULT CIrProgress::StartProgressDialog()
  141. {
  142. HRESULT hr = S_OK;
  143. if (m_pPD)
  144. {
  145. DWORD dwFlags = PROGDLG_NORMAL|PROGDLG_AUTOTIME|PROGDLG_NOMINIMIZE;
  146. HRESULT hr = m_pPD->StartProgressDialog( NULL, // hwndParent
  147. NULL,
  148. dwFlags,
  149. NULL );
  150. }
  151. return hr;
  152. }
  153. //--------------------------------------------------------------------------
  154. // CIrProgress::UpdateProgressDialog()
  155. //
  156. //--------------------------------------------------------------------------
  157. HRESULT CIrProgress::UpdateProgressDialog( IN DWORD dwCompleted,
  158. IN DWORD dwTotal )
  159. {
  160. HRESULT hr = S_OK;
  161. if (m_pPD)
  162. {
  163. hr = m_pPD->SetProgress( dwCompleted, dwTotal );
  164. }
  165. return hr;
  166. }
  167. //--------------------------------------------------------------------------
  168. // CIrProgress::HasUserCancelled()
  169. //
  170. //--------------------------------------------------------------------------
  171. BOOL CIrProgress::HasUserCancelled()
  172. {
  173. if (m_pPD)
  174. {
  175. return m_pPD->HasUserCancelled();
  176. }
  177. else
  178. {
  179. return S_OK;
  180. }
  181. }
  182. //--------------------------------------------------------------------------
  183. // CIrProgress::EndProgressDialog()
  184. //
  185. //--------------------------------------------------------------------------
  186. HRESULT CIrProgress::EndProgressDialog()
  187. {
  188. HRESULT hr = S_OK;
  189. if (m_pPD)
  190. {
  191. hr = m_pPD->StopProgressDialog();
  192. }
  193. return hr;
  194. }