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.

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