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.

316 lines
8.2 KiB

  1. #include "stdafx.h"
  2. #include "RoutingMethodProp.h"
  3. #include "RoutingMethodConfig.h"
  4. #include <faxutil.h>
  5. #include <faxreg.h>
  6. #include <faxres.h>
  7. #include <PrintConfigPage.h>
  8. #include <Util.h>
  9. HRESULT
  10. CPrintConfigPage::Init(
  11. LPCTSTR lpctstrServerName,
  12. DWORD dwDeviceId
  13. )
  14. {
  15. DEBUG_FUNCTION_NAME(TEXT("CPrintConfigPage::Init"));
  16. DWORD ec = ERROR_SUCCESS;
  17. m_bstrServerName = lpctstrServerName;
  18. m_dwDeviceId = dwDeviceId;
  19. if (!m_bstrServerName)
  20. {
  21. DebugPrintEx(
  22. DEBUG_ERR,
  23. TEXT("Out of memory while copying server name (ec: %ld)")
  24. );
  25. ec = ERROR_NOT_ENOUGH_MEMORY;
  26. DisplayRpcErrorMessage(ERROR_NOT_ENOUGH_MEMORY, IDS_PRINT_TITLE, m_hWnd);
  27. goto exit;
  28. }
  29. if (!FaxConnectFaxServer(lpctstrServerName, &m_hFax))
  30. {
  31. ec = GetLastError();
  32. DebugPrintEx(
  33. DEBUG_ERR,
  34. TEXT("FaxConnectFaxServer failed (ec: %ld)"),
  35. ec);
  36. DisplayRpcErrorMessage(ec, IDS_PRINT_TITLE, m_hWnd);
  37. goto exit;
  38. }
  39. //
  40. // Retrieve the data
  41. //
  42. ec = ReadExtStringData (
  43. m_hFax,
  44. m_dwDeviceId,
  45. REGVAL_RM_PRINTING_GUID,
  46. m_bstrPrinter,
  47. TEXT(""),
  48. IDS_PRINT_TITLE,
  49. m_hWnd);
  50. if (ERROR_SUCCESS != ec)
  51. {
  52. DebugPrintEx(
  53. DEBUG_ERR,
  54. TEXT("ReadExtStringData() failed. (ec: %ld)"),
  55. ec);
  56. goto exit;
  57. }
  58. exit:
  59. if ((ERROR_SUCCESS != ec) && m_hFax)
  60. {
  61. if (!FaxClose(m_hFax))
  62. {
  63. DebugPrintEx(
  64. DEBUG_ERR,
  65. TEXT("FaxClose() failed on fax handle (0x%08X : %s). (ec: %ld)"),
  66. m_hFax,
  67. m_bstrServerName,
  68. GetLastError());
  69. }
  70. m_hFax = NULL;
  71. }
  72. return HRESULT_FROM_WIN32(ec);
  73. } // CPrintConfigPage::Init
  74. LRESULT CPrintConfigPage::OnInitDialog(
  75. UINT uiMsg,
  76. WPARAM wParam,
  77. LPARAM lParam,
  78. BOOL& fHandled
  79. )
  80. {
  81. DEBUG_FUNCTION_NAME( _T("CPrintConfigPage::OnInitDialog"));
  82. HINSTANCE hInst = _Module.GetResourceInstance();
  83. SetLTRComboBox(m_hWnd, IDC_PRINTERS_COMBO);
  84. //
  85. // Attach controls
  86. //
  87. m_PrintersCombo.Attach(GetDlgItem(IDC_PRINTERS_COMBO));
  88. m_PrintersCombo.LimitText(MAX_PATH-1);
  89. //
  90. // Init printers drop-down box
  91. //
  92. m_pPrinterNames = CollectPrinterNames (&m_dwNumOfPrinters, TRUE);
  93. if (!m_pPrinterNames)
  94. {
  95. if (ERROR_PRINTER_NOT_FOUND == GetLastError ())
  96. {
  97. //
  98. // No printers
  99. //
  100. }
  101. else
  102. {
  103. //
  104. // Real error
  105. //
  106. }
  107. m_PrintersCombo.SetCurSel(-1);
  108. m_PrintersCombo.SetWindowText(m_bstrPrinter);
  109. }
  110. else
  111. {
  112. //
  113. // Success - fill in the combo-box
  114. //
  115. DWORD dw;
  116. LPCWSTR lpcwstrMatchingText;
  117. for (dw = 0; dw < m_dwNumOfPrinters; dw++)
  118. {
  119. m_PrintersCombo.AddString (m_pPrinterNames[dw].lpcwstrDisplayName);
  120. }
  121. //
  122. // Now find out if we match the data the server has
  123. //
  124. if (lstrlen(m_bstrPrinter))
  125. {
  126. //
  127. // Server has some name for printer
  128. //
  129. lpcwstrMatchingText = FindPrinterNameFromPath (m_pPrinterNames, m_dwNumOfPrinters, m_bstrPrinter);
  130. if (!lpcwstrMatchingText)
  131. {
  132. //
  133. // No match, just fill in the text we got from the server
  134. //
  135. m_PrintersCombo.SetCurSel(-1);
  136. m_PrintersCombo.SetWindowText(m_bstrPrinter);
  137. }
  138. else
  139. {
  140. m_PrintersCombo.SelectString(-1, lpcwstrMatchingText);
  141. }
  142. }
  143. else
  144. {
  145. //
  146. // No server configuation - select nothing
  147. //
  148. }
  149. }
  150. m_fIsDialogInitiated = TRUE;
  151. return 1;
  152. }
  153. BOOL
  154. CPrintConfigPage::OnApply()
  155. {
  156. DEBUG_FUNCTION_NAME(TEXT("CPrintConfigPage::OnApply"));
  157. if (!m_fIsDirty)
  158. {
  159. return TRUE;
  160. }
  161. //
  162. // Get the selected printer name
  163. //
  164. if (!m_PrintersCombo.GetWindowText(&m_bstrPrinter))
  165. {
  166. DebugPrintEx( DEBUG_ERR, _T("Out of Memory - fail to set string."));
  167. DisplayErrorMessage (IDS_PRINT_TITLE, IDS_FAIL2READPRINTER, FALSE, m_hWnd);
  168. return FALSE;
  169. }
  170. //
  171. // Check data validity
  172. //
  173. if (0 == m_bstrPrinter.Length())
  174. {
  175. DebugPrintEx( DEBUG_ERR, _T("Zero length string."));
  176. DisplayErrorMessage (IDS_PRINT_TITLE, IDS_EMPTY_PRINTERNAME, FALSE, m_hWnd);
  177. return FALSE;
  178. }
  179. //
  180. // Attempt to convert printer name to path
  181. //
  182. LPCWSTR lpcwstrPrinterPath = FindPrinterPathFromName (m_pPrinterNames, m_dwNumOfPrinters, m_bstrPrinter);
  183. if (lpcwstrPrinterPath)
  184. {
  185. //
  186. // We have a matching path - replace name with path.
  187. //
  188. m_bstrPrinter = lpcwstrPrinterPath;
  189. if (!m_bstrPrinter)
  190. {
  191. DebugPrintEx( DEBUG_ERR, _T("Out of Memory - fail to alloc string."));
  192. DisplayErrorMessage (IDS_PRINT_TITLE, IDS_FAIL2READPRINTER, FALSE, m_hWnd);
  193. return FALSE;
  194. }
  195. }
  196. //
  197. // Write the data using RPC
  198. //
  199. if (ERROR_SUCCESS != WriteExtData (m_hFax,
  200. m_dwDeviceId,
  201. REGVAL_RM_PRINTING_GUID,
  202. (LPBYTE)(LPCWSTR)m_bstrPrinter,
  203. sizeof (WCHAR) * (1 + m_bstrPrinter.Length()),
  204. IDS_PRINT_TITLE,
  205. m_hWnd))
  206. {
  207. return FALSE;
  208. }
  209. //
  210. // Success
  211. //
  212. m_fIsDirty = FALSE;
  213. return TRUE;
  214. } // CPrintConfigPage::OnApply
  215. /*
  216. +
  217. +
  218. * CPrintConfigPage::OnComboChanged
  219. -
  220. -
  221. */
  222. LRESULT
  223. CPrintConfigPage::OnComboChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  224. {
  225. DEBUG_FUNCTION_NAME( _T("CPrintConfigPage::OnComboChanged"));
  226. if (!m_fIsDialogInitiated) //event was receieved in a too early stage
  227. {
  228. return 0;
  229. }
  230. else
  231. {
  232. switch (wNotifyCode)
  233. {
  234. case CBN_SELCHANGE: //assumption: all the registered printer names are valid
  235. SetModified(TRUE);
  236. m_fIsDirty = TRUE;
  237. break;
  238. case CBN_EDITCHANGE:
  239. if ( 0 == m_PrintersCombo.GetWindowTextLength() )
  240. {
  241. SetModified(FALSE);
  242. }
  243. else
  244. {
  245. SetModified(TRUE);
  246. m_fIsDirty = TRUE;
  247. }
  248. break;
  249. default:
  250. ATLASSERT(FALSE);
  251. }
  252. }
  253. return 0;
  254. }
  255. //////////////////////////////////////////////////////////////////////////////
  256. /*++
  257. CPrintConfigPage::OnHelpRequest
  258. This is called in response to the WM_HELP Notify
  259. message and to the WM_CONTEXTMENU Notify message.
  260. WM_HELP Notify message.
  261. This message is sent when the user presses F1 or <Shift>-F1
  262. over an item or when the user clicks on the ? icon and then
  263. presses the mouse over an item.
  264. WM_CONTEXTMENU Notify message.
  265. This message is sent when the user right clicks over an item
  266. and then clicks "What's this?"
  267. --*/
  268. /////////////////////////////////////////////////////////////////////////////
  269. LRESULT
  270. CPrintConfigPage::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  271. {
  272. DEBUG_FUNCTION_NAME(_T("CPrintConfigPage::OnHelpRequest"));
  273. switch (uMsg)
  274. {
  275. case WM_HELP:
  276. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  277. break;
  278. case WM_CONTEXTMENU:
  279. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  280. break;
  281. }
  282. return TRUE;
  283. }