Source code of Windows XP (NT5)
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.

146 lines
4.3 KiB

  1. #include "precomp.h"
  2. #include "imagescr.h"
  3. #include "waitcurs.h"
  4. #include "ssutil.h"
  5. #include "findthrd.h"
  6. #include "ssmprsrc.h"
  7. CImageScreenSaver::CImageScreenSaver( HINSTANCE hInstance,
  8. bool bToolbarVisible )
  9. :m_pPainter(NULL),
  10. m_hInstance(hInstance),
  11. m_bToolbarVisible(bToolbarVisible)
  12. {
  13. }
  14. CImageScreenSaver::~CImageScreenSaver(void)
  15. {
  16. if (m_pPainter)
  17. {
  18. delete m_pPainter;
  19. m_pPainter = NULL;
  20. }
  21. }
  22. void CImageScreenSaver::ShowToolbar(bool bFlag)
  23. {
  24. m_bToolbarVisible = bFlag;
  25. if(m_pPainter)
  26. {
  27. m_pPainter->SetToolbarVisible(bFlag);
  28. }
  29. }
  30. bool CImageScreenSaver::IsValid(void) const
  31. {
  32. return(true);
  33. }
  34. HANDLE CImageScreenSaver::Initialize( HWND hwndNotify,
  35. UINT nNotifyMessage,
  36. HANDLE hEventCancel )
  37. {
  38. HANDLE hResult = NULL;
  39. // Get the file extensions for the file types we are able to deal with
  40. CSimpleString strExtensions;
  41. m_GdiPlusHelper.ConstructDecoderExtensionSearchStrings(strExtensions);
  42. // Start the image finding thread
  43. TCHAR pBuffer[MAX_PATH] = {0};
  44. ::GetCurrentDirectory(MAX_PATH,(LPTSTR)&pBuffer);
  45. hResult = CFindFilesThread::Find((LPTSTR) pBuffer,
  46. strExtensions,
  47. hwndNotify,
  48. nNotifyMessage,
  49. hEventCancel,
  50. MAX_FAILED_FILES,
  51. MAX_SUCCESSFUL_FILES,
  52. MAX_DIRECTORIES );
  53. // Return the thread handle
  54. return hResult;
  55. }
  56. void CImageScreenSaver::OnInput()
  57. {
  58. if(m_pPainter)
  59. {
  60. m_pPainter->OnInput();
  61. }
  62. }
  63. bool CImageScreenSaver::TimerTick( CSimpleDC &ClientDC )
  64. {
  65. if (m_pPainter && ClientDC.IsValid())
  66. {
  67. return m_pPainter->TimerTick( ClientDC );
  68. }
  69. return false;
  70. }
  71. void CImageScreenSaver::Paint( CSimpleDC &PaintDC )
  72. {
  73. if (m_pPainter && PaintDC.IsValid())
  74. {
  75. m_pPainter->SetToolbarVisible(m_bToolbarVisible);
  76. m_pPainter->Paint( PaintDC );
  77. }
  78. }
  79. bool CImageScreenSaver::ReplaceImage( bool bForward, bool bNoTransition )
  80. {
  81. CSimpleString strCurrentFile;
  82. if (m_pPainter)
  83. {
  84. delete m_pPainter;
  85. m_pPainter = NULL;
  86. }
  87. if (m_FindImageFiles.Count())
  88. {
  89. // exit the loop when we get a valid image or we've exhausted the list
  90. int nNumTries = 0;
  91. while (!m_pPainter && nNumTries < m_FindImageFiles.Count())
  92. {
  93. CSimpleString strNextFile;
  94. bool bNextFile = bForward ? m_FindImageFiles.NextFile(strNextFile) : m_FindImageFiles.PreviousFile(strNextFile);
  95. if (bNextFile)
  96. {
  97. CSimpleDC ClientDC;
  98. if (ClientDC.GetDC(NULL))
  99. {
  100. CBitmapImage *pBitmapImage = new CBitmapImage;
  101. if (pBitmapImage)
  102. {
  103. if (pBitmapImage->Load( ClientDC,
  104. strNextFile,
  105. m_rcClient,
  106. MAX_SCREEN_PERCENT,
  107. ALLOW_STRECTCHING,
  108. false ))
  109. {
  110. m_pPainter = new CSimpleTransitionPainter( pBitmapImage,
  111. ClientDC,
  112. m_rcClient,
  113. m_bToolbarVisible );
  114. //
  115. // If we couldn't create a painter, delete the bitmap
  116. //
  117. if (!m_pPainter)
  118. {
  119. delete pBitmapImage;
  120. }
  121. }
  122. else
  123. {
  124. delete pBitmapImage;
  125. }
  126. }
  127. }
  128. }
  129. nNumTries++;
  130. }
  131. }
  132. return(m_pPainter != NULL);
  133. }