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.

1125 lines
29 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File: cfgDlg.cpp
  4. //
  5. // Description:
  6. //
  7. // Copyright (c) 2000 Microsoft Corp.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. // App Includes
  11. #include "precomp.h"
  12. #include "resource.h"
  13. #include "main.h"
  14. #include "msprjctr.h"
  15. #include "msprjctr_i.c"
  16. #include <atlconv.h>
  17. #include <commctrl.h>
  18. #include <shlobj.h>
  19. #include <shlwapi.h>
  20. ///////////////////////////////
  21. // ErrorState_Enum
  22. //
  23. typedef enum
  24. {
  25. ErrorState_NONE = 0,
  26. ErrorState_IMAGE_DIR_DOESNT_EXIST = 1,
  27. ErrorState_DEVICE_DIR_DOESNT_EXIST = 2,
  28. ErrorState_SLIDESHOW_SERVER_NOT_FOUND = 3,
  29. ErrorState_FAILED_TO_START_SLIDESHOW = 4
  30. } ErrorState_Enum;
  31. ///////////////////////////
  32. // GVAR_LOCAL
  33. //
  34. // Global Variable
  35. //
  36. static struct GVAR_LOCAL
  37. {
  38. HINSTANCE hInstance;
  39. HWND hwndMain;
  40. ErrorState_Enum ErrorState;
  41. TCHAR szImagePath[MAX_PATH];
  42. } GVAR_LOCAL =
  43. {
  44. NULL,
  45. NULL,
  46. ErrorState_NONE
  47. };
  48. ///////////////////////////////
  49. // GVAR_pSlideshowProjector
  50. //
  51. CComPtr<IUPnPDeviceProvider> GVAR_pProjector;
  52. // Custom user message
  53. #define WM_USER_TASKBAR WM_USER + 100
  54. ////////////////////////// Function Prototypes ////////////////////////////////
  55. INT_PTR CALLBACK DlgProc(HWND hwndDlg,
  56. UINT uiMsg,
  57. WPARAM wParam,
  58. LPARAM lParam);
  59. static int InitDlg(HWND hwndDlg);
  60. static int ProcessWMCommand(HWND hwndDlg,
  61. UINT uiMsg,
  62. WPARAM wParam,
  63. LPARAM lParam);
  64. static int ProcessTaskbarMsg(HWND hwnd,
  65. UINT uiMessage,
  66. WPARAM wParam,
  67. LPARAM lParam);
  68. static int ProcessScroll(HWND hwndDlg,
  69. HWND hwndScroll);
  70. static HRESULT LoadCurrentSettings();
  71. static HRESULT SaveCurrentSettings();
  72. static HRESULT ShowConfigWindow();
  73. static BOOL IsChecked(INT iResID);
  74. static void ProcessError(ErrorState_Enum ErrorState);
  75. static HRESULT SetImageFreqTrackbar(DWORD dwImageFreq);
  76. static HRESULT SetImageScaleTrackbar(DWORD dwImageScaleFactor);
  77. static void EnableApplyButton(BOOL bEnable);
  78. static HRESULT GetFirstSlideshowService(ISlideshowService **ppSlideshowService,
  79. ISlideshowAlbum **ppSlideshowAlbum);
  80. //////////////////////////////
  81. // CfgDlg::Init
  82. //
  83. HRESULT CfgDlg::Init(HINSTANCE hInstance)
  84. {
  85. HRESULT hr = S_OK;
  86. TCHAR szImageDir[_MAX_PATH + 1] = {0};
  87. TCHAR szDeviceDir[_MAX_PATH + 1] = {0};
  88. GVAR_LOCAL.hInstance = hInstance;
  89. if (SUCCEEDED(hr))
  90. {
  91. hr = CoCreateInstance(CLSID_Projector,
  92. NULL,
  93. CLSCTX_INPROC_SERVER,
  94. IID_IUPnPDeviceProvider,
  95. (void**) &GVAR_pProjector);
  96. if (FAILED(hr))
  97. {
  98. DBG_ERR(("Failed to CoCreate CLSID_SlideshowDevice. Is the "
  99. "server DLL registered?, hr = 0x%08lx",
  100. hr));
  101. GVAR_LOCAL.ErrorState = ErrorState_SLIDESHOW_SERVER_NOT_FOUND;
  102. }
  103. }
  104. ASSERT(GVAR_pProjector != NULL);
  105. return hr;
  106. }
  107. //////////////////////////////
  108. // CfgDlg::Term
  109. //
  110. HRESULT CfgDlg::Term()
  111. {
  112. HRESULT hr = S_OK;
  113. return hr;
  114. }
  115. //////////////////////////////
  116. // CfgDlg::Create
  117. //
  118. HWND CfgDlg::Create(int nCmdShow)
  119. {
  120. HWND hwnd = CreateDialog(GVAR_LOCAL.hInstance,
  121. MAKEINTRESOURCE(IDD_CONFIG_DIALOG),
  122. NULL,
  123. DlgProc);
  124. // this is set in InitDlg
  125. if (GVAR_LOCAL.hwndMain != NULL)
  126. {
  127. Tray::Init(GVAR_LOCAL.hInstance,
  128. GVAR_LOCAL.hwndMain,
  129. WM_USER_TASKBAR);
  130. ::ShowWindow(GVAR_LOCAL.hwndMain, nCmdShow);
  131. }
  132. return GVAR_LOCAL.hwndMain;
  133. }
  134. //////////////////////////////
  135. // ProcessError
  136. //
  137. static void ProcessError(ErrorState_Enum ErrorState)
  138. {
  139. HRESULT hr = S_OK;
  140. TCHAR szErrMsg[255 + 1] = {0};
  141. TCHAR szCaption[63 + 1] = {0};
  142. if (ErrorState == ErrorState_NONE)
  143. {
  144. return;
  145. }
  146. Util::GetString(GVAR_LOCAL.hInstance,
  147. IDS_ERR_CAPTION,
  148. szCaption,
  149. sizeof(szCaption) / sizeof(TCHAR));
  150. if (ErrorState == ErrorState_SLIDESHOW_SERVER_NOT_FOUND)
  151. {
  152. Util::GetString(GVAR_LOCAL.hInstance,
  153. IDS_ERR_SLIDESHOW_SERVER_NOT_FOUND,
  154. szErrMsg,
  155. sizeof(szErrMsg) / sizeof(TCHAR));
  156. }
  157. else if (ErrorState == ErrorState_FAILED_TO_START_SLIDESHOW)
  158. {
  159. Util::GetString(GVAR_LOCAL.hInstance,
  160. IDS_ERR_FAILED_TO_START_SLIDESHOW,
  161. szErrMsg,
  162. sizeof(szErrMsg) / sizeof(TCHAR));
  163. }
  164. else
  165. {
  166. Util::GetString(GVAR_LOCAL.hInstance,
  167. IDS_ERR_SERVER_ERROR,
  168. szErrMsg,
  169. sizeof(szErrMsg) / sizeof(TCHAR));
  170. }
  171. MessageBox(GVAR_LOCAL.hwndMain,
  172. szErrMsg,
  173. szCaption,
  174. MB_ICONERROR | MB_OK);
  175. return;
  176. }
  177. //////////////////////////////
  178. // InitDlg
  179. //
  180. static int InitDlg(HWND hwndDlg)
  181. {
  182. HRESULT hr = S_OK;
  183. GVAR_LOCAL.hwndMain = hwndDlg;
  184. //
  185. // set the image frequency trackbar range.
  186. //
  187. SendDlgItemMessage(hwndDlg,
  188. IDC_FREQUENCY,
  189. TBM_SETRANGE,
  190. (WPARAM) TRUE,
  191. (LPARAM) MAKELONG(MIN_IMAGE_FREQ_IN_SEC, MAX_IMAGE_FREQ_IN_SEC));
  192. //
  193. // set the image scale factor range.
  194. //
  195. SendDlgItemMessage(hwndDlg,
  196. IDC_MAX_SIZE,
  197. TBM_SETRANGE,
  198. (WPARAM) TRUE,
  199. (LPARAM) MAKELONG(MIN_IMAGE_SCALE_FACTOR, MAX_IMAGE_SCALE_FACTOR));
  200. // these are just initial settings in case we fail to load the last
  201. // saved settings.
  202. //
  203. SetImageFreqTrackbar(MIN_IMAGE_FREQ_IN_SEC);
  204. SetImageScaleTrackbar(MAX_IMAGE_SCALE_FACTOR);
  205. if (GVAR_LOCAL.ErrorState == ErrorState_NONE)
  206. {
  207. if (GVAR_pProjector)
  208. {
  209. BSTR bstrInitString = SysAllocString(L"");
  210. // Start the Projector!
  211. hr = GVAR_pProjector->Start(bstrInitString);
  212. if (bstrInitString)
  213. {
  214. ::SysFreeString(bstrInitString);
  215. bstrInitString = NULL;
  216. }
  217. if (FAILED(hr))
  218. {
  219. GVAR_LOCAL.ErrorState = ErrorState_FAILED_TO_START_SLIDESHOW;
  220. }
  221. }
  222. if (SUCCEEDED(hr))
  223. {
  224. LoadCurrentSettings();
  225. }
  226. }
  227. ProcessError(GVAR_LOCAL.ErrorState);
  228. return 0;
  229. }
  230. //////////////////////////////
  231. // TermDlg
  232. //
  233. static bool TermDlg()
  234. {
  235. HRESULT hr = S_OK;
  236. if (GVAR_pProjector)
  237. {
  238. // Stop the projector
  239. //
  240. GVAR_pProjector->Stop();
  241. }
  242. Tray::Term(GVAR_LOCAL.hwndMain);
  243. DestroyWindow(GVAR_LOCAL.hwndMain);
  244. return true;
  245. }
  246. //////////////////////////////
  247. // DlgProc
  248. //
  249. INT_PTR CALLBACK DlgProc(HWND hwndDlg,
  250. UINT uiMsg,
  251. WPARAM wParam,
  252. LPARAM lParam)
  253. {
  254. int iReturn = 0;
  255. switch(uiMsg)
  256. {
  257. case WM_INITDIALOG:
  258. // intialize the controls on the dialog.
  259. InitDlg(hwndDlg);
  260. iReturn = TRUE;
  261. break;
  262. case WM_CLOSE:
  263. // rather than closing the window when the user hits the
  264. // X, we hide it, thereby keeping the taskbar icon.
  265. ShowWindow(hwndDlg, SW_HIDE);
  266. break;
  267. case WM_DESTROY:
  268. // if we are destroying the window, then lets
  269. // exit the app.
  270. ::PostQuitMessage(0);
  271. break;
  272. case WM_COMMAND:
  273. iReturn = ProcessWMCommand(hwndDlg,
  274. uiMsg,
  275. wParam,
  276. lParam);
  277. break;
  278. case WM_USER_TASKBAR:
  279. iReturn = ProcessTaskbarMsg(hwndDlg,
  280. uiMsg,
  281. wParam,
  282. lParam);
  283. break;
  284. case WM_HSCROLL:
  285. ProcessScroll(hwndDlg, (HWND) lParam);
  286. break;
  287. default:
  288. iReturn = 0;
  289. break;
  290. }
  291. return iReturn;
  292. }
  293. ///////////////////////////////
  294. // ProcessWMCommand
  295. //
  296. static int ProcessWMCommand(HWND hwndDlg,
  297. UINT uiMsg,
  298. WPARAM wParam,
  299. LPARAM lParam)
  300. {
  301. int iReturn = 0;
  302. int iControlID = LOWORD(wParam);
  303. int iNotifyCode = HIWORD(wParam);
  304. switch (iControlID)
  305. {
  306. case IDOK:
  307. // the user hit the OK button, save the setting changes
  308. // they made, and hide the window.
  309. SaveCurrentSettings();
  310. ShowWindow(hwndDlg, SW_HIDE);
  311. break;
  312. case IDCANCEL:
  313. // abandoning changes made by the user.
  314. ShowWindow(hwndDlg, SW_HIDE);
  315. EnableApplyButton(FALSE);
  316. break;
  317. case IDC_APPLY:
  318. // the user hit the APPLY button, save the setting changes
  319. // they made, but don't hide the window
  320. SaveCurrentSettings();
  321. break;
  322. case IDC_ALLOWSTRETCHING:
  323. case IDC_DISPLAYFILENAME:
  324. case IDC_ALLOW_KEYBOARDCONTROL:
  325. EnableApplyButton(TRUE);
  326. break;
  327. case IDM_POPUP_OPEN:
  328. ShowConfigWindow();
  329. break;
  330. case IDM_POPUP_EXIT:
  331. TermDlg();
  332. break;
  333. case IDC_BROWSE:
  334. {
  335. TCHAR szTitle[127 + 1] = {0};
  336. bool bNewDirSelected = false;
  337. LoadString(GVAR_LOCAL.hInstance,
  338. IDS_PLEASE_SELECT_IMAGE_DIR,
  339. szTitle,
  340. sizeof(szTitle) / sizeof(TCHAR));
  341. // popup the browse for directories dialog.
  342. // On return this dialog returns the directory selected
  343. // by the user.
  344. bNewDirSelected = Util::BrowseForDirectory(hwndDlg,
  345. szTitle,
  346. GVAR_LOCAL.szImagePath,
  347. sizeof(GVAR_LOCAL.szImagePath) / sizeof(TCHAR));
  348. if (bNewDirSelected)
  349. {
  350. HDC hDC = NULL;
  351. TCHAR szImageDir[MAX_PATH + 1] = {0};
  352. RECT rc = {0};
  353. _tcsncpy(szImageDir,
  354. GVAR_LOCAL.szImagePath,
  355. sizeof(szImageDir) / sizeof(TCHAR));
  356. hDC = GetDC(GetDlgItem(GVAR_LOCAL.hwndMain, IDC_IMAGEDIR));
  357. GetClientRect(GetDlgItem(GVAR_LOCAL.hwndMain, IDC_IMAGEDIR), &rc);
  358. PathCompactPath(hDC, szImageDir, rc.right - rc.left);
  359. SetDlgItemText(GVAR_LOCAL.hwndMain,
  360. IDC_IMAGEDIR,
  361. szImageDir);
  362. if (hDC)
  363. {
  364. ReleaseDC(GetDlgItem(GVAR_LOCAL.hwndMain, IDC_IMAGEDIR), hDC);
  365. hDC = NULL;
  366. }
  367. EnableApplyButton(TRUE);
  368. }
  369. }
  370. break;
  371. default:
  372. break;
  373. }
  374. return iReturn;
  375. }
  376. //////////////////////////////////////////////////////////////////////
  377. // ProcessTaskbarMsg
  378. //
  379. // Desc: Function is called when there is an event at the taskbar
  380. //
  381. //
  382. // Params: - hwnd, handle of main window.
  383. // - uiMessage, message sent.
  384. static int ProcessTaskbarMsg(HWND hwnd,
  385. UINT uiMessage,
  386. WPARAM wParam,
  387. LPARAM lParam)
  388. {
  389. int iReturn = 0;
  390. UINT uID;
  391. UINT uMouseMsg;
  392. uID = (UINT) wParam;
  393. uMouseMsg = (UINT) lParam;
  394. // remove unref param warning
  395. uiMessage = uiMessage;
  396. switch (uMouseMsg)
  397. {
  398. case WM_LBUTTONDBLCLK:
  399. ShowConfigWindow();
  400. break;
  401. case WM_LBUTTONDOWN:
  402. break;
  403. case WM_RBUTTONDOWN:
  404. Tray::PopupMenu(hwnd);
  405. break;
  406. }
  407. return iReturn;
  408. }
  409. ///////////////////////////////
  410. // ShowConfigWindow
  411. //
  412. static int ProcessScroll(HWND hwndDlg,
  413. HWND hwndScroll)
  414. {
  415. ASSERT(hwndScroll != NULL);
  416. int iReturn = 0;
  417. HRESULT hr = S_OK;
  418. TCHAR szString[255 + 1] = {0};
  419. if (hwndScroll == NULL)
  420. {
  421. return E_INVALIDARG;
  422. }
  423. if (GetDlgItem(hwndDlg, IDC_FREQUENCY) == hwndScroll)
  424. {
  425. UINT nFrequency = (UINT)SendDlgItemMessage(hwndDlg,
  426. IDC_FREQUENCY,
  427. TBM_GETPOS,
  428. 0, 0 );
  429. SetImageFreqTrackbar(nFrequency);
  430. hr = Util::FormatTime(GVAR_LOCAL.hInstance,
  431. nFrequency,
  432. szString,
  433. sizeof(szString) / sizeof(TCHAR));
  434. SendDlgItemMessage(hwndDlg,
  435. IDC_MINUTES_AND_SECONDS,
  436. WM_SETTEXT,
  437. 0,
  438. (LPARAM) szString);
  439. }
  440. else if (GetDlgItem(hwndDlg, IDC_MAX_SIZE) == hwndScroll)
  441. {
  442. UINT nScaleFactor = (UINT)SendDlgItemMessage(hwndDlg,
  443. IDC_MAX_SIZE,
  444. TBM_GETPOS,
  445. 0, 0 );
  446. SetImageScaleTrackbar(nScaleFactor);
  447. }
  448. EnableApplyButton(TRUE);
  449. return iReturn;
  450. }
  451. ///////////////////////////////
  452. // ShowConfigWindow
  453. //
  454. static HRESULT ShowConfigWindow()
  455. {
  456. HRESULT hr = S_OK;
  457. // reload our settings from the DLL to ensure that
  458. // we are reflecting the real state of the settings.
  459. LoadCurrentSettings();
  460. // popup the window on double click.
  461. ShowWindow(GVAR_LOCAL.hwndMain,
  462. SW_SHOW);
  463. // make sure we are the foreground window.
  464. SetForegroundWindow(GVAR_LOCAL.hwndMain);
  465. return hr;
  466. }
  467. ///////////////////////////////
  468. // IsChecked
  469. //
  470. static BOOL IsChecked(INT iResID)
  471. {
  472. LRESULT lState = 0;
  473. BOOL bChecked = TRUE;
  474. // Get the Display File Name
  475. lState = SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  476. iResID,
  477. BM_GETCHECK,
  478. 0,
  479. 0);
  480. if (lState == BST_CHECKED)
  481. {
  482. bChecked = TRUE;
  483. }
  484. else
  485. {
  486. bChecked = FALSE;
  487. }
  488. return bChecked;
  489. }
  490. ///////////////////////////////
  491. // SetImageFreqTrackbar
  492. //
  493. static HRESULT SetImageFreqTrackbar(DWORD dwImageFreq)
  494. {
  495. HRESULT hr = S_OK;
  496. if (SUCCEEDED(hr))
  497. {
  498. TCHAR szTime[255 + 1] = {0};
  499. // set the trackbar's current position.
  500. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  501. IDC_FREQUENCY,
  502. TBM_SETPOS,
  503. (WPARAM) TRUE,
  504. (LPARAM) dwImageFreq);
  505. hr = Util::FormatTime(GVAR_LOCAL.hInstance,
  506. dwImageFreq,
  507. szTime,
  508. sizeof(szTime) / sizeof(TCHAR));
  509. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  510. IDC_MINUTES_AND_SECONDS,
  511. WM_SETTEXT,
  512. 0,
  513. (LPARAM) szTime);
  514. }
  515. return hr;
  516. }
  517. ///////////////////////////////
  518. // SetImageScaleTrackbar
  519. //
  520. static HRESULT SetImageScaleTrackbar(DWORD dwImageScaleFactor)
  521. {
  522. HRESULT hr = S_OK;
  523. //
  524. // Set Image Scale Factor Trackbar
  525. //
  526. if (SUCCEEDED(hr))
  527. {
  528. TCHAR szScale[255 + 1] = {0};
  529. // set the trackbar's current position.
  530. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  531. IDC_MAX_SIZE,
  532. TBM_SETPOS,
  533. (WPARAM) TRUE,
  534. (LPARAM) dwImageScaleFactor);
  535. hr = Util::FormatScale(GVAR_LOCAL.hInstance,
  536. dwImageScaleFactor,
  537. szScale,
  538. sizeof(szScale) / sizeof(TCHAR));
  539. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  540. IDC_IMAGE_SIZE_DESC,
  541. WM_SETTEXT,
  542. 0,
  543. (LPARAM) szScale);
  544. }
  545. return hr;
  546. }
  547. ///////////////////////////////
  548. // EnableApplyButton
  549. //
  550. static void EnableApplyButton(BOOL bEnable)
  551. {
  552. EnableWindow(GetDlgItem(GVAR_LOCAL.hwndMain, IDC_APPLY), bEnable);
  553. }
  554. ///////////////////////////////
  555. // GetFirstSlideshowService
  556. //
  557. static HRESULT GetFirstSlideshowService(ISlideshowService **ppSlideshowService,
  558. ISlideshowAlbum **ppSlideshowAlbum)
  559. {
  560. ASSERT(ppSlideshowService != NULL);
  561. HRESULT hr = S_OK;
  562. IEnumAlbums *pEnum = NULL;
  563. IAlbumManager *pAlbumManager = NULL;
  564. if (GVAR_pProjector == NULL)
  565. {
  566. hr = E_FAIL;
  567. CHECK_S_OK2(hr, ("GetFirstSlideshowService received a NULL pointer"));
  568. return hr;
  569. }
  570. if (hr == S_OK)
  571. {
  572. hr = GVAR_pProjector->QueryInterface(IID_IAlbumManager, (void**)&pAlbumManager);
  573. }
  574. if (hr == S_OK)
  575. {
  576. hr = pAlbumManager->EnumAlbums(&pEnum);
  577. }
  578. if (hr == S_OK)
  579. {
  580. hr = pEnum->Reset();
  581. }
  582. if (hr == S_OK)
  583. {
  584. ISlideshowAlbum *pSlideshowAlbum = NULL;
  585. DWORD dwFetched = 0;
  586. hr = pEnum->Next(1, &pSlideshowAlbum, &dwFetched);
  587. if (hr == S_OK)
  588. {
  589. if (ppSlideshowService)
  590. {
  591. hr = pSlideshowAlbum->QueryInterface(IID_ISlideshowService,
  592. (void**) ppSlideshowService);
  593. }
  594. if (ppSlideshowAlbum)
  595. {
  596. hr = pSlideshowAlbum->QueryInterface(IID_ISlideshowAlbum,
  597. (void**) ppSlideshowAlbum);
  598. }
  599. if (pSlideshowAlbum)
  600. {
  601. pSlideshowAlbum->Release();
  602. pSlideshowAlbum = NULL;
  603. }
  604. }
  605. }
  606. if (pEnum)
  607. {
  608. pEnum->Release();
  609. pEnum = NULL;
  610. }
  611. if (pAlbumManager)
  612. {
  613. pAlbumManager->Release();
  614. pAlbumManager = NULL;
  615. }
  616. return hr;
  617. }
  618. ///////////////////////////////
  619. // LoadCurrentSettings
  620. //
  621. static HRESULT LoadCurrentSettings()
  622. {
  623. USES_CONVERSION;
  624. HRESULT hr = S_OK;
  625. long lImageFreq = 0;
  626. long lImageScaleFactor = 0;
  627. TCHAR szImageDir[_MAX_PATH + 1] = {0};
  628. BOOL bShowFileName = FALSE;
  629. BOOL bAllowKeyControl = FALSE;
  630. BOOL bStretchSmallImages = FALSE;
  631. BSTR bstrImageDir = NULL;
  632. ISlideshowService *pSlideshowService = NULL;
  633. ISlideshowAlbum *pSlideshowAlbum = NULL;
  634. ASSERT(GVAR_pProjector != NULL);
  635. if (GVAR_pProjector == NULL)
  636. {
  637. DBG_ERR(("InitDlg, failed to get Image Frequency, slide show "
  638. "projector object doesn't exist"));
  639. return 0;
  640. }
  641. hr = GetFirstSlideshowService(&pSlideshowService, &pSlideshowAlbum);
  642. if (hr != S_OK)
  643. {
  644. hr = E_FAIL;
  645. CHECK_S_OK2(hr, ("LoadCurrentSettings, failed to get first Slideshow Service"));
  646. return hr;
  647. }
  648. //
  649. // Get the Image Frequency
  650. //
  651. hr = pSlideshowService->get_ImageFrequency(&lImageFreq);
  652. if (SUCCEEDED(hr))
  653. {
  654. if (lImageFreq < MIN_IMAGE_FREQ_IN_SEC)
  655. {
  656. lImageFreq = MIN_IMAGE_FREQ_IN_SEC;
  657. hr = pSlideshowService->put_ImageFrequency(lImageFreq);
  658. }
  659. else if (lImageFreq > MAX_IMAGE_FREQ_IN_SEC)
  660. {
  661. lImageFreq = MAX_IMAGE_FREQ_IN_SEC;
  662. hr = pSlideshowService->put_ImageFrequency(lImageFreq);
  663. }
  664. }
  665. //
  666. // Set Image Frequency Trackbar
  667. //
  668. if (SUCCEEDED(hr))
  669. {
  670. SetImageFreqTrackbar((DWORD) lImageFreq);
  671. }
  672. //
  673. // Get the Image Scale Factor
  674. //
  675. hr = pSlideshowService->get_ImageScaleFactor(&lImageScaleFactor);
  676. if (SUCCEEDED(hr))
  677. {
  678. if (lImageScaleFactor < MIN_IMAGE_SCALE_FACTOR)
  679. {
  680. lImageScaleFactor = MIN_IMAGE_SCALE_FACTOR;
  681. hr = pSlideshowService->put_ImageScaleFactor(lImageScaleFactor);
  682. }
  683. else if (lImageScaleFactor > MAX_IMAGE_SCALE_FACTOR)
  684. {
  685. lImageScaleFactor = MAX_IMAGE_SCALE_FACTOR;
  686. hr = pSlideshowService->put_ImageScaleFactor(lImageScaleFactor);
  687. }
  688. }
  689. //
  690. // Set Image Scale Factor Trackbar
  691. //
  692. if (SUCCEEDED(hr))
  693. {
  694. SetImageScaleTrackbar((DWORD)lImageScaleFactor);
  695. }
  696. //
  697. // Get the current Image Directory
  698. //
  699. hr = pSlideshowAlbum->get_ImagePath(&bstrImageDir);
  700. // set the edit control's image directory to reflect the current
  701. // image directory.
  702. if (SUCCEEDED(hr))
  703. {
  704. HDC hDC = NULL;
  705. TCHAR szImageDir[MAX_PATH + 1] = {0};
  706. RECT rc = {0};
  707. _tcsncpy(szImageDir,
  708. OLE2T(bstrImageDir),
  709. sizeof(szImageDir) / sizeof(TCHAR));
  710. _tcsncpy(GVAR_LOCAL.szImagePath,
  711. OLE2T(bstrImageDir),
  712. sizeof(GVAR_LOCAL.szImagePath) / sizeof(TCHAR));
  713. hDC = GetDC(GetDlgItem(GVAR_LOCAL.hwndMain, IDC_IMAGEDIR));
  714. GetClientRect(GetDlgItem(GVAR_LOCAL.hwndMain, IDC_IMAGEDIR), &rc);
  715. PathCompactPath(hDC, szImageDir, rc.right - rc.left);
  716. SetDlgItemText(GVAR_LOCAL.hwndMain,
  717. IDC_IMAGEDIR,
  718. szImageDir);
  719. if (hDC)
  720. {
  721. ReleaseDC(GetDlgItem(GVAR_LOCAL.hwndMain, IDC_IMAGEDIR), hDC);
  722. hDC = NULL;
  723. }
  724. }
  725. if (bstrImageDir)
  726. {
  727. ::SysFreeString(bstrImageDir);
  728. bstrImageDir = NULL;
  729. }
  730. //
  731. // get the "ShowFilename" attribute
  732. //
  733. hr = pSlideshowService->get_ShowFileName(&bShowFileName);
  734. // set the ShowFileName checkbox
  735. if (SUCCEEDED(hr))
  736. {
  737. if (bShowFileName)
  738. {
  739. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  740. IDC_DISPLAYFILENAME,
  741. BM_SETCHECK,
  742. BST_CHECKED,
  743. 0);
  744. }
  745. else
  746. {
  747. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  748. IDC_DISPLAYFILENAME,
  749. BM_SETCHECK,
  750. BST_UNCHECKED,
  751. 0);
  752. }
  753. }
  754. //
  755. // get the "AllowKeyControl" attribute
  756. //
  757. hr = pSlideshowService->get_AllowKeyControl(&bAllowKeyControl);
  758. // set the Allow Keyboard Control checkbox
  759. if (SUCCEEDED(hr))
  760. {
  761. if (bAllowKeyControl)
  762. {
  763. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  764. IDC_ALLOW_KEYBOARDCONTROL,
  765. BM_SETCHECK,
  766. BST_CHECKED,
  767. 0);
  768. }
  769. else
  770. {
  771. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  772. IDC_ALLOW_KEYBOARDCONTROL,
  773. BM_SETCHECK,
  774. BST_UNCHECKED,
  775. 0);
  776. }
  777. }
  778. //
  779. // get the "StretchSmallImages" attribute
  780. //
  781. hr = pSlideshowService->get_StretchSmallImages(&bStretchSmallImages);
  782. // set the Stretch Small Images Control checkbox
  783. if (SUCCEEDED(hr))
  784. {
  785. if (bStretchSmallImages)
  786. {
  787. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  788. IDC_ALLOWSTRETCHING,
  789. BM_SETCHECK,
  790. BST_CHECKED,
  791. 0);
  792. }
  793. else
  794. {
  795. SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  796. IDC_ALLOWSTRETCHING,
  797. BM_SETCHECK,
  798. BST_UNCHECKED,
  799. 0);
  800. }
  801. }
  802. if (pSlideshowService)
  803. {
  804. pSlideshowService->Release();
  805. pSlideshowService = NULL;
  806. }
  807. if (pSlideshowAlbum)
  808. {
  809. pSlideshowAlbum->Release();
  810. pSlideshowAlbum = NULL;
  811. }
  812. return hr;
  813. }
  814. ///////////////////////////////
  815. // SaveCurrentSettings
  816. //
  817. static HRESULT SaveCurrentSettings()
  818. {
  819. HRESULT hr = S_OK;
  820. DWORD_PTR dwImageFreq = 0;
  821. DWORD_PTR dwImageScaleFactor = 0;
  822. BOOL bShowFileName = FALSE;
  823. BOOL bAllowKeyControl = FALSE;
  824. BOOL bStretchSmallImages = FALSE;
  825. LONG lState = 0;
  826. ISlideshowService *pSlideshowService = NULL;
  827. ISlideshowAlbum *pSlideshowAlbum = NULL;
  828. ASSERT(GVAR_pProjector != NULL);
  829. hr = GetFirstSlideshowService(&pSlideshowService, &pSlideshowAlbum);
  830. if (hr != S_OK)
  831. {
  832. hr = E_FAIL;
  833. CHECK_S_OK2(hr, ("LoadCurrentSettings, failed to get first Slideshow Service"));
  834. return hr;
  835. }
  836. //
  837. // get the image frequency trackbar value
  838. //
  839. dwImageFreq = (DWORD_PTR) SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  840. IDC_FREQUENCY,
  841. TBM_GETPOS,
  842. 0,
  843. 0);
  844. //
  845. // get the image scale factor trackbar value
  846. //
  847. dwImageScaleFactor = (DWORD_PTR) SendDlgItemMessage(GVAR_LOCAL.hwndMain,
  848. IDC_MAX_SIZE,
  849. TBM_GETPOS,
  850. 0,
  851. 0);
  852. // Get the Display File Name
  853. bShowFileName = IsChecked(IDC_DISPLAYFILENAME);
  854. // Get the Allow Key Control
  855. bAllowKeyControl = IsChecked(IDC_ALLOW_KEYBOARDCONTROL);
  856. // Get the Stretch Small Images
  857. bStretchSmallImages = IsChecked(IDC_ALLOWSTRETCHING);
  858. //
  859. // set the image frequency
  860. //
  861. hr = pSlideshowService->put_ImageFrequency((DWORD) dwImageFreq);
  862. if (FAILED(hr))
  863. {
  864. DBG_ERR(("SaveCurrentSettings, failed to set image frequency"));
  865. }
  866. //
  867. // set the image scale factor
  868. //
  869. hr = pSlideshowService->put_ImageScaleFactor((DWORD) dwImageScaleFactor);
  870. if (FAILED(hr))
  871. {
  872. DBG_ERR(("SaveCurrentSettings, failed to set image scale factor"));
  873. }
  874. //
  875. // put the show file name attribute
  876. //
  877. hr = pSlideshowService->put_ShowFileName(bShowFileName);
  878. if (FAILED(hr))
  879. {
  880. DBG_ERR(("SaveCurrentSettings, failed to set show filename property"));
  881. }
  882. //
  883. // put the allow key control attribute
  884. //
  885. hr = pSlideshowService->put_AllowKeyControl(bAllowKeyControl);
  886. if (FAILED(hr))
  887. {
  888. DBG_ERR(("SaveCurrentSettings, failed to set Allow Key Control property"));
  889. }
  890. //
  891. // put the Stretch Small Images control attribute
  892. //
  893. hr = pSlideshowService->put_StretchSmallImages(bStretchSmallImages);
  894. if (FAILED(hr))
  895. {
  896. DBG_ERR(("SaveCurrentSettings, failed to set StretchSmallImages property"));
  897. }
  898. //
  899. // set the control's image directory
  900. // Notice we store the image directory rather than the Projector
  901. // server control because it is not something that can be
  902. // set remotely. Only items that can be configured by the client
  903. // are stored by the COM Projector Server
  904. //
  905. hr = pSlideshowAlbum->put_ImagePath(GVAR_LOCAL.szImagePath);
  906. EnableApplyButton(FALSE);
  907. if (pSlideshowService)
  908. {
  909. pSlideshowService->Release();
  910. pSlideshowService = NULL;
  911. }
  912. if (pSlideshowAlbum)
  913. {
  914. pSlideshowAlbum->Release();
  915. pSlideshowAlbum = NULL;
  916. }
  917. return hr;
  918. }