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.

257 lines
9.8 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998, 1999, 2000
  4. *
  5. * TITLE: CFGDLG.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 1/19/1999
  12. *
  13. * DESCRIPTION: Screensaver Configuration Dialog
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include <windows.h>
  19. #include <commctrl.h>
  20. #include <scrnsave.h>
  21. #include "cfgdlg.h"
  22. #include "ssmprsrc.h"
  23. #include "simstr.h"
  24. #include "ssdata.h"
  25. #include "isdbg.h"
  26. #include "simcrack.h"
  27. #include "ssutil.h"
  28. #include "ssconst.h"
  29. #include "simidlst.h"
  30. #include "wiacsh.h"
  31. static const DWORD g_HelpIDs[] =
  32. {
  33. IDC_MYPICTURES_ICON, -1,
  34. IDC_DIALOG_DESCRIPTION, -1,
  35. IDC_DIVIDER, -1,
  36. IDC_FREQUENCY_STATIC, IDH_WIA_CHANGE_PICS,
  37. IDC_FREQUENCY, IDH_WIA_CHANGE_PICS,
  38. IDC_MINUTES_AND_SECONDS, IDH_WIA_CHANGE_PICS,
  39. IDC_FREQ_LESS, IDH_WIA_CHANGE_PICS,
  40. IDC_FREQ_MORE, IDH_WIA_CHANGE_PICS,
  41. IDC_MAX_SIZE_STATIC, IDH_WIA_PIC_SIZE,
  42. IDC_SIZE_LESS, IDH_WIA_PIC_SIZE,
  43. IDC_SIZE_MORE, IDH_WIA_PIC_SIZE,
  44. IDC_MAX_SIZE, IDH_WIA_PIC_SIZE,
  45. IDC_IMAGE_SIZE_DESC, IDH_WIA_PIC_SIZE,
  46. IDC_IMAGEDIR, IDH_WIA_PICTURE_FOLDER,
  47. IDC_ALLOWSTRETCHING, IDH_WIA_STRETCH_PICS,
  48. IDC_DISPLAYFILENAME, IDH_WIA_SHOW_FILE_NAMES,
  49. IDC_ENABLE_TRANSITIONS, IDH_WIA_TRANSITION_EFFECTS,
  50. IDC_ALLOW_KEYBOARDCONTROL, IDH_WIA_ALLOW_SCROLL,
  51. IDOK, IDH_OK,
  52. IDCANCEL, IDH_CANCEL,
  53. IDC_BROWSE, IDH_WIA_BROWSE,
  54. 0, 0
  55. };
  56. static CSimpleString ConstructMinutesAndSecondsString( HINSTANCE hInstance, UINT nTotalSeconds )
  57. {
  58. CSimpleString strResult;
  59. UINT nMinutes = nTotalSeconds / 60;
  60. UINT nSeconds = nTotalSeconds % 60;
  61. if (0==nMinutes)
  62. {
  63. if (1==nSeconds)
  64. {
  65. strResult.Format( IDS_SECOND, hInstance, nSeconds );
  66. }
  67. else
  68. {
  69. strResult.Format( IDS_SECONDS, hInstance, nSeconds );
  70. }
  71. }
  72. else if (0==nSeconds)
  73. {
  74. if (1==nMinutes)
  75. {
  76. strResult.Format( IDS_MINUTE, hInstance, nMinutes );
  77. }
  78. else
  79. {
  80. strResult.Format( IDS_MINUTES, hInstance, nMinutes );
  81. }
  82. }
  83. else if (1==nMinutes && 1==nSeconds)
  84. {
  85. strResult.Format( IDS_MINUTE_AND_SECOND, hInstance, nMinutes, nSeconds );
  86. }
  87. else if (1==nMinutes)
  88. {
  89. strResult.Format( IDS_MINUTE_AND_SECONDS, hInstance, nMinutes, nSeconds );
  90. }
  91. else if (1==nSeconds)
  92. {
  93. strResult.Format( IDS_MINUTES_AND_SECOND, hInstance, nMinutes, nSeconds );
  94. }
  95. else
  96. {
  97. strResult.Format( IDS_MINUTES_AND_SECONDS, hInstance, nMinutes, nSeconds );
  98. }
  99. return strResult;
  100. }
  101. BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
  102. {
  103. switch (message)
  104. {
  105. case WM_INITDIALOG:
  106. {
  107. ScreenSaverUtil::SetIcons( hDlg, (HINSTANCE)GetWindowLongPtr(hDlg,GWLP_HINSTANCE), IDI_MONITOR );
  108. CMyDocsScreenSaverData MyDocsScreenSaverData( HKEY_CURRENT_USER, REGISTRY_PATH );
  109. //
  110. // Initialize path
  111. //
  112. SendDlgItemMessage( hDlg, IDC_IMAGEDIR, WM_SETTEXT, 0, (LPARAM)MyDocsScreenSaverData.ImageDirectory().String() );
  113. //
  114. // Initialize change frequency
  115. //
  116. SendDlgItemMessage( hDlg, IDC_FREQUENCY, TBM_SETRANGE, 1, MAKELONG(6,180) );
  117. SendDlgItemMessage( hDlg, IDC_FREQUENCY, TBM_SETPOS, 1, MyDocsScreenSaverData.ChangeInterval() / 1000 );
  118. CSimpleString strRes = ConstructMinutesAndSecondsString( (HINSTANCE)GetWindowLongPtr(hDlg,GWLP_HINSTANCE), MyDocsScreenSaverData.ChangeInterval() / 1000 );
  119. SendDlgItemMessage( hDlg, IDC_MINUTES_AND_SECONDS, WM_SETTEXT, 0, (LPARAM)strRes.String() );
  120. //
  121. // Initialize maximum screen percentage size
  122. //
  123. SendDlgItemMessage( hDlg, IDC_MAX_SIZE, TBM_SETRANGE, 1, MAKELONG(25,100) );
  124. SendDlgItemMessage( hDlg, IDC_MAX_SIZE, TBM_SETPOS, 1, MyDocsScreenSaverData.MaxScreenPercent() );
  125. strRes.Format( IDS_PERCENT, (HINSTANCE)GetWindowLongPtr(hDlg,GWLP_HINSTANCE), MyDocsScreenSaverData.MaxScreenPercent() );
  126. SendDlgItemMessage( hDlg, IDC_IMAGE_SIZE_DESC, WM_SETTEXT, 0, (LPARAM)strRes.String() );
  127. SendDlgItemMessage( hDlg, IDC_DISPLAYFILENAME, BM_SETCHECK, MyDocsScreenSaverData.DisplayFilename() ? BST_CHECKED : BST_UNCHECKED, 0 );
  128. SendDlgItemMessage( hDlg, IDC_ENABLE_TRANSITIONS, BM_SETCHECK, MyDocsScreenSaverData.DisableTransitions() ? BST_UNCHECKED : BST_CHECKED, 0 );
  129. SendDlgItemMessage( hDlg, IDC_ALLOWSTRETCHING, BM_SETCHECK, MyDocsScreenSaverData.AllowStretching() ? BST_CHECKED : BST_UNCHECKED, 0 );
  130. SendDlgItemMessage( hDlg, IDC_ALLOW_KEYBOARDCONTROL, BM_SETCHECK, MyDocsScreenSaverData.AllowKeyboardControl() ? BST_CHECKED : BST_UNCHECKED, 0 );
  131. }
  132. return (TRUE);
  133. case WM_HSCROLL:
  134. {
  135. HWND hWndScroll = (HWND)lParam;
  136. if (GetDlgItem( hDlg, IDC_FREQUENCY )==hWndScroll)
  137. {
  138. UINT nFrequency = (UINT)SendDlgItemMessage( hDlg, IDC_FREQUENCY, TBM_GETPOS, 0, 0 );
  139. CSimpleString strRes = ConstructMinutesAndSecondsString( (HINSTANCE)GetWindowLongPtr(hDlg,GWLP_HINSTANCE), nFrequency );
  140. SendDlgItemMessage( hDlg, IDC_MINUTES_AND_SECONDS, WM_SETTEXT, 0, (LPARAM)strRes.String() );
  141. }
  142. else if (GetDlgItem( hDlg, IDC_MAX_SIZE )==hWndScroll)
  143. {
  144. int nPercent = (int)SendDlgItemMessage( hDlg, IDC_MAX_SIZE, TBM_GETPOS, 0, 0 );
  145. CSimpleString strRes;
  146. strRes.Format( IDS_PERCENT, (HINSTANCE)GetWindowLongPtr(hDlg,GWLP_HINSTANCE), nPercent );
  147. SendDlgItemMessage( hDlg, IDC_IMAGE_SIZE_DESC, WM_SETTEXT, 0, (LPARAM)strRes.String() );
  148. }
  149. }
  150. return TRUE;
  151. case WM_CONTEXTMENU:
  152. WiaHelp::HandleWmContextMenu( wParam, lParam, g_HelpIDs );
  153. return true;
  154. case WM_HELP:
  155. WiaHelp::HandleWmHelp( wParam, lParam, g_HelpIDs );
  156. return true;
  157. case WM_COMMAND:
  158. {
  159. switch (LOWORD(wParam))
  160. {
  161. case IDC_BROWSE:
  162. {
  163. TCHAR szTxt[MAX_PATH];
  164. SendDlgItemMessage( hDlg, IDC_IMAGEDIR, WM_GETTEXT, sizeof(szTxt)/sizeof(szTxt[0]), (LPARAM)szTxt );
  165. CSimpleString strPrompt( IDS_DIRECTORYPROMPT, (HINSTANCE)GetWindowLongPtr(hDlg,GWLP_HINSTANCE) );
  166. if (ScreenSaverUtil::SelectDirectory( hDlg, strPrompt.String(), szTxt ))
  167. {
  168. SendDlgItemMessage( hDlg, IDC_IMAGEDIR, WM_SETTEXT, 0, (LPARAM)szTxt );
  169. }
  170. }
  171. return TRUE;
  172. case IDOK:
  173. {
  174. TCHAR szTxt[MAX_PATH];
  175. CMyDocsScreenSaverData MyDocsScreenSaverData( HKEY_CURRENT_USER, REGISTRY_PATH );
  176. //
  177. // Get the image path
  178. //
  179. if (SendDlgItemMessage( hDlg, IDC_IMAGEDIR, WM_GETTEXT, sizeof(szTxt)/sizeof(szTxt[0]), (LPARAM)szTxt ))
  180. {
  181. //
  182. // If this is the my pictures folder, delete the path name, so we will use the default next time
  183. //
  184. if (CSimpleIdList().GetSpecialFolder(hDlg,CSIDL_MYPICTURES).Name() == CSimpleString(szTxt))
  185. {
  186. MyDocsScreenSaverData.ImageDirectory(TEXT(""));
  187. }
  188. else
  189. {
  190. MyDocsScreenSaverData.ImageDirectory(szTxt);
  191. }
  192. }
  193. UINT nFrequency = (UINT)SendDlgItemMessage( hDlg, IDC_FREQUENCY, TBM_GETPOS, 0, 0 );
  194. MyDocsScreenSaverData.ChangeInterval(nFrequency * 1000);
  195. int nPercent = (int)SendDlgItemMessage( hDlg, IDC_MAX_SIZE, TBM_GETPOS, 0, 0 );
  196. MyDocsScreenSaverData.MaxScreenPercent(nPercent);
  197. bool bChecked = (BST_CHECKED == SendDlgItemMessage( hDlg, IDC_DISPLAYFILENAME, BM_GETSTATE, 0, 0 ));
  198. MyDocsScreenSaverData.DisplayFilename(bChecked);
  199. bChecked = (BST_CHECKED == SendDlgItemMessage( hDlg, IDC_ENABLE_TRANSITIONS, BM_GETSTATE, 0, 0 ));
  200. MyDocsScreenSaverData.DisableTransitions(!bChecked);
  201. bChecked = (BST_CHECKED == SendDlgItemMessage( hDlg, IDC_ALLOWSTRETCHING, BM_GETSTATE, 0, 0 ));
  202. MyDocsScreenSaverData.AllowStretching(bChecked);
  203. bChecked = (BST_CHECKED == SendDlgItemMessage( hDlg, IDC_ALLOW_KEYBOARDCONTROL, BM_GETSTATE, 0, 0 ));
  204. MyDocsScreenSaverData.AllowKeyboardControl(bChecked);
  205. MyDocsScreenSaverData.Write();
  206. HWND hWndParent = (HWND)GetWindowLongPtr( hDlg, GWLP_HWNDPARENT );
  207. if (hWndParent)
  208. PostMessage( hWndParent, UWM_CONFIG_CHANGED, 0, 0 );
  209. EndDialog(hDlg, IDOK);
  210. }
  211. return (TRUE);
  212. case IDCANCEL:
  213. {
  214. EndDialog(hDlg, IDCANCEL);
  215. }
  216. return (TRUE);
  217. }
  218. }
  219. return (FALSE);
  220. }
  221. return (FALSE);
  222. }
  223. BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
  224. {
  225. InitCommonControls();
  226. return TRUE;
  227. }