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.

206 lines
6.0 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SSTEST.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 1/19/1999
  12. *
  13. * DESCRIPTION: Test driver for My Pictures Screensaver
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include <windows.h>
  19. #include <uicommon.h>
  20. #include <initguid.h>
  21. #include <gdiplus.h>
  22. #include "cfgdlg.h"
  23. #include "imagescr.h"
  24. #include "simcrack.h"
  25. #include "scrnsave.h"
  26. #include "ssconst.h"
  27. #include "resource.h"
  28. #include "sshndler.h"
  29. #include "ssmprsrc.h"
  30. #include "findthrd.h"
  31. #define MAIN_WINDOW_CLASSNAME TEXT("TestScreenSaverWindow")
  32. #define ID_PAINTTIMER 1
  33. #define ID_CHANGETIMER 2
  34. #define ID_STARTTIMER 3
  35. #define UWM_FINDFILE (WM_USER+1301)
  36. HINSTANCE g_hInstance;
  37. class CMainWindow
  38. {
  39. private:
  40. HWND m_hWnd;
  41. CScreenSaverHandler *m_pScreenSaverHandler;
  42. public:
  43. CMainWindow( HWND hWnd )
  44. : m_hWnd(hWnd),m_pScreenSaverHandler(NULL)
  45. {
  46. }
  47. virtual ~CMainWindow(void)
  48. {
  49. }
  50. static HWND Create( DWORD dwExStyle, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance )
  51. {
  52. RegisterClass( hInstance );
  53. return CreateWindowEx( dwExStyle, MAIN_WINDOW_CLASSNAME, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, NULL );
  54. }
  55. static bool RegisterClass( HINSTANCE hInstance )
  56. {
  57. WNDCLASSEX wcex;
  58. ZeroMemory( &wcex, sizeof(wcex) );
  59. wcex.cbSize = sizeof(wcex);
  60. wcex.style = CS_DBLCLKS;
  61. wcex.lpfnWndProc = WndProc;
  62. wcex.hInstance = hInstance;
  63. wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION );
  64. wcex.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
  65. wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
  66. wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  67. wcex.lpszClassName = MAIN_WINDOW_CLASSNAME;
  68. BOOL res = (::RegisterClassEx(&wcex) != 0);
  69. return (res != 0);
  70. }
  71. LRESULT OnDestroy( WPARAM, LPARAM )
  72. {
  73. if (m_pScreenSaverHandler)
  74. delete m_pScreenSaverHandler;
  75. m_pScreenSaverHandler = NULL;
  76. PostQuitMessage(0);
  77. return 0;
  78. }
  79. LRESULT OnTimer( WPARAM wParam, LPARAM )
  80. {
  81. if (m_pScreenSaverHandler)
  82. m_pScreenSaverHandler->HandleTimer(wParam);
  83. return 0;
  84. }
  85. LRESULT OnPaint( WPARAM, LPARAM )
  86. {
  87. if (m_pScreenSaverHandler)
  88. m_pScreenSaverHandler->HandlePaint();
  89. return 0;
  90. }
  91. LRESULT OnShowWindow( WPARAM, LPARAM )
  92. {
  93. if (!m_pScreenSaverHandler)
  94. {
  95. m_pScreenSaverHandler = new CScreenSaverHandler( m_hWnd, UWM_FINDFILE, ID_PAINTTIMER, ID_CHANGETIMER, ID_STARTTIMER, REGISTRY_PATH, g_hInstance );
  96. if (m_pScreenSaverHandler)
  97. m_pScreenSaverHandler->Initialize();
  98. }
  99. return 0;
  100. }
  101. LRESULT OnLButtonDblClk( WPARAM, LPARAM )
  102. {
  103. RegisterDialogClasses(g_hInstance);
  104. DialogBox( g_hInstance, MAKEINTRESOURCE(IDD_CONFIG_DIALOG), m_hWnd, (DLGPROC)ScreenSaverConfigureDialog );
  105. return 0;
  106. }
  107. LRESULT OnConfigChanged( WPARAM, LPARAM )
  108. {
  109. if (m_pScreenSaverHandler)
  110. m_pScreenSaverHandler->HandleConfigChanged();
  111. return 0;
  112. }
  113. LRESULT OnSize( WPARAM, LPARAM )
  114. {
  115. if (m_pScreenSaverHandler)
  116. m_pScreenSaverHandler->HandleConfigChanged();
  117. return 0;
  118. }
  119. LRESULT OnKeydown( WPARAM wParam, LPARAM )
  120. {
  121. if (m_pScreenSaverHandler)
  122. m_pScreenSaverHandler->HandleKeyboardMessage( WM_KEYDOWN, static_cast<int>(wParam) );
  123. return 0;
  124. }
  125. LRESULT OnKeyup( WPARAM wParam, LPARAM )
  126. {
  127. if (m_pScreenSaverHandler)
  128. m_pScreenSaverHandler->HandleKeyboardMessage( WM_KEYUP, static_cast<int>(wParam) );
  129. return 0;
  130. }
  131. LRESULT OnChar( WPARAM wParam, LPARAM )
  132. {
  133. if (m_pScreenSaverHandler)
  134. m_pScreenSaverHandler->HandleKeyboardMessage( WM_CHAR, static_cast<int>(wParam) );
  135. return 0;
  136. }
  137. LRESULT OnFindFile( WPARAM wParam, LPARAM lParam )
  138. {
  139. if (m_pScreenSaverHandler)
  140. m_pScreenSaverHandler->HandleFindFile( reinterpret_cast<CFoundFileMessageData*>(lParam) );
  141. return 0;
  142. }
  143. static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  144. {
  145. SC_BEGIN_MESSAGE_HANDLERS(CMainWindow)
  146. {
  147. SC_HANDLE_MESSAGE( WM_SHOWWINDOW, OnShowWindow );
  148. SC_HANDLE_MESSAGE( WM_DESTROY, OnDestroy );
  149. SC_HANDLE_MESSAGE( WM_TIMER, OnTimer );
  150. SC_HANDLE_MESSAGE( WM_PAINT, OnPaint );
  151. SC_HANDLE_MESSAGE( WM_SIZE, OnSize );
  152. SC_HANDLE_MESSAGE( WM_KEYDOWN, OnKeydown );
  153. SC_HANDLE_MESSAGE( WM_KEYUP, OnKeyup );
  154. SC_HANDLE_MESSAGE( WM_CHAR, OnChar );
  155. SC_HANDLE_MESSAGE( WM_LBUTTONDBLCLK, OnLButtonDblClk );
  156. SC_HANDLE_MESSAGE( UWM_CONFIG_CHANGED, OnConfigChanged );
  157. SC_HANDLE_MESSAGE( UWM_FINDFILE, OnFindFile );
  158. }
  159. SC_END_MESSAGE_HANDLERS();
  160. }
  161. };
  162. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow )
  163. {
  164. WIA_DEBUG_CREATE( hInstance );
  165. HRESULT hr = CoInitialize(NULL);
  166. if (SUCCEEDED(hr))
  167. {
  168. g_hInstance = hInstance;
  169. HWND hwndMain = CMainWindow::Create( 0, TEXT("My Pictures Screen Saver Test"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance );
  170. if (hwndMain)
  171. {
  172. ShowWindow( hwndMain, nCmdShow );
  173. UpdateWindow( hwndMain );
  174. MSG msg;
  175. while (GetMessage(&msg, 0, 0, 0))
  176. {
  177. TranslateMessage(&msg);
  178. DispatchMessage(&msg);
  179. }
  180. }
  181. CoUninitialize();
  182. }
  183. WIA_DEBUG_DESTROY();
  184. return 0;
  185. }