Leaked source code of windows server 2003
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.

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