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.

448 lines
11 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. statopts.c
  5. Abstract:
  6. Functions to handle status monitor options dialog
  7. Environment:
  8. Fax configuration applet
  9. Revision History:
  10. 12/3/96 -georgeje-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include <windows.h>
  16. #include <windowsx.h>
  17. #include <winfax.h>
  18. #include <shellapi.h>
  19. #include <tchar.h>
  20. #include <winspool.h>
  21. #include "faxcfg.h"
  22. #include "faxutil.h"
  23. #include "faxreg.h"
  24. #include "faxcfgrs.h"
  25. #include "faxhelp.h"
  26. HMODULE hModWinfax = NULL;
  27. PFAXCONNECTFAXSERVER pFaxConnectFaxServer;
  28. PFAXCLOSE pFaxClose;
  29. PFAXACCESSCHECK pFaxAccessCheck;
  30. VOID
  31. DoInitStatusOptions(
  32. HWND hDlg
  33. )
  34. /*++
  35. Routine Description:
  36. Initializes the Status Options property sheet page with information from the registry
  37. Arguments:
  38. hDlg - Handle to the Status Options property sheet page
  39. Return Value:
  40. NONE
  41. --*/
  42. #define InitStatusOptionsCheckBox(id, pValueName, DefaultValue) \
  43. CheckDlgButton( hDlg, id, GetRegistryDword( hRegKey, pValueName ));
  44. {
  45. HKEY hRegKey;
  46. HANDLE hFax;
  47. //
  48. // Open the user info registry key for reading
  49. //
  50. if (! (hRegKey = OpenRegistryKey(HKEY_CURRENT_USER, REGKEY_FAX_USERINFO, FALSE,KEY_READ)))
  51. return;
  52. //
  53. // Fill in the edit text fields
  54. //
  55. InitStatusOptionsCheckBox(IDC_STATUS_TASKBAR, REGVAL_TASKBAR, BST_CHECKED);
  56. InitStatusOptionsCheckBox(IDC_STATUS_ONTOP, REGVAL_ALWAYS_ON_TOP, BST_CHECKED);
  57. InitStatusOptionsCheckBox(IDC_STATUS_VISUAL, REGVAL_VISUAL_NOTIFICATION, BST_CHECKED);
  58. InitStatusOptionsCheckBox(IDC_STATUS_SOUND, REGVAL_SOUND_NOTIFICATION, BST_UNCHECKED);
  59. InitStatusOptionsCheckBox(IDC_STATUS_MANUAL, REGVAL_ENABLE_MANUAL_ANSWER, BST_UNCHECKED);
  60. //
  61. // Close the registry key before returning to the caller
  62. //
  63. RegCloseKey(hRegKey);
  64. //
  65. // check if the user has permission to change manual answer, gray it out if he doesn't
  66. //
  67. if (!LoadWinfax()) {
  68. return;
  69. }
  70. if (!pFaxConnectFaxServer(NULL, &hFax)) {
  71. return;
  72. }
  73. EnableWindow(GetDlgItem(hDlg, IDC_STATUS_MANUAL), pFaxAccessCheck(hFax, FAX_PORT_QUERY | FAX_PORT_SET));
  74. pFaxClose(hFax);
  75. UnloadWinfax();
  76. }
  77. VOID
  78. DoSaveStatusOptions(
  79. HWND hDlg
  80. )
  81. /*++
  82. Routine Description:
  83. Save the information on the Status Options property sheet page to registry
  84. Arguments:
  85. hDlg - Handle to the Status Options property sheet page
  86. Return Value:
  87. NONE
  88. --*/
  89. #define SaveStatusOptionsCheckBox(id, pValueName) \
  90. SetRegistryDword(hRegKey, pValueName, IsDlgButtonChecked(hDlg, id));
  91. {
  92. HKEY hRegKey;
  93. BOOL fSaveConfig = FALSE;
  94. HWND hWndFaxStat = NULL;
  95. //
  96. // Open the user registry key for writing and create it if necessary
  97. //
  98. if (! (hRegKey = OpenRegistryKey(HKEY_CURRENT_USER, REGKEY_FAX_USERINFO,TRUE, KEY_ALL_ACCESS)))
  99. {
  100. return;
  101. }
  102. SaveStatusOptionsCheckBox(IDC_STATUS_TASKBAR, REGVAL_TASKBAR);
  103. SaveStatusOptionsCheckBox(IDC_STATUS_ONTOP, REGVAL_ALWAYS_ON_TOP);
  104. SaveStatusOptionsCheckBox(IDC_STATUS_VISUAL, REGVAL_VISUAL_NOTIFICATION);
  105. SaveStatusOptionsCheckBox(IDC_STATUS_SOUND, REGVAL_SOUND_NOTIFICATION);
  106. SaveStatusOptionsCheckBox(IDC_STATUS_MANUAL, REGVAL_ENABLE_MANUAL_ANSWER);
  107. //
  108. // Close the registry key before returning to the caller
  109. //
  110. RegCloseKey(hRegKey);
  111. // See if faxstat is running
  112. hWndFaxStat = FindWindow(FAXSTAT_WINCLASS, NULL);
  113. if (hWndFaxStat) {
  114. PostMessage(hWndFaxStat, WM_FAXSTAT_CONTROLPANEL, IsDlgButtonChecked(hDlg, IDC_STATUS_MANUAL), 0);
  115. }
  116. }
  117. BOOL
  118. StatusOptionsProc(
  119. HWND hDlg,
  120. UINT message,
  121. WPARAM wParam,
  122. LPARAM lParam
  123. )
  124. /*++
  125. Routine Description:
  126. Procedure for handling the "Status Options" tab
  127. Arguments:
  128. hDlg - Identifies the property sheet page
  129. message - Specifies the message
  130. wParam - Specifies additional message-specific information
  131. lParam - Specifies additional message-specific information
  132. Return Value:
  133. Depends on the value of message parameter
  134. --*/
  135. {
  136. LPNMHDR lpNMHdr = (LPNMHDR) lParam;
  137. switch (message) {
  138. case WM_INITDIALOG:
  139. DoInitStatusOptions( hDlg );
  140. return TRUE;
  141. case WM_COMMAND:
  142. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  143. case IDC_STATUS_TASKBAR:
  144. case IDC_STATUS_ONTOP:
  145. case IDC_STATUS_VISUAL:
  146. case IDC_STATUS_SOUND:
  147. case IDC_STATUS_MANUAL:
  148. if (GET_WM_COMMAND_CMD(wParam, lParam) == BN_CLICKED)
  149. break;
  150. default:
  151. return FALSE;
  152. }
  153. SetChangedFlag(hDlg, TRUE);
  154. return TRUE;
  155. case WM_NOTIFY:
  156. switch (lpNMHdr->code) {
  157. case PSN_SETACTIVE:
  158. break;
  159. case PSN_APPLY:
  160. //
  161. // User pressed OK or Apply - validate inputs and save changes
  162. //
  163. DoSaveStatusOptions(hDlg);
  164. SetChangedFlag(hDlg, FALSE);
  165. return PSNRET_NOERROR;
  166. }
  167. break;
  168. case WM_HELP:
  169. case WM_CONTEXTMENU:
  170. return HandleHelpPopup(hDlg, message, wParam, lParam,STATUS_OPTIONS_PAGE);
  171. }
  172. return FALSE;
  173. }
  174. BOOL
  175. AdvancedOptionsProc(
  176. HWND hDlg,
  177. UINT message,
  178. WPARAM wParam,
  179. LPARAM lParam
  180. )
  181. /*++
  182. Routine Description:
  183. Procedure for handling the "Status Options" tab
  184. Arguments:
  185. hDlg - Identifies the property sheet page
  186. message - Specifies the message
  187. wParam - Specifies additional message-specific information
  188. lParam - Specifies additional message-specific information
  189. Return Value:
  190. Depends on the value of message parameter
  191. --*/
  192. {
  193. LPNMHDR lpNMHdr = (LPNMHDR) lParam;
  194. TCHAR Text[MAX_PATH], CommandLine[MAX_PATH], Caption[MAX_PATH];
  195. WORD IconIndex;
  196. HICON hIconMMC, hIconMMCHelp, hIconAddPrinter;
  197. WCHAR FaxPrinterName[MAX_PATH];
  198. HANDLE hPrinter, hChangeNotification;
  199. DWORD dwWaitResult;
  200. switch (message) {
  201. case WM_INITDIALOG:
  202. // Load and set the mmc icon
  203. IconIndex = 0;
  204. LoadString(ghInstance, IDS_MMC_CMDLINE, Text, MAX_PATH);
  205. ExpandEnvironmentStrings(Text, CommandLine, MAX_PATH);
  206. hIconMMC = ExtractAssociatedIcon(ghInstance, CommandLine, &IconIndex);
  207. SendDlgItemMessage(hDlg, IDC_LAUNCH_MMC, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) hIconMMC);
  208. // Load and set the mmc help icon
  209. IconIndex = 0;
  210. LoadString(ghInstance, IDS_MMC_HELP_CMDLINE, Text, MAX_PATH);
  211. ExpandEnvironmentStrings(Text, CommandLine, MAX_PATH);
  212. hIconMMCHelp = ExtractAssociatedIcon(ghInstance, CommandLine, &IconIndex);
  213. SendDlgItemMessage(hDlg, IDC_LAUNCH_MMC_HELP, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) hIconMMCHelp);
  214. // Load and set the add printer icon
  215. IconIndex = 59;
  216. LoadString(ghInstance, IDS_SHELL32_CMDLINE, Text, MAX_PATH);
  217. ExpandEnvironmentStrings(Text, CommandLine, MAX_PATH);
  218. hIconAddPrinter = ExtractAssociatedIcon(ghInstance, CommandLine, &IconIndex);
  219. SendDlgItemMessage(hDlg, IDC_ADD_PRINTER, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) hIconAddPrinter);
  220. return TRUE;
  221. case WM_COMMAND:
  222. switch (LOWORD(wParam)) {
  223. case IDC_LAUNCH_MMC:
  224. LoadString(ghInstance, IDS_MMC_CMDLINE, Text, MAX_PATH);
  225. ExpandEnvironmentStrings(Text, CommandLine, MAX_PATH);
  226. ShellExecute(
  227. hDlg,
  228. NULL,
  229. CommandLine,
  230. TEXT("/s"),
  231. TEXT("."),
  232. SW_SHOWNORMAL
  233. );
  234. return TRUE;
  235. case IDC_LAUNCH_MMC_HELP:
  236. LoadString(ghInstance, IDS_MMC_HELP_CMDLINE, Text, MAX_PATH);
  237. ExpandEnvironmentStrings(Text, CommandLine, MAX_PATH);
  238. ShellExecute(
  239. hDlg,
  240. NULL,
  241. CommandLine,
  242. NULL,
  243. TEXT("."),
  244. SW_SHOWNORMAL
  245. );
  246. return TRUE;
  247. case IDC_ADD_PRINTER:
  248. // Initialize the handles
  249. hPrinter = NULL;
  250. hChangeNotification = INVALID_HANDLE_VALUE;
  251. // Initialize the wait result
  252. dwWaitResult = WAIT_TIMEOUT;
  253. // Open the local print server
  254. if (OpenPrinter(NULL, &hPrinter, NULL) == TRUE)
  255. {
  256. hChangeNotification = FindFirstPrinterChangeNotification(hPrinter, PRINTER_CHANGE_ADD_PRINTER, 0, NULL);
  257. }
  258. // Add the fax printer
  259. MyLoadString(ghInstance, IDS_DEFAULT_PRINTER_NAME, FaxPrinterName, MAX_PATH, GetSystemDefaultUILanguage());
  260. swprintf(Text, TEXT("printui.dll,PrintUIEntry %s /q /if /b \"%s\" /f \"%%SystemRoot%%\\inf\\ntprint.inf\" /r \"MSFAX:\" /m \"%s\" /l \"%%SystemRoot%%\\system32\""), IsProductSuite() ? L"/Z" : L"/z", FaxPrinterName, FAX_DRIVER_NAME);
  261. ExpandEnvironmentStrings(Text, CommandLine, MAX_PATH);
  262. ExpandEnvironmentStrings(TEXT("%systemroot%\\system32\\rundll32.exe"), Text, MAX_PATH);
  263. ShellExecute(
  264. hDlg,
  265. NULL,
  266. Text,
  267. CommandLine,
  268. TEXT("."),
  269. SW_SHOWNORMAL
  270. );
  271. if (hChangeNotification != INVALID_HANDLE_VALUE)
  272. {
  273. // Wait for the change notification
  274. dwWaitResult = WaitForSingleObject(hChangeNotification, 60000);
  275. // Close the change notification
  276. FindClosePrinterChangeNotification(hChangeNotification);
  277. }
  278. if (hPrinter != NULL)
  279. {
  280. // Close the local printer server
  281. ClosePrinter(hPrinter);
  282. }
  283. // Load the caption
  284. LoadString(ghInstance, IDS_ADD_PRINTER_CAPTION, Caption, MAX_PATH);
  285. // Load the text
  286. if (dwWaitResult == WAIT_OBJECT_0)
  287. {
  288. LoadString(ghInstance, IDS_ADD_PRINTER_SUCCESS, Text, MAX_PATH);
  289. }
  290. else
  291. {
  292. LoadString(ghInstance, IDS_ADD_PRINTER_FAILED, Text, MAX_PATH);
  293. }
  294. // Display the message
  295. MessageBox(hDlg, Text, Caption, dwWaitResult == WAIT_OBJECT_0 ? MB_ICONINFORMATION : MB_ICONWARNING);
  296. return TRUE;
  297. };
  298. #if 0
  299. case WM_NOTIFY:
  300. switch (lpNMHdr->code) {
  301. case PSN_APPLY:
  302. //
  303. // User pressed OK or Apply - validate inputs and save changes
  304. //
  305. DoSaveStatusOptions(hDlg);
  306. SetChangedFlag(hDlg, FALSE);
  307. return PSNRET_NOERROR;
  308. }
  309. break;
  310. #endif
  311. case WM_HELP:
  312. case WM_CONTEXTMENU:
  313. return HandleHelpPopup(hDlg, message, wParam, lParam,ADVNCD_OPTIONS_PAGE);
  314. }
  315. return FALSE;
  316. }