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.

407 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxcfg.c
  5. Abstract:
  6. Implementation of the control panel applet entry point
  7. Environment:
  8. Windows NT fax configuration applet
  9. Revision History:
  10. 02/27/96 -davidx-
  11. Created it.
  12. 05/22/96 -davidx-
  13. Share the same DLL with remote admin program.
  14. mm/dd/yy -author-
  15. description
  16. --*/
  17. #include <stdlib.h>
  18. #include <windows.h>
  19. #include <windowsx.h>
  20. #include <commctrl.h>
  21. #include <tchar.h>
  22. #include "faxcfg.h"
  23. #include "resource.h"
  24. //
  25. // Name of the remote fax server machine
  26. //
  27. #define MAX_NAME (MAX_COMPUTERNAME_LENGTH+3)
  28. #define MAX_TITLE_LEN 128
  29. #define MAX_MESSAGE_LEN 512
  30. #define MAX_PAGES 16
  31. HINSTANCE ghInstance;
  32. INT gFaxConfigType;
  33. INT gNumPages;
  34. HPROPSHEETPAGE ghPropSheetPages[MAX_PAGES];
  35. TCHAR FaxServerName[MAX_NAME];
  36. TCHAR TitleStr[MAX_TITLE_LEN];
  37. VOID
  38. DisplayErrorMessage(
  39. INT msgStrId
  40. )
  41. /*++
  42. Routine Description:
  43. Display an error message dialog box
  44. Arguments:
  45. msgStrId - Message format string resource ID
  46. Return Value:
  47. NONE
  48. --*/
  49. {
  50. TCHAR buffer[MAX_MESSAGE_LEN];
  51. if (! LoadString(ghInstance, msgStrId, buffer, MAX_MESSAGE_LEN))
  52. buffer[0] = 0;
  53. MessageBox(NULL, buffer, TitleStr, MB_OK | MB_ICONERROR);
  54. }
  55. VOID
  56. MakeTitleString(
  57. LPTSTR pServerName
  58. )
  59. /*++
  60. Routine Description:
  61. Compose the title string for the remote configuration dialog
  62. Arguments:
  63. pServerName - Specifies the name of the remote server
  64. Return Value:
  65. NONE
  66. --*/
  67. {
  68. if (! LoadString(ghInstance, IDS_FAX_REMOTE_ADMIN, TitleStr, MAX_TITLE_LEN))
  69. TitleStr[0] = 0;
  70. if (_tcslen(TitleStr) + _tcslen(pServerName) < MAX_TITLE_LEN)
  71. _tcscat(TitleStr, pServerName);
  72. }
  73. BOOL CALLBACK
  74. GetFaxServerNameProc(
  75. HWND hDlg,
  76. UINT uMsg,
  77. WPARAM wParam,
  78. LPARAM lParam
  79. )
  80. /*++
  81. Routine Description:
  82. Dialog procedure for prompting the user to enter a fax server name
  83. Arguments:
  84. hDlg - Handle to dialog window
  85. uMsg - Message
  86. wParam, lParam - Parameters
  87. Return Value:
  88. Depends on message
  89. --*/
  90. {
  91. switch (uMsg) {
  92. case WM_INITDIALOG:
  93. SendDlgItemMessage(hDlg, IDC_FAXSERVER_NAME, EM_LIMITTEXT, MAX_NAME-1, 0);
  94. SetDlgItemText(hDlg, IDC_FAXSERVER_NAME, FaxServerName);
  95. return TRUE;
  96. case WM_COMMAND:
  97. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  98. case IDC_FAXSERVER_NAME:
  99. if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE) {
  100. EnableWindow(GetDlgItem(hDlg, IDOK),
  101. GetWindowTextLength(GetDlgItem(hDlg, IDC_FAXSERVER_NAME)) > 0);
  102. }
  103. return TRUE;
  104. case IDOK:
  105. if (GetWindowTextLength(GetDlgItem(hDlg, IDC_FAXSERVER_NAME)) > 0) {
  106. GetDlgItemText(hDlg, IDC_FAXSERVER_NAME, FaxServerName, MAX_NAME);
  107. EndDialog(hDlg, IDOK);
  108. } else
  109. MessageBeep(MB_OK);
  110. return TRUE;
  111. case IDCANCEL:
  112. EndDialog(hDlg, IDCANCEL);
  113. return TRUE;
  114. }
  115. break;
  116. }
  117. return FALSE;
  118. }
  119. DWORD
  120. ConnectFaxServerThread(
  121. HWND hDlg
  122. )
  123. /*++
  124. Routine Description:
  125. Thread proc for connecting to the remote fax server
  126. Arguments:
  127. hDlg - Handle to the status dialog
  128. Return Value:
  129. IDOK if successful, IDCANCEL otherwise
  130. --*/
  131. {
  132. DWORD result = IDCANCEL;
  133. gFaxConfigType = FaxConfigInit(FaxServerName, FALSE);
  134. if (gFaxConfigType == FAXCONFIG_SERVER &&
  135. (gNumPages = FaxConfigGetServerPages(ghPropSheetPages, MAX_PAGES)) <= MAX_PAGES)
  136. {
  137. result = IDOK;
  138. }
  139. PostMessage(hDlg, WM_APP, result, 0);
  140. return result;
  141. }
  142. BOOL CALLBACK
  143. ConnectFaxServerProc(
  144. HWND hDlg,
  145. UINT uMsg,
  146. WPARAM wParam,
  147. LPARAM lParam
  148. )
  149. /*++
  150. Routine Description:
  151. Dialog procedure for connecting to the fax server
  152. Arguments:
  153. hDlg - Handle to dialog window
  154. uMsg - Message
  155. wParam, lParam - Parameters
  156. Return Value:
  157. Depends on message
  158. --*/
  159. {
  160. HANDLE hThread;
  161. DWORD threadId;
  162. switch (uMsg) {
  163. case WM_INITDIALOG:
  164. SetWindowText(hDlg, TitleStr);
  165. if (hThread = CreateThread(NULL,
  166. 0,
  167. (LPTHREAD_START_ROUTINE) ConnectFaxServerThread,
  168. (LPVOID) hDlg,
  169. 0,
  170. &threadId))
  171. {
  172. CloseHandle(hThread);
  173. } else
  174. EndDialog(hDlg, IDCANCEL);
  175. break;
  176. case WM_APP:
  177. EndDialog(hDlg, wParam);
  178. return TRUE;
  179. }
  180. return FALSE;
  181. }
  182. INT
  183. wWinMain(
  184. HINSTANCE hInstance,
  185. HINSTANCE hPrevInstance,
  186. LPTSTR lpCmdLine,
  187. INT nCmdShow
  188. )
  189. /*++
  190. Routine Description:
  191. Application entry point
  192. Arguments:
  193. hInstance - Identifies the current instance of the application
  194. hPrevInstance - Identifies the previous instance of the application
  195. lpCmdLine - Specifies the command line for the application.
  196. nCmdShow - Specifies how the window is to be shown
  197. Return Value:
  198. 0
  199. --*/
  200. {
  201. PROPSHEETHEADER psh;
  202. BOOL cmdlineServerName;
  203. BOOL success = FALSE;
  204. ghInstance = hInstance;
  205. //
  206. // Check if the server name is specified on the command line
  207. //
  208. if (lpCmdLine && *lpCmdLine) {
  209. cmdlineServerName = TRUE;
  210. if (_tcslen(lpCmdLine) > MAX_NAME+2) {
  211. MakeTitleString(lpCmdLine);
  212. DisplayErrorMessage(IDS_NAME_TOO_LONG);
  213. return -1;
  214. } else
  215. _tcscpy(FaxServerName, lpCmdLine);
  216. } else
  217. cmdlineServerName = FALSE;
  218. do {
  219. //
  220. // Let the user enter the name of fax server computer
  221. //
  222. if (! cmdlineServerName &&
  223. DialogBox(hInstance,
  224. MAKEINTRESOURCE(IDD_SELECT_FAXSERVER),
  225. NULL,
  226. GetFaxServerNameProc) != IDOK)
  227. {
  228. break;
  229. }
  230. MakeTitleString(FaxServerName);
  231. //
  232. // Establish connection to the fax server
  233. //
  234. gFaxConfigType = -1;
  235. if (DialogBox(ghInstance,
  236. MAKEINTRESOURCE(IDD_CONNECT_FAXSERVER),
  237. NULL,
  238. ConnectFaxServerProc) == IDOK)
  239. {
  240. ZeroMemory(&psh, sizeof(psh));
  241. psh.dwSize = sizeof(PROPSHEETHEADER);
  242. psh.dwFlags = PSH_USEICONID;
  243. psh.hwndParent = NULL;
  244. psh.hInstance = ghInstance;
  245. psh.pszIcon = MAKEINTRESOURCE(IDI_FAX_REMOTE_ADMIN);
  246. psh.pszCaption = TitleStr;
  247. psh.nPages = gNumPages;
  248. psh.phpage = ghPropSheetPages;
  249. //
  250. // Display the property sheet
  251. //
  252. success = (PropertySheet(&psh) != -1);
  253. }
  254. if (gFaxConfigType >= 0)
  255. FaxConfigCleanup();
  256. //
  257. // Display an error message if the fax server
  258. // configuration dialog wasn't displayed
  259. //
  260. if (! success)
  261. DisplayErrorMessage(IDS_REMOTE_ADMIN_FAILED);
  262. } while (!success && !cmdlineServerName);
  263. return 0;
  264. }