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.

465 lines
13 KiB

  1. /*******************************************************************************
  2. * TITLE: SSHOW.CPP
  3. * VERSION: 1.0
  4. * AUTHOR: HunterH
  5. * DATE: 11/20/2000
  6. * DESCRIPTION: SlideShow for downlevel platforms.
  7. *******************************************************************************/
  8. #include "precomp.h"
  9. #include <windows.h>
  10. #include <gdiplus.h>
  11. #include "imagescr.h"
  12. #include "scrnsave.h"
  13. #include "sshndler.h"
  14. #include "ssmprsrc.h"
  15. #include "findthrd.h"
  16. #include "FindInstance.h"
  17. #include "ssutil.h"
  18. #define MAIN_WINDOW_CLASSNAME TEXT("MySlideshowPicturesWindow")
  19. #define ID_PAINTTIMER 1
  20. #define ID_CHANGETIMER 2
  21. #define ID_TOOLBARTIMER 3
  22. #define UWM_FINDFILE (WM_USER+1301)
  23. HINSTANCE g_hInstance = NULL;
  24. // Turn Features ON
  25. #define FEATURE_FULLSCREEN_MODE
  26. class CMainWindow
  27. {
  28. private:
  29. HWND m_hWnd;
  30. CScreenSaverHandler *m_pScreenSaverHandler;
  31. public:
  32. CMainWindow( HWND hWnd )
  33. : m_hWnd(hWnd),m_pScreenSaverHandler(NULL)
  34. {
  35. }
  36. virtual ~CMainWindow(void)
  37. {
  38. }
  39. static HWND Create( DWORD dwExStyle,
  40. LPCTSTR lpWindowName,
  41. DWORD dwStyle,
  42. int x,
  43. int y,
  44. int nWidth,
  45. int nHeight,
  46. HWND hWndParent,
  47. HMENU hMenu,
  48. HINSTANCE hInstance )
  49. {
  50. RegisterClass( hInstance );
  51. return CreateWindowEx( dwExStyle,
  52. MAIN_WINDOW_CLASSNAME,
  53. lpWindowName,
  54. dwStyle,
  55. x,
  56. y,
  57. nWidth,
  58. nHeight,
  59. hWndParent,
  60. hMenu,
  61. hInstance,
  62. NULL );
  63. }
  64. static bool RegisterClass( HINSTANCE hInstance )
  65. {
  66. WNDCLASSEX wcex = {0};
  67. wcex.cbSize = sizeof(wcex);
  68. wcex.style = CS_DBLCLKS;
  69. wcex.lpfnWndProc = WndProc;
  70. wcex.hInstance = hInstance;
  71. wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION );
  72. wcex.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
  73. wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
  74. wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  75. wcex.lpszClassName = MAIN_WINDOW_CLASSNAME;
  76. BOOL res = (::RegisterClassEx(&wcex) != 0);
  77. return (res != 0);
  78. }
  79. LRESULT OnDestroy( WPARAM, LPARAM )
  80. {
  81. if (m_pScreenSaverHandler)
  82. {
  83. delete m_pScreenSaverHandler;
  84. }
  85. m_pScreenSaverHandler = NULL;
  86. PostQuitMessage(0);
  87. return 0;
  88. }
  89. LRESULT OnTimer( WPARAM wParam, LPARAM )
  90. {
  91. if (m_pScreenSaverHandler)
  92. {
  93. m_pScreenSaverHandler->HandleTimer(wParam);
  94. }
  95. return 0;
  96. }
  97. LRESULT OnPaint( WPARAM, LPARAM )
  98. {
  99. if (m_pScreenSaverHandler)
  100. {
  101. m_pScreenSaverHandler->HandlePaint();
  102. }
  103. return 0;
  104. }
  105. LRESULT OnShowWindow( WPARAM, LPARAM )
  106. {
  107. if (!m_pScreenSaverHandler)
  108. {
  109. m_pScreenSaverHandler = new CScreenSaverHandler( m_hWnd,
  110. UWM_FINDFILE,
  111. ID_PAINTTIMER,
  112. ID_CHANGETIMER,
  113. ID_TOOLBARTIMER,
  114. g_hInstance );
  115. if (m_pScreenSaverHandler)
  116. {
  117. m_pScreenSaverHandler->Initialize();
  118. }
  119. }
  120. return 0;
  121. }
  122. LRESULT OnMouseButton(WPARAM wParam, LPARAM lParam)
  123. {
  124. if (m_pScreenSaverHandler)
  125. {
  126. m_pScreenSaverHandler->HandleMouseMessage( wParam, lParam );
  127. }
  128. return 0;
  129. }
  130. LRESULT OnMouseMove(WPARAM wParam, LPARAM lParam)
  131. {
  132. if (m_pScreenSaverHandler)
  133. {
  134. m_pScreenSaverHandler->HandleMouseMove( wParam, lParam );
  135. }
  136. return 0;
  137. }
  138. LRESULT OnConfigChanged( WPARAM, LPARAM )
  139. {
  140. if (m_pScreenSaverHandler)
  141. {
  142. m_pScreenSaverHandler->HandleConfigChange();
  143. }
  144. return 0;
  145. }
  146. LRESULT OnSize(WPARAM wParam, LPARAM lParam)
  147. {
  148. if (m_pScreenSaverHandler)
  149. {
  150. m_pScreenSaverHandler->OnSize(wParam,lParam);
  151. }
  152. return 0;
  153. }
  154. LRESULT OnKeydown( WPARAM wParam, LPARAM )
  155. {
  156. if (m_pScreenSaverHandler)
  157. {
  158. m_pScreenSaverHandler->HandleKeyboardMessage( WM_KEYDOWN,
  159. static_cast<int>(wParam) );
  160. }
  161. return 0;
  162. }
  163. LRESULT OnKeyup( WPARAM wParam, LPARAM )
  164. {
  165. if (m_pScreenSaverHandler)
  166. {
  167. m_pScreenSaverHandler->HandleKeyboardMessage( WM_KEYUP,
  168. static_cast<int>(wParam) );
  169. }
  170. return 0;
  171. }
  172. LRESULT OnChar( WPARAM wParam, LPARAM )
  173. {
  174. if (m_pScreenSaverHandler)
  175. {
  176. m_pScreenSaverHandler->HandleKeyboardMessage( WM_CHAR,
  177. static_cast<int>(wParam) );
  178. }
  179. return 0;
  180. }
  181. LRESULT OnWmAppCommand( WPARAM wParam, LPARAM lParam )
  182. {
  183. if (m_pScreenSaverHandler)
  184. {
  185. m_pScreenSaverHandler->HandleOnAppCommand(wParam,lParam);
  186. }
  187. return 0;
  188. }
  189. LRESULT OnFindFile( WPARAM wParam, LPARAM lParam )
  190. {
  191. if (m_pScreenSaverHandler && lParam)
  192. {
  193. m_pScreenSaverHandler->HandleFindFile( reinterpret_cast<CFoundFileMessageData*>(lParam) );
  194. }
  195. return 0;
  196. }
  197. LRESULT OnCommand( WPARAM wParam, LPARAM lParam)
  198. {
  199. if (m_pScreenSaverHandler)
  200. {
  201. m_pScreenSaverHandler->HandleOnCommand(wParam,lParam);
  202. }
  203. return 0;
  204. }
  205. LRESULT OnNotify( WPARAM wParam, LPARAM lParam )
  206. {
  207. LPNMHDR pNMHDR = (LPNMHDR) lParam;
  208. if(pNMHDR)
  209. {
  210. }
  211. return 0;
  212. }
  213. static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  214. {
  215. CMainWindow *pThis = (CMainWindow*)GetWindowLongPtrA(hWnd,GWLP_USERDATA);
  216. if (WM_CREATE == uMsg)
  217. {
  218. pThis = new CMainWindow(hWnd);
  219. SetWindowLongA(hWnd,GWLP_USERDATA,(INT_PTR)pThis);
  220. }
  221. else if (WM_NCDESTROY == uMsg)
  222. {
  223. delete pThis;
  224. pThis = 0;
  225. SetWindowLongA(hWnd,GWLP_USERDATA,0);
  226. }
  227. switch (uMsg)
  228. {
  229. case (WM_COMMAND):
  230. {
  231. if (pThis)
  232. {
  233. return pThis->OnCommand( wParam, lParam );
  234. }
  235. }
  236. break;
  237. case (WM_SHOWWINDOW):
  238. {
  239. if (pThis)
  240. {
  241. return pThis->OnShowWindow( wParam, lParam );
  242. }
  243. }
  244. break;
  245. case (WM_DESTROY):
  246. {
  247. if (pThis)
  248. {
  249. return pThis->OnDestroy( wParam, lParam );
  250. }
  251. }
  252. break;
  253. case (WM_TIMER):
  254. {
  255. if (pThis)
  256. {
  257. return pThis->OnTimer( wParam, lParam );
  258. }
  259. }
  260. break;
  261. case (WM_PAINT):
  262. {
  263. if (pThis)
  264. {
  265. return pThis->OnPaint( wParam, lParam );
  266. }
  267. }
  268. break;
  269. case (WM_SIZE):
  270. {
  271. if (pThis)
  272. {
  273. return pThis->OnSize( wParam, lParam );
  274. }
  275. }
  276. break;
  277. case (WM_KEYDOWN):
  278. {
  279. if (pThis)
  280. {
  281. return pThis->OnKeydown( wParam, lParam );
  282. }
  283. }
  284. break;
  285. case (WM_KEYUP):
  286. {
  287. if (pThis)
  288. {
  289. return pThis->OnKeyup( wParam, lParam );
  290. }
  291. }
  292. break;
  293. case (WM_CHAR):
  294. {
  295. if (pThis)
  296. {
  297. return pThis->OnChar( wParam, lParam );
  298. }
  299. }
  300. break;
  301. case (WM_NOTIFY):
  302. {
  303. if (pThis)
  304. {
  305. return pThis->OnNotify( wParam, lParam );
  306. }
  307. }
  308. break;
  309. case (WM_LBUTTONDOWN):
  310. {
  311. if (pThis)
  312. {
  313. return pThis->OnMouseButton( wParam, lParam );
  314. }
  315. }
  316. break;
  317. case (WM_MOUSEMOVE):
  318. {
  319. if (pThis)
  320. {
  321. return pThis->OnMouseMove( wParam, lParam );
  322. }
  323. }
  324. break;
  325. case (WM_RBUTTONDOWN):
  326. {
  327. if (pThis)
  328. {
  329. return pThis->OnMouseButton( wParam, lParam );
  330. }
  331. }
  332. break;
  333. case (UWM_FINDFILE):
  334. {
  335. if (pThis)
  336. {
  337. return pThis->OnFindFile( wParam, lParam );
  338. }
  339. }
  340. break;
  341. case (WM_APPCOMMAND):
  342. {
  343. if (pThis)
  344. {
  345. return pThis->OnWmAppCommand( wParam, lParam );
  346. }
  347. }
  348. break;
  349. }
  350. return (DefWindowProcA(hWnd,uMsg,wParam,lParam));
  351. }
  352. };
  353. typedef void (CALLBACK* lpFunc)(HWND,HINSTANCE,LPTSTR,int);
  354. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpszCmdParam, int nCmdShow )
  355. {
  356. try
  357. {
  358. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | SEM_NOGPFAULTERRORBOX);
  359. // see if we've already started a copy?
  360. CFindInstance FindInstance;
  361. if(FindInstance.FindInstance(MAIN_WINDOW_CLASSNAME))
  362. {
  363. return 1;
  364. }
  365. g_hInstance = hInstance;
  366. #ifdef FEATURE_FULLSCREEN_MODE
  367. HWND hwndMain = CMainWindow::Create( 0,
  368. TEXT("My Slideshow"),
  369. WS_POPUP | WS_VISIBLE,
  370. CW_USEDEFAULT,
  371. CW_USEDEFAULT,
  372. ::GetSystemMetrics(SM_CXSCREEN),
  373. ::GetSystemMetrics(SM_CYSCREEN),
  374. NULL,
  375. NULL,
  376. hInstance );
  377. #else
  378. HWND hwndMain = CMainWindow::Create( 0,
  379. TEXT("My Slideshow"),
  380. WS_OVERLAPPEDWINDOW,
  381. CW_USEDEFAULT,
  382. CW_USEDEFAULT,
  383. CW_USEDEFAULT,
  384. CW_USEDEFAULT,
  385. NULL,
  386. NULL,
  387. hInstance );
  388. #endif
  389. if (hwndMain)
  390. {
  391. ShowWindow( hwndMain, nCmdShow );
  392. UpdateWindow( hwndMain );
  393. MSG msg;
  394. while (GetMessage(&msg, 0, 0, 0))
  395. {
  396. TranslateMessage(&msg);
  397. DispatchMessage(&msg);
  398. }
  399. }
  400. }
  401. catch(...)
  402. {
  403. }
  404. return 0;
  405. }
  406. void DebugMsg(int i, const char* pszFormat, ...)
  407. {
  408. #ifdef _DEBUG
  409. char buf[4096];
  410. sprintf(buf, "[%s](0x%x): ", "sshow", GetCurrentThreadId());
  411. va_list arglist;
  412. va_start(arglist, pszFormat);
  413. vsprintf(&buf[strlen(buf)], pszFormat, arglist);
  414. va_end(arglist);
  415. strcat(buf, "\n");
  416. OutputDebugString(buf);
  417. #endif
  418. }