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.

314 lines
11 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998, 1999, 2000
  4. *
  5. * TITLE: IMAGESCR.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 1/13/1999
  12. *
  13. * DESCRIPTION: My Pictures Slideshow screen saver class
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "imagescr.h"
  19. #include "simreg.h"
  20. #include "waitcurs.h"
  21. #include "ssutil.h"
  22. #include "findthrd.h"
  23. #include "ssmprsrc.h"
  24. #include <shlobj.h>
  25. CImageScreenSaver::CImageScreenSaver( HINSTANCE hInstance, const CSimpleString &strRegistryKey )
  26. : m_pPainter(NULL),
  27. m_hInstance(hInstance),
  28. m_MyDocsScreenSaverData( HKEY_CURRENT_USER, strRegistryKey )
  29. {
  30. EnumDisplayMonitors( NULL, NULL, MonitorEnumProc, reinterpret_cast<LPARAM>(this) );
  31. }
  32. CImageScreenSaver::~CImageScreenSaver(void)
  33. {
  34. if (m_pPainter)
  35. delete m_pPainter;
  36. m_pPainter = NULL;
  37. }
  38. BOOL CALLBACK CImageScreenSaver::MonitorEnumProc( HMONITOR hMonitor, HDC hdcMonitor, LPRECT prcMonitor, LPARAM lParam )
  39. {
  40. CImageScreenSaver *pThis = reinterpret_cast<CImageScreenSaver*>(lParam);
  41. if (pThis)
  42. {
  43. if (hMonitor)
  44. {
  45. MONITORINFOEX MonitorInfoEx;
  46. ZeroMemory( &MonitorInfoEx, sizeof(MonitorInfoEx) );
  47. MonitorInfoEx.cbSize = sizeof(MonitorInfoEx);
  48. if (GetMonitorInfo( hMonitor, reinterpret_cast<MONITORINFO*>(&MonitorInfoEx)))
  49. {
  50. pThis->m_ScreenList.Append( MonitorInfoEx.rcMonitor );
  51. WIA_TRACE((TEXT("Monitor = [%s], rcMonitor = (%d,%d,%d,%d), rcWork = (%d,%d,%d,%d), dwFlags = %08X\n"),
  52. MonitorInfoEx.szDevice,
  53. MonitorInfoEx.rcMonitor.left, MonitorInfoEx.rcMonitor.top, MonitorInfoEx.rcMonitor.right, MonitorInfoEx.rcMonitor.bottom,
  54. MonitorInfoEx.rcWork.left, MonitorInfoEx.rcWork.top, MonitorInfoEx.rcWork.right, MonitorInfoEx.rcWork.bottom,
  55. MonitorInfoEx.dwFlags ));
  56. }
  57. else
  58. {
  59. WIA_TRACE((TEXT("MonitorEnumProc, GetMonitorInfo failed (%d)\n"), GetLastError()));
  60. }
  61. }
  62. else
  63. {
  64. WIA_TRACE((TEXT("MonitorEnumProc, hMonitor == NULL\n")));
  65. }
  66. }
  67. else
  68. {
  69. WIA_TRACE((TEXT("MonitorEnumProc, pThis == NULL\n")));
  70. }
  71. return TRUE;
  72. }
  73. bool CImageScreenSaver::IsValid(void) const
  74. {
  75. return(true);
  76. }
  77. HANDLE CImageScreenSaver::Initialize( HWND hwndNotify, UINT nNotifyMessage, HANDLE hEventCancel )
  78. {
  79. HANDLE hResult = NULL;
  80. //
  81. // Get the file extensions for the file types we are able to deal with
  82. //
  83. CSimpleString strExtensions;
  84. m_GdiPlusHelper.ConstructDecoderExtensionSearchStrings(strExtensions);
  85. WIA_TRACE((TEXT("strExtensions = %s"), strExtensions.String()));
  86. //
  87. // Start the image finding thread
  88. //
  89. hResult = CFindFilesThread::Find(
  90. m_MyDocsScreenSaverData.ImageDirectory(),
  91. strExtensions,
  92. hwndNotify,
  93. nNotifyMessage,
  94. hEventCancel,
  95. m_MyDocsScreenSaverData.MaxFailedFiles(),
  96. m_MyDocsScreenSaverData.MaxSuccessfulFiles(),
  97. m_MyDocsScreenSaverData.MaxDirectories()
  98. );
  99. //
  100. // Return the thread handle
  101. //
  102. return hResult;
  103. }
  104. bool CImageScreenSaver::TimerTick( CSimpleDC &ClientDC )
  105. {
  106. if (m_pPainter && ClientDC.IsValid())
  107. {
  108. return m_pPainter->TimerTick( ClientDC );
  109. }
  110. return false;
  111. }
  112. void CImageScreenSaver::Paint( CSimpleDC &PaintDC )
  113. {
  114. if (m_pPainter && PaintDC.IsValid())
  115. {
  116. m_pPainter->Paint( PaintDC );
  117. }
  118. }
  119. int CImageScreenSaver::ChangeTimerInterval(void) const
  120. {
  121. return(m_MyDocsScreenSaverData.ChangeInterval());
  122. }
  123. int CImageScreenSaver::PaintTimerInterval(void) const
  124. {
  125. return(m_MyDocsScreenSaverData.PaintInterval());
  126. }
  127. bool CImageScreenSaver::AllowKeyboardControl(void)
  128. {
  129. return(m_MyDocsScreenSaverData.AllowKeyboardControl());
  130. }
  131. bool CImageScreenSaver::ReplaceImage( bool bForward, bool bNoTransition )
  132. {
  133. CSimpleString strCurrentFile;
  134. if (m_pPainter)
  135. {
  136. delete m_pPainter;
  137. m_pPainter = NULL;
  138. }
  139. if (!m_VisibleAreaList.Size())
  140. {
  141. return false;
  142. }
  143. if (m_FindImageFiles.Count())
  144. {
  145. //
  146. // exit the loop when we get a valid image or we've exhausted the list
  147. //
  148. int nNumTries = 0;
  149. while (!m_pPainter && nNumTries < m_FindImageFiles.Count())
  150. {
  151. CSimpleString strNextFile;
  152. bool bNextFile = bForward ? m_FindImageFiles.NextFile(strNextFile) : m_FindImageFiles.PreviousFile(strNextFile);
  153. if (bNextFile)
  154. {
  155. CSimpleDC ClientDC;
  156. if (ClientDC.GetDC(NULL))
  157. {
  158. CBitmapImage *pBitmapImage = new CBitmapImage;
  159. if (pBitmapImage)
  160. {
  161. int nAreaToUse = CRandomNumberGen().Generate(0,m_VisibleAreaList.Size());
  162. RECT rcAreaToUse = m_VisibleAreaList[nAreaToUse];
  163. WIA_TRACE((TEXT("Chosen Image Area [%d] = (%d,%d), (%d,%d)"), nAreaToUse, rcAreaToUse.left, rcAreaToUse.top, rcAreaToUse.right, rcAreaToUse.bottom ));
  164. if (pBitmapImage->Load( ClientDC, strNextFile, rcAreaToUse, m_MyDocsScreenSaverData.MaxScreenPercent(), m_MyDocsScreenSaverData.AllowStretching(), m_MyDocsScreenSaverData.DisplayFilename() ))
  165. {
  166. if (m_MyDocsScreenSaverData.DisableTransitions() || bNoTransition)
  167. {
  168. m_pPainter = new CSimpleTransitionPainter( pBitmapImage, ClientDC, rcAreaToUse, m_rcClient );
  169. }
  170. else
  171. {
  172. m_pPainter = GetRandomImagePainter( pBitmapImage, ClientDC, rcAreaToUse, m_rcClient );
  173. }
  174. //
  175. // If we couldn't create a painter, delete the bitmap
  176. //
  177. if (!m_pPainter)
  178. {
  179. WIA_TRACE((TEXT("%hs (%d): Unable to create a painter\n"), __FILE__, __LINE__ ));
  180. delete pBitmapImage;
  181. }
  182. }
  183. else
  184. {
  185. WIA_TRACE((TEXT("%hs (%d): pBitmapImage->Load() failed\n"), __FILE__, __LINE__ ));
  186. delete pBitmapImage;
  187. }
  188. }
  189. else
  190. {
  191. WIA_TRACE((TEXT("%hs (%d): CImageScreenSaver::CreateImage() failed\n"), __FILE__, __LINE__ ));
  192. }
  193. }
  194. else
  195. {
  196. WIA_TRACE((TEXT("%hs (%d): ClientDC.GetDC() failed\n"), __FILE__, __LINE__ ));
  197. }
  198. }
  199. else
  200. {
  201. WIA_TRACE((TEXT("%hs (%d): m_FindImageFiles.NextFile() failed\n"), __FILE__, __LINE__ ));
  202. }
  203. nNumTries++;
  204. }
  205. }
  206. else
  207. {
  208. //
  209. // Create a new image
  210. //
  211. CBitmapImage *pBitmapImage = new CBitmapImage;
  212. if (pBitmapImage)
  213. {
  214. //
  215. // Get a desktop DC
  216. //
  217. CSimpleDC ClientDC;
  218. if (ClientDC.GetDC(NULL))
  219. {
  220. //
  221. // Figure out which screen to display the message on
  222. //
  223. RECT rcAreaToUse = m_VisibleAreaList[CRandomNumberGen().Generate(0,m_VisibleAreaList.Size())];
  224. //
  225. // Create the bitmap with an appropriate message
  226. //
  227. if (pBitmapImage->CreateFromText( CSimpleString().Format( IDS_NO_FILES_FOUND, g_hInstance, m_MyDocsScreenSaverData.ImageDirectory().String() ), rcAreaToUse, m_MyDocsScreenSaverData.MaxScreenPercent() ))
  228. {
  229. //
  230. // Create a simple painter to display it
  231. //
  232. m_pPainter = new CSimpleTransitionPainter( pBitmapImage, ClientDC, rcAreaToUse, m_rcClient );
  233. if (!m_pPainter)
  234. {
  235. //
  236. // If we couldn't get a painter, destroy the bitmap
  237. //
  238. delete pBitmapImage;
  239. }
  240. }
  241. else
  242. {
  243. //
  244. // If we couldn't create a bitmap, destroy it
  245. //
  246. delete pBitmapImage;
  247. }
  248. }
  249. }
  250. }
  251. return(m_pPainter != NULL);
  252. }
  253. CImagePainter *CImageScreenSaver::GetRandomImagePainter( CBitmapImage *pBitmapImage, CSimpleDC &dc, const RECT &rcAreaToUse, const RECT &rcClient )
  254. {
  255. CImagePainter *pPainter = NULL;
  256. int nPainter = CRandomNumberGen().Generate(0,5);
  257. if (!pPainter)
  258. {
  259. switch (nPainter)
  260. {
  261. case 0:
  262. pPainter = new CSimpleTransitionPainter( pBitmapImage, dc, rcAreaToUse, rcClient );
  263. break;
  264. case 1:
  265. pPainter = new CSlidingTransitionPainter( pBitmapImage, dc, rcAreaToUse, rcClient );
  266. break;
  267. case 2:
  268. pPainter = new CRandomBlockPainter( pBitmapImage, dc, rcAreaToUse, rcClient );
  269. break;
  270. case 3:
  271. pPainter = new CAlphaFadePainter( pBitmapImage, dc, rcAreaToUse, rcClient );
  272. break;
  273. case 4:
  274. pPainter = new COpenCurtainPainter( pBitmapImage, dc, rcAreaToUse, rcClient );
  275. break;
  276. }
  277. }
  278. if (!pPainter)
  279. {
  280. WIA_TRACE((TEXT("%hs (%d): pPainter is NULL\n"), __FILE__, __LINE__ ));
  281. return(NULL);
  282. }
  283. if (!pPainter->IsValid())
  284. {
  285. WIA_TRACE((TEXT("%hs (%d): pPainter->IsValid() == FALSE\n"), __FILE__, __LINE__ ));
  286. delete pPainter;
  287. return(NULL);
  288. }
  289. return(pPainter);
  290. }