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.

404 lines
8.0 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. dialogs.c
  6. // @@BEGIN_DDKSPLIT
  7. Abstract:
  8. Environment:
  9. User Mode -Win32
  10. Revision History:
  11. // @@END_DDKSPLIT
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include "spltypes.h"
  16. #include "localui.h"
  17. #include "local.h"
  18. #include "dialogs.h"
  19. WCHAR szINIKey_TransmissionRetryTimeout[] = L"TransmissionRetryTimeout";
  20. WCHAR szHelpFile[] = L"WINDOWS.HLP";
  21. #define MAX_LOCAL_PORTNAME 246
  22. const DWORD g_aHelpIDs[]=
  23. {
  24. IDD_PN_EF_PORTNAME, 8805136, // Port Name: "" (Edit)
  25. IDD_CL_EF_TRANSMISSIONRETRY, 8807704, // Configure LPT Port: "" (Edit)
  26. 0, 0
  27. };
  28. INT_PTR APIENTRY
  29. ConfigureLPTPortDlg(
  30. HWND hwnd,
  31. UINT msg,
  32. WPARAM wparam,
  33. LPARAM lparam
  34. )
  35. {
  36. switch(msg)
  37. {
  38. case WM_INITDIALOG:
  39. return ConfigureLPTPortInitDialog(hwnd, (PPORTDIALOG) lparam);
  40. case WM_COMMAND:
  41. switch (LOWORD(wparam))
  42. {
  43. case IDOK:
  44. return ConfigureLPTPortCommandOK(hwnd);
  45. case IDCANCEL:
  46. return ConfigureLPTPortCommandCancel(hwnd);
  47. case IDD_CL_EF_TRANSMISSIONRETRY:
  48. if( HIWORD(wparam) == EN_UPDATE )
  49. ConfigureLPTPortCommandTransmissionRetryUpdate(hwnd, LOWORD(wparam));
  50. break;
  51. }
  52. break;
  53. case WM_HELP:
  54. case WM_CONTEXTMENU:
  55. return LocalUIHelp(hwnd, msg, wparam, lparam);
  56. break;
  57. }
  58. return FALSE;
  59. }
  60. /*
  61. *
  62. */
  63. BOOL
  64. ConfigureLPTPortInitDialog(
  65. HWND hwnd,
  66. PPORTDIALOG pPort
  67. )
  68. {
  69. DWORD dwTransmissionRetryTimeout;
  70. DWORD cbNeeded;
  71. DWORD dwDummy;
  72. BOOL rc;
  73. DWORD dwStatus;
  74. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) pPort);
  75. SetForegroundWindow(hwnd);
  76. SendDlgItemMessage( hwnd, IDD_CL_EF_TRANSMISSIONRETRY,
  77. EM_LIMITTEXT, TIMEOUT_STRING_MAX, 0 );
  78. // Get the Transmission Retry Timeout from the host
  79. rc = XcvData( pPort->hXcv,
  80. L"GetTransmissionRetryTimeout",
  81. (PBYTE) &dwDummy,
  82. 0,
  83. (PBYTE) &dwTransmissionRetryTimeout,
  84. sizeof dwTransmissionRetryTimeout,
  85. &cbNeeded,
  86. &dwStatus);
  87. if(!rc) {
  88. DBGMSG(DBG_WARNING, ("Error %d checking TransmissionRetryTimeout\n", GetLastError()));
  89. } else if(dwStatus != ERROR_SUCCESS) {
  90. DBGMSG(DBG_WARNING, ("Error %d checking TransmissionRetryTimeout\n", dwStatus));
  91. SetLastError(dwStatus);
  92. rc = FALSE;
  93. } else {
  94. SetDlgItemInt( hwnd, IDD_CL_EF_TRANSMISSIONRETRY,
  95. dwTransmissionRetryTimeout, FALSE );
  96. SET_LAST_VALID_ENTRY( hwnd, IDD_CL_EF_TRANSMISSIONRETRY,
  97. dwTransmissionRetryTimeout );
  98. }
  99. return rc;
  100. }
  101. /*
  102. *
  103. */
  104. BOOL
  105. ConfigureLPTPortCommandOK(
  106. HWND hwnd
  107. )
  108. {
  109. WCHAR String[TIMEOUT_STRING_MAX+1];
  110. UINT TransmissionRetryTimeout;
  111. BOOL b;
  112. DWORD cbNeeded;
  113. PPORTDIALOG pPort;
  114. DWORD dwStatus;
  115. if ((pPort = (PPORTDIALOG) GetWindowLongPtr(hwnd, GWLP_USERDATA)) == NULL)
  116. {
  117. dwStatus = ERROR_INVALID_DATA;
  118. ErrorMessage (hwnd, dwStatus);
  119. SetLastError (dwStatus);
  120. return FALSE;
  121. }
  122. TransmissionRetryTimeout = GetDlgItemInt( hwnd,
  123. IDD_CL_EF_TRANSMISSIONRETRY,
  124. &b,
  125. FALSE );
  126. StringCchPrintf (String, COUNTOF (String), L"%d", TransmissionRetryTimeout);
  127. b = XcvData(pPort->hXcv,
  128. L"ConfigureLPTPortCommandOK",
  129. (PBYTE) String,
  130. (wcslen(String) + 1)*sizeof(WCHAR),
  131. (PBYTE) &cbNeeded,
  132. 0,
  133. &cbNeeded,
  134. &dwStatus);
  135. EndDialog(hwnd, b ? dwStatus : GetLastError());
  136. return TRUE;
  137. }
  138. /*
  139. *
  140. */
  141. BOOL
  142. ConfigureLPTPortCommandCancel(
  143. HWND hwnd
  144. )
  145. {
  146. EndDialog(hwnd, ERROR_CANCELLED);
  147. return TRUE;
  148. }
  149. /*
  150. *
  151. */
  152. BOOL
  153. ConfigureLPTPortCommandTransmissionRetryUpdate(
  154. HWND hwnd,
  155. WORD CtlId
  156. )
  157. {
  158. int Value;
  159. BOOL OK;
  160. Value = GetDlgItemInt( hwnd, CtlId, &OK, FALSE );
  161. if( WITHINRANGE( Value, TIMEOUT_MIN, TIMEOUT_MAX ) )
  162. {
  163. SET_LAST_VALID_ENTRY( hwnd, CtlId, Value );
  164. }
  165. else
  166. {
  167. SetDlgItemInt( hwnd, CtlId, (UINT) GET_LAST_VALID_ENTRY( hwnd, CtlId ), FALSE );
  168. SendDlgItemMessage( hwnd, CtlId, EM_SETSEL, 0, (LPARAM)-1 );
  169. }
  170. return TRUE;
  171. }
  172. /*
  173. *
  174. */
  175. INT_PTR CALLBACK
  176. PortNameDlg(
  177. HWND hwnd,
  178. WORD msg,
  179. WPARAM wparam,
  180. LPARAM lparam
  181. )
  182. {
  183. switch(msg)
  184. {
  185. case WM_INITDIALOG:
  186. return PortNameInitDialog(hwnd, (PPORTDIALOG)lparam);
  187. case WM_COMMAND:
  188. switch (LOWORD(wparam))
  189. {
  190. case IDOK:
  191. return PortNameCommandOK(hwnd);
  192. case IDCANCEL:
  193. return PortNameCommandCancel(hwnd);
  194. }
  195. break;
  196. case WM_HELP:
  197. case WM_CONTEXTMENU:
  198. return LocalUIHelp(hwnd, msg, wparam, lparam);
  199. }
  200. return FALSE;
  201. }
  202. /*
  203. *
  204. */
  205. BOOL
  206. PortNameInitDialog(
  207. HWND hwnd,
  208. PPORTDIALOG pPort
  209. )
  210. {
  211. SetForegroundWindow(hwnd);
  212. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) pPort);
  213. // Number used to check port length in LocalMon (247)
  214. SendDlgItemMessage (hwnd, IDD_PN_EF_PORTNAME, EM_LIMITTEXT, MAX_LOCAL_PORTNAME, 0);
  215. return TRUE;
  216. }
  217. /*
  218. *
  219. */
  220. BOOL
  221. PortNameCommandOK(
  222. HWND hwnd
  223. )
  224. {
  225. PPORTDIALOG pPort;
  226. WCHAR string [MAX_LOCAL_PORTNAME + 1];
  227. BOOL rc;
  228. DWORD cbNeeded;
  229. DWORD dwStatus;
  230. if ((pPort = (PPORTDIALOG) GetWindowLongPtr( hwnd, GWLP_USERDATA )) == NULL)
  231. {
  232. dwStatus = ERROR_INVALID_DATA;
  233. ErrorMessage (hwnd, dwStatus);
  234. SetLastError (dwStatus);
  235. return FALSE;
  236. }
  237. GetDlgItemText( hwnd, IDD_PN_EF_PORTNAME, string, COUNTOF (string) );
  238. rc = XcvData( pPort->hXcv,
  239. L"PortIsValid",
  240. (PBYTE) string,
  241. (wcslen(string) + 1)*sizeof *string,
  242. (PBYTE) NULL,
  243. 0,
  244. &cbNeeded,
  245. &dwStatus);
  246. if (!rc) {
  247. return FALSE;
  248. } else if (dwStatus != ERROR_SUCCESS) {
  249. SetLastError(dwStatus);
  250. if (dwStatus == ERROR_INVALID_NAME)
  251. Message( hwnd, MSG_ERROR, IDS_LOCALMONITOR, IDS_INVALIDPORTNAME_S, string );
  252. else
  253. ErrorMessage(hwnd, dwStatus);
  254. return FALSE;
  255. } else {
  256. pPort->pszPortName = AllocSplStr( string );
  257. EndDialog( hwnd, ERROR_SUCCESS );
  258. return TRUE;
  259. }
  260. }
  261. /*
  262. *
  263. */
  264. BOOL
  265. PortNameCommandCancel(
  266. HWND hwnd
  267. )
  268. {
  269. EndDialog(hwnd, ERROR_CANCELLED);
  270. return TRUE;
  271. }
  272. /*++
  273. Routine Name:
  274. LocalUIHelp
  275. Routine Description:
  276. Handles context sensitive help for the configure LPTX:
  277. port and the dialog for adding a local port.
  278. Arguments:
  279. UINT uMsg,
  280. HWND hDlg,
  281. WPARAM wParam,
  282. LPARAM lParam
  283. Return Value:
  284. TRUE if message handled, otherwise FALSE.
  285. --*/
  286. BOOL
  287. LocalUIHelp(
  288. IN HWND hDlg,
  289. IN UINT uMsg,
  290. IN WPARAM wParam,
  291. IN LPARAM lParam
  292. )
  293. {
  294. BOOL bStatus = FALSE;
  295. switch( uMsg ){
  296. case WM_HELP:
  297. bStatus = WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  298. szHelpFile,
  299. HELP_WM_HELP,
  300. (ULONG_PTR)g_aHelpIDs );
  301. break;
  302. case WM_CONTEXTMENU:
  303. bStatus = WinHelp((HWND)wParam,
  304. szHelpFile,
  305. HELP_CONTEXTMENU,
  306. (ULONG_PTR)g_aHelpIDs );
  307. break;
  308. }
  309. return bStatus;
  310. }