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.

287 lines
5.1 KiB

  1. //
  2. // Microsoft Windows Media Technologies
  3. // Copyright (C) Microsoft Corporation, 1999 - 2001. All rights reserved.
  4. //
  5. //
  6. // This workspace contains two projects -
  7. // 1. ProgHelp which implements the Progress Interface
  8. // 2. The Sample application WmdmApp.
  9. //
  10. // ProgHelp.dll needs to be registered first for the SampleApp to run.
  11. // Includes
  12. //
  13. #include "appPCH.h"
  14. // Local functions
  15. //
  16. INT_PTR CALLBACK Progress_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  17. /////////////////////////////////////////////////////////////////////
  18. //
  19. // Function implementations
  20. //
  21. CProgress::CProgress (void )
  22. {
  23. m_hwndProgress = NULL;
  24. m_nCurrentNum = 0;
  25. m_nTotalNum = 0;
  26. m_dwCurrentBytes = 0;
  27. m_dwTotalBytes = 0;
  28. m_fCancelled = FALSE;
  29. }
  30. CProgress::~CProgress( void )
  31. {
  32. m_hwndProgress = NULL;
  33. }
  34. BOOL CProgress::Show( BOOL fShow )
  35. {
  36. // If showing the dialog, center it relative to its parent
  37. //
  38. if( fShow )
  39. {
  40. CenterWindow( m_hwndProgress, GetParent(m_hwndProgress) );
  41. // enable the cancel button
  42. EnableWindow( GetDlgItem(m_hwndProgress, IDCANCEL), TRUE );
  43. }
  44. // Show/Hide the window
  45. //
  46. ShowWindow( m_hwndProgress, (fShow ? SW_SHOW : SW_HIDE) );
  47. if( fShow )
  48. {
  49. BringWndToTop( GetParent(m_hwndProgress) );
  50. BringWndToTop( m_hwndProgress );
  51. }
  52. return TRUE;
  53. }
  54. BOOL CProgress::IsCancelled( void )
  55. {
  56. return m_fCancelled;
  57. }
  58. BOOL CProgress::Cancel( void )
  59. {
  60. BOOL fWasAlreadyCancelled = m_fCancelled;
  61. m_fCancelled = TRUE;
  62. EnableWindow( GetDlgItem(m_hwndProgress, IDCANCEL), FALSE );
  63. return fWasAlreadyCancelled;
  64. }
  65. INT_PTR CALLBACK Progress_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  66. {
  67. static CProgress *pThis = NULL;
  68. switch( uMsg )
  69. {
  70. case WM_INITDIALOG:
  71. pThis = (CProgress *)lParam;
  72. break;
  73. case WM_COMMAND:
  74. if( IDCANCEL == LOWORD(wParam) )
  75. {
  76. pThis->Cancel();
  77. }
  78. break;
  79. default:
  80. break;
  81. }
  82. return 0;
  83. }
  84. BOOL CProgress::Create( HWND hwndParent )
  85. {
  86. BOOL fRet = FALSE;
  87. if( m_hwndProgress )
  88. {
  89. Destroy();
  90. }
  91. m_hwndProgress = CreateDialogParam(
  92. g_hInst,
  93. MAKEINTRESOURCE( IDD_PROGRESS ),
  94. hwndParent,
  95. Progress_DlgProc,
  96. (LPARAM)this
  97. );
  98. if( NULL == m_hwndProgress )
  99. {
  100. return FALSE;
  101. }
  102. // Hide the window initially
  103. //
  104. ShowWindow( m_hwndProgress, SW_HIDE );
  105. m_fCancelled = FALSE;
  106. fRet = TRUE;
  107. return fRet;
  108. }
  109. VOID CProgress::Destroy( void )
  110. {
  111. if( m_hwndProgress )
  112. {
  113. DestroyWindow( m_hwndProgress );
  114. }
  115. }
  116. BOOL CProgress::SetRange( INT nMin, INT nMax )
  117. {
  118. HWND hwnd = GetDlgItem( m_hwndProgress, IDC_PB_PROGRESS );
  119. SendMessage( hwnd, PBM_SETRANGE, (WPARAM)0, (LPARAM)MAKELPARAM(nMin,nMax) );
  120. return TRUE;
  121. }
  122. BOOL CProgress::SetOperation( LPSTR lpsz )
  123. {
  124. HWND hwnd = GetDlgItem( m_hwndProgress, IDC_ST_OPERATION );
  125. SetWindowText( hwnd, lpsz );
  126. return TRUE;
  127. }
  128. BOOL CProgress::SetDetails( LPSTR lpsz )
  129. {
  130. HWND hwnd = GetDlgItem( m_hwndProgress, IDC_ST_DETAILS );
  131. SetWindowText( hwnd, lpsz );
  132. return TRUE;
  133. }
  134. BOOL CProgress::SetCount( INT nCurrentNum, INT nTotalNum )
  135. {
  136. HWND hwnd = GetDlgItem( m_hwndProgress, IDC_ST_COUNTER );
  137. char szFormat[MAX_PATH];
  138. char szCount[MAX_PATH];
  139. if( (DWORD)-1 != nCurrentNum )
  140. {
  141. m_nCurrentNum = nCurrentNum;
  142. }
  143. if( (DWORD)-1 != nTotalNum )
  144. {
  145. m_nTotalNum = nTotalNum;
  146. }
  147. if( nCurrentNum == -1 && nTotalNum == -1 )
  148. {
  149. SetWindowText( hwnd, "" );
  150. }
  151. else
  152. {
  153. LoadString( g_hInst, IDS_PROGRESS_COUNT, szFormat, sizeof(szFormat) );
  154. wsprintf( szCount, szFormat, nCurrentNum, nTotalNum );
  155. SetWindowText( hwnd, szCount );
  156. }
  157. return TRUE;
  158. }
  159. BOOL CProgress::IncCount( INT nIncrement )
  160. {
  161. SetCount( m_nCurrentNum + nIncrement, m_nTotalNum );
  162. return TRUE;
  163. }
  164. BOOL CProgress::SetPos( INT nPos )
  165. {
  166. HWND hwnd = GetDlgItem( m_hwndProgress, IDC_PB_PROGRESS );
  167. if( -1 == nPos )
  168. {
  169. // get the top limit
  170. nPos = (INT)SendMessage( hwnd, PBM_GETRANGE, (WPARAM)(BOOL)FALSE, (LPARAM)0 );
  171. }
  172. // set the position
  173. SendMessage( hwnd, PBM_SETPOS, (WPARAM)nPos, (LPARAM)0 );
  174. return TRUE;
  175. }
  176. BOOL CProgress::IncPos( INT nIncrement )
  177. {
  178. HWND hwnd = GetDlgItem( m_hwndProgress, IDC_PB_PROGRESS );
  179. // increment the position
  180. SendMessage( hwnd, PBM_DELTAPOS, (WPARAM)nIncrement, (LPARAM)0 );
  181. return TRUE;
  182. }
  183. BOOL CProgress::SetBytes( DWORD dwCurrentNum, DWORD dwTotalNum )
  184. {
  185. HWND hwnd = GetDlgItem( m_hwndProgress, IDC_ST_BYTECOUNTER );
  186. char szFormat[MAX_PATH];
  187. char szCount[MAX_PATH];
  188. if( (DWORD)-1 != dwCurrentNum )
  189. {
  190. m_dwCurrentBytes = dwCurrentNum;
  191. }
  192. if( (DWORD)-1 != dwTotalNum )
  193. {
  194. m_dwTotalBytes = dwTotalNum;
  195. }
  196. if( dwCurrentNum == -1 && dwTotalNum == -1 )
  197. {
  198. SetWindowText( hwnd, "" );
  199. }
  200. else
  201. {
  202. LoadString( g_hInst, IDS_PROGRESS_BYTECOUNT, szFormat, sizeof(szFormat) );
  203. wsprintf( szCount, szFormat, m_dwCurrentBytes/1024, m_dwTotalBytes/1024 );
  204. SetWindowText( hwnd, szCount );
  205. }
  206. return TRUE;
  207. }
  208. BOOL CProgress::IncBytes( DWORD dwIncrement )
  209. {
  210. SetBytes( m_dwCurrentBytes + dwIncrement, m_dwTotalBytes );
  211. return TRUE;
  212. }