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.

219 lines
5.9 KiB

  1. // IFaxControl.cpp : Implementation of CFaxControl
  2. #include "stdafx.h"
  3. #include "FaxControl.h"
  4. #include "IFaxControl.h"
  5. #include "faxocm.h"
  6. #include "faxres.h"
  7. #include <faxsetup.h>
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CFaxControl
  10. FaxInstallationReportType g_InstallReportType = REPORT_FAX_DETECT;
  11. //
  12. // IsFaxInstalled and InstallFaxUnattended are implemented in fxocprnt.cpp
  13. //
  14. DWORD
  15. IsFaxInstalled (
  16. LPBOOL lpbInstalled
  17. );
  18. //
  19. // This function is trying to get the last active popup of the top
  20. // level owner of the current thread active window.
  21. //
  22. HRESULT GetCurrentThreadLastPopup(HWND *phwnd)
  23. {
  24. HRESULT hr = E_INVALIDARG;
  25. if( phwnd )
  26. {
  27. hr = E_FAIL;
  28. if( NULL == *phwnd )
  29. {
  30. // if *phwnd is NULL then get the current thread active window
  31. GUITHREADINFO ti = {0};
  32. ti.cbSize = sizeof(ti);
  33. if( GetGUIThreadInfo(GetCurrentThreadId(), &ti) && ti.hwndActive )
  34. {
  35. *phwnd = ti.hwndActive;
  36. }
  37. }
  38. if( *phwnd )
  39. {
  40. HWND hwndOwner, hwndParent;
  41. // climb up to the top parent in case it's a child window...
  42. while( hwndParent = GetParent(*phwnd) )
  43. {
  44. *phwnd = hwndParent;
  45. }
  46. // get the owner in case the top parent is owned
  47. hwndOwner = GetWindow(*phwnd, GW_OWNER);
  48. if( hwndOwner )
  49. {
  50. *phwnd = hwndOwner;
  51. }
  52. // get the last popup of the owner of the top level parent window
  53. *phwnd = GetLastActivePopup(*phwnd);
  54. hr = (*phwnd) ? S_OK : E_FAIL;
  55. }
  56. }
  57. return hr;
  58. }
  59. ///////////////////////////////////////////////////////////////////////////////////////
  60. // Function:
  61. // DisplayErrorMessage
  62. //
  63. // Purpose:
  64. // Load FXSRES.DLL and load an error message string from it
  65. // Display this string in a message box
  66. // Ideally, we would have added the error message dialog to this module
  67. // but this is added in a time of UI freeze (close to RTM) and the only
  68. // place we have such a dialog is FXSRES.DLL
  69. //
  70. // Params:
  71. // Error code
  72. //
  73. // Return Value:
  74. // NO_ERROR - everything was ok.
  75. // Win32 Error code in case if failure.
  76. //
  77. // Author:
  78. // Mooly Beery (MoolyB) 19-Jul-2001
  79. ///////////////////////////////////////////////////////////////////////////////////////
  80. static DWORD DisplayErrorMessage(DWORD ec)
  81. {
  82. DWORD dwReturn = NO_ERROR;
  83. HMODULE hModule = NULL;
  84. HWND hWnd = NULL;
  85. TCHAR tszMessage[MAX_PATH] = {0};
  86. UINT uResourceId = 0;
  87. DBG_ENTER(_T("DisplayErrorMessage"), dwReturn);
  88. hModule = GetResInstance(NULL);
  89. if (!hModule)
  90. {
  91. return dwReturn;
  92. }
  93. // get the string id
  94. uResourceId = GetErrorStringId(ec);
  95. dwReturn = LoadString(hModule,uResourceId,tszMessage,MAX_PATH);
  96. if (dwReturn==0)
  97. {
  98. //
  99. // Resource string is not found
  100. //
  101. dwReturn = GetLastError();
  102. VERBOSE(DBG_WARNING, _T("LoadString() failed, ec = %ld."), dwReturn);
  103. goto exit;
  104. }
  105. // try to get the windows handle for the current thread.
  106. if (FAILED(GetCurrentThreadLastPopup(&hWnd)))
  107. {
  108. CALL_FAIL(GENERAL_ERR,TEXT("GetCurrentThreadLastPopup"), GetLastError());
  109. hWnd = NULL;
  110. }
  111. // show the message
  112. MessageBox(hWnd,tszMessage,NULL,MB_OK | MB_ICONERROR | MB_TOPMOST);
  113. exit:
  114. FreeResInstance();
  115. return dwReturn;
  116. }
  117. STDMETHODIMP CFaxControl::get_IsFaxServiceInstalled(VARIANT_BOOL *pbResult)
  118. {
  119. HRESULT hr;
  120. BOOL bRes;
  121. DBG_ENTER(_T("CFaxControl::get_IsFaxServiceInstalled"), hr);
  122. DWORD dwRes = ERROR_SUCCESS;
  123. switch (g_InstallReportType)
  124. {
  125. case REPORT_FAX_INSTALLED:
  126. bRes = TRUE;
  127. break;
  128. case REPORT_FAX_UNINSTALLED:
  129. bRes = FALSE;
  130. break;
  131. case REPORT_FAX_DETECT:
  132. dwRes = IsFaxInstalled (&bRes);
  133. break;
  134. default:
  135. ASSERTION_FAILURE;
  136. bRes = FALSE;
  137. break;
  138. }
  139. if (ERROR_SUCCESS == dwRes)
  140. {
  141. *pbResult = bRes ? VARIANT_TRUE : VARIANT_FALSE;
  142. }
  143. hr = HRESULT_FROM_WIN32 (dwRes);
  144. return hr;
  145. }
  146. STDMETHODIMP CFaxControl::get_IsLocalFaxPrinterInstalled(VARIANT_BOOL *pbResult)
  147. {
  148. HRESULT hr;
  149. BOOL bRes;
  150. DBG_ENTER(_T("CFaxControl::get_IsLocalFaxPrinterInstalled"), hr);
  151. DWORD dwRes = ::IsLocalFaxPrinterInstalled (&bRes);
  152. if (ERROR_SUCCESS == dwRes)
  153. {
  154. *pbResult = bRes ? VARIANT_TRUE : VARIANT_FALSE;
  155. }
  156. hr = HRESULT_FROM_WIN32 (dwRes);
  157. return hr;
  158. }
  159. STDMETHODIMP CFaxControl::InstallFaxService()
  160. {
  161. HRESULT hr;
  162. DBG_ENTER(_T("CFaxControl::InstallFaxService"), hr);
  163. DWORD dwRes = InstallFaxUnattended ();
  164. hr = HRESULT_FROM_WIN32 (dwRes);
  165. return hr;
  166. }
  167. STDMETHODIMP CFaxControl::InstallLocalFaxPrinter()
  168. {
  169. HRESULT hr;
  170. DWORD dwRes = ERROR_SUCCESS;
  171. DBG_ENTER(_T("CFaxControl::InstallLocalFaxPrinter"), hr);
  172. dwRes = AddLocalFaxPrinter (FAX_PRINTER_NAME, NULL);
  173. if (dwRes!=ERROR_SUCCESS)
  174. {
  175. // fail to add the local fax printer
  176. // display an error message
  177. if (DisplayErrorMessage(dwRes)!=ERROR_SUCCESS)
  178. {
  179. CALL_FAIL(GENERAL_ERR,TEXT("DisplayErrorMessage"), GetLastError());
  180. }
  181. }
  182. hr = HRESULT_FROM_WIN32 (dwRes);
  183. return hr;
  184. }