Windows NT 4.0 source code leak
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.

301 lines
7.5 KiB

4 years ago
  1. // ABRTSRCH.cpp : implementation file
  2. // This class is for the abort search dialog box.
  3. #include "stdafx.h"
  4. #include <stdlib.h>
  5. #include "ftsrch.h"
  6. #include "ABRTSRCH.h"
  7. #include "memex.h"
  8. #include "dialogs.h"
  9. #include "ftsrchlp.h"
  10. #include "CSHelp.h"
  11. #include "Except.h"
  12. // Example usage
  13. //
  14. // BOOL fAlreadySearching= !StartAbortTimer();
  15. //
  16. // while (...)
  17. // {
  18. //
  19. // CAbortSearch::CheckContinueState();
  20. //
  21. // // Do something
  22. //
  23. // }
  24. //
  25. // if (!fAlreadySearching) StopAbortTimer();
  26. //
  27. static CAbortSearch *pAbortSearch = NULL;
  28. void CAbortSearch::CheckContinueState()
  29. {
  30. pAbortSearch->ProcessContinueState();
  31. }
  32. BOOL CAbortSearch::StartAbortTimer(HINSTANCE hInst, HWND hWnd)
  33. {
  34. if (pAbortSearch) return FALSE;
  35. pAbortSearch= New CAbortSearch(hInst, IDD_ABORTSEARCH, hWnd);
  36. return TRUE;
  37. }
  38. void CAbortSearch::StopAbortTimer()
  39. {
  40. ASSERT(pAbortSearch);
  41. delete pAbortSearch; pAbortSearch= NULL;
  42. }
  43. CAbortSearch::CAbortSearch(HINSTANCE hInst, UINT uID, HWND hWnd,UINT uTimerCount, UINT uMinAnimate)
  44. {
  45. ASSERT(!pAbortSearch); // Can't have more than CAbortSearch active at the same
  46. // time!
  47. m_hInst = hInst; // Class member initialization
  48. m_ID = uID; //
  49. m_hParent = hWnd; //
  50. m_hDlg = NULL; //
  51. m_hwndFocus = NULL; //
  52. m_bTimerActive = FALSE; //
  53. m_fCanceling = FALSE;
  54. m_uTimerCount = uTimerCount; // A default of 3 seconds
  55. m_uMinAnimate = uMinAnimate; // A default minimum for animation
  56. m_hbmAnimate = NULL;
  57. m_hSrcDC = NULL;
  58. m_hbmAnimate = NULL;
  59. m_iAnimateHeight = 0;
  60. m_iAnimateWidth = 0;
  61. m_dwStartTime =
  62. m_dwLastTime = GetTickCount(); // check time for animation
  63. m_uFrame = 0; // start at first frame
  64. }
  65. CAbortSearch::~CAbortSearch()
  66. {
  67. ASSERT(pAbortSearch == this);
  68. pAbortSearch= NULL;
  69. if (m_hSrcDC) // delete our saved DC
  70. {
  71. SelectObject(m_hSrcDC,m_hbmpSave);
  72. DeleteDC(m_hSrcDC);
  73. }
  74. if (m_hbmAnimate) // Delete the animation bitmap
  75. {
  76. DeleteObject(m_hbmAnimate);
  77. m_hbmAnimate = NULL;
  78. }
  79. if (m_hDlg) { DestroyWindow(m_hDlg); m_hDlg= NULL; } // Shut the dialog down
  80. if (m_hwndFocus) ::SetFocus(m_hwndFocus);
  81. }
  82. BOOL CAbortSearch::Create()
  83. {
  84. return ((m_hDlg = ::CreateDialogParam(m_hInst,MAKEINTRESOURCE(m_ID),
  85. GetDesktopWindow(),(DLGPROC) &CAbortSearch::DlgProc,
  86. (LPARAM) this)) != NULL);
  87. }
  88. void CAbortSearch::ProcessContinueState()
  89. {
  90. extern ANIMATOR pAnimate;
  91. extern BOOL fAnimatorExternal;
  92. if (!this || fAnimatorExternal) // external animator now takes precedence
  93. {
  94. pAnimate(); // external animator takes care of timing
  95. return;
  96. }
  97. if (m_fCanceling) return;
  98. DWORD dwCurTime = GetTickCount();
  99. if (!m_bTimerActive)
  100. {
  101. if (m_uTimerCount <= dwCurTime - m_dwStartTime)
  102. {
  103. m_dwLastTime= dwCurTime;
  104. BITMAP bmp;
  105. m_hbmAnimate = LoadBitmap(m_hInst,MAKEINTRESOURCE(IDB_SEARCHING));
  106. if (!m_hbmAnimate) return;
  107. GetObject(m_hbmAnimate,sizeof(bmp),&bmp); // Get the bitmap size information
  108. m_iAnimateHeight = bmp.bmHeight;
  109. m_iAnimateWidth = bmp.bmWidth;
  110. m_bTimerActive= TRUE;
  111. m_hwndFocus= ::GetFocus();
  112. Create();
  113. // We move the focus back to the Find dialog to
  114. // avoid accidentally killing the current search.
  115. ::SetFocus(m_hwndFocus);
  116. HDC hDC = GetDC(m_hDlg);
  117. DrawNextFrame(hDC);
  118. ReleaseDC(m_hDlg,hDC);
  119. ProcessInput();
  120. }
  121. else
  122. if (dwCurTime - m_dwLastTime > m_uMinAnimate)
  123. {
  124. m_dwLastTime = dwCurTime;
  125. ProcessInput();
  126. }
  127. return; // return either way
  128. }
  129. if (dwCurTime - m_dwLastTime > m_uMinAnimate)
  130. {
  131. m_dwLastTime = dwCurTime;
  132. HDC hDC = GetDC(m_hDlg);
  133. DrawNextFrame(hDC);
  134. ReleaseDC(m_hDlg,hDC);
  135. ProcessInput();
  136. }
  137. }
  138. void CAbortSearch::DrawNextFrame(HDC hDC, BOOL fAdvance)
  139. {
  140. // Note the Height is used for both since the width can represent n frames
  141. // This means that the animations need to be square but can be any number of frames long...
  142. StretchBlt(hDC,m_rcClient.left,m_rcClient.top,m_rcClient.right,m_rcClient.bottom,
  143. m_hSrcDC,m_uFrame,0,m_iAnimateHeight,m_iAnimateHeight,SRCCOPY);
  144. if (fAdvance)
  145. {
  146. m_uFrame += m_iAnimateHeight;
  147. if (m_uFrame >= (UINT) m_iAnimateWidth) m_uFrame = 0; // Start over.
  148. }
  149. }
  150. void CAbortSearch::ProcessInput()
  151. {
  152. MSG msg;
  153. while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  154. {
  155. TranslateMessage(&msg); // Keep the buttons active
  156. DispatchMessage(&msg);
  157. }
  158. }
  159. // Private functions
  160. void CAbortSearch::OnCancel()
  161. {
  162. m_fCanceling= TRUE;
  163. RaiseException(STATUS_ABORT_SEARCH, EXCEPTION_NONCONTINUABLE, 0, NULL);
  164. }
  165. void CAbortSearch::OnInit()
  166. {
  167. LPPOINT lppnt;
  168. RECT rcParent;
  169. RECT rcDialog;
  170. UINT uX,uY;
  171. m_hwndAnimate = GetDlgItem(m_hDlg,IDC_ANIMATEFRAME);
  172. GetWindowRect(m_hParent,&rcParent); // Center in my parent
  173. GetWindowRect(m_hDlg,&rcDialog); // Center in my parent
  174. uX = rcParent.left + (((rcParent.right - rcParent.left) - (rcDialog.right - rcDialog.left)) / 2);
  175. uY = rcParent.top + (((rcParent.bottom - rcParent.top) - (rcDialog.bottom - rcDialog.top)) / 2);
  176. SetWindowPos(m_hDlg,HWND_TOPMOST,uX,uY,0,0,SWP_NOSIZE);
  177. GetWindowRect(m_hwndAnimate,&m_rcClient);
  178. lppnt = (LPPOINT) &m_rcClient;
  179. // convert to dialog screen coordinates
  180. ScreenToClient(m_hDlg,lppnt++);
  181. ScreenToClient(m_hDlg,lppnt);
  182. m_rcClient.right -= m_rcClient.left; // make it a width
  183. m_rcClient.bottom -= m_rcClient.top; // Make it a height
  184. HDC hDC = GetDC(m_hDlg);
  185. m_hSrcDC = CreateCompatibleDC(hDC);
  186. m_hbmpSave = (HBITMAP) SelectObject(m_hSrcDC,m_hbmAnimate);
  187. ReleaseDC(m_hDlg,hDC);
  188. }
  189. BOOL CALLBACK CAbortSearch::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  190. {
  191. BOOL bStatus = FALSE; // Assume we won't process the message
  192. CAbortSearch *pToMe = (CAbortSearch *) GetWindowLong(hDlg,DWL_USER);
  193. switch (uMsg)
  194. {
  195. case WM_INITDIALOG :
  196. {
  197. // if focus is set to a control return FALSE
  198. // Otherwise return TRUE;
  199. SetWindowLong(hDlg,DWL_USER,lParam);
  200. pToMe = (CAbortSearch *) lParam;
  201. pToMe->m_hDlg = hDlg;
  202. bStatus = TRUE; // did not set the focus == TRUE
  203. pToMe->OnInit();
  204. }
  205. break;
  206. case WM_PAINT:
  207. {
  208. PAINTSTRUCT ps;
  209. HDC hDC = BeginPaint(hDlg, &ps);
  210. pToMe->DrawNextFrame(hDC, FALSE);
  211. EndPaint(hDlg, &ps);
  212. }
  213. break;
  214. case WM_COMMAND :
  215. {
  216. switch(LOWORD(wParam))
  217. {
  218. case IDCANCEL :
  219. if(HIWORD(wParam) == BN_CLICKED)
  220. {
  221. pToMe->OnCancel();
  222. bStatus = TRUE;
  223. }
  224. break;
  225. }
  226. }
  227. break;
  228. }
  229. // Note do not call DefWindowProc to process unwanted window messages!
  230. return bStatus;
  231. }