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.

212 lines
6.0 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: condlg.cpp
  3. *
  4. * Author: David Stewart [dstewart]
  5. *
  6. * Copyright (c) 1998 Microsoft Corporation. All rights reserved.
  7. \**************************************************************************/
  8. #include "windows.h"
  9. #include "condlg.h"
  10. #include "netres.h"
  11. #include "..\cdopt\cdopt.h"
  12. #include <htmlhelp.h>
  13. #include "icwcfg.h"
  14. extern HINSTANCE g_dllInst;
  15. TCHAR g_Drive;
  16. BOOL InternetConnectionWizardHasRun()
  17. {
  18. HKEY hKey;
  19. DWORD dwICWCompleted = 0;
  20. if (RegOpenKey(HKEY_CURRENT_USER, TEXT(ICW_REGPATHSETTINGS), &hKey) == ERROR_SUCCESS)
  21. {
  22. DWORD dwSize = sizeof(dwICWCompleted);
  23. RegQueryValueEx(hKey, TEXT(ICW_REGKEYCOMPLETED), NULL, NULL, (LPBYTE)&dwICWCompleted, &dwSize);
  24. RegCloseKey(hKey);
  25. }
  26. if (dwICWCompleted > 0)
  27. {
  28. return TRUE;
  29. }
  30. return FALSE;
  31. }
  32. void LaunchICW()
  33. {
  34. HINSTANCE hInetCfgDll = LoadLibrary(TEXT("inetcfg.dll"));
  35. if (hInetCfgDll)
  36. {
  37. PFNCHECKCONNECTIONWIZARD fp = (PFNCHECKCONNECTIONWIZARD)GetProcAddress(hInetCfgDll, "CheckConnectionWizard");
  38. if (fp)
  39. {
  40. DWORD dwRet;
  41. DWORD dwFlags = ICW_LAUNCHFULL | ICW_LAUNCHMANUAL | ICW_FULL_SMARTSTART;
  42. // Launch ICW full or manual path, whichever is available
  43. // NOTE: the ICW code makes sure only a single instance is up
  44. fp(dwFlags, &dwRet);
  45. }
  46. FreeLibrary(hInetCfgDll);
  47. }
  48. }
  49. BOOL _InternetGetConnectedState(DWORD* pdwHow, DWORD dwReserved, BOOL fConnect)
  50. {
  51. //note: to make this work on Win95 machines, set retval to true by default
  52. BOOL retval = FALSE;
  53. //check to see if we have configured the connection already
  54. if (!InternetConnectionWizardHasRun())
  55. {
  56. //nope, so we need to run the ICW and return FALSE here
  57. LaunchICW();
  58. return FALSE;
  59. }
  60. HMODULE hNet = LoadLibrary(TEXT("WININET.DLL"));
  61. if (hNet!=NULL)
  62. {
  63. typedef BOOL (PASCAL *CONPROC)(DWORD*, DWORD);
  64. CONPROC conProc = (CONPROC)GetProcAddress(hNet,"InternetGetConnectedState");
  65. if (conProc)
  66. {
  67. retval = conProc(pdwHow,dwReserved);
  68. if ((!retval) && (*pdwHow &1)) //INTERNET_CONNECTION_MODEM
  69. {
  70. if (fConnect)
  71. {
  72. typedef BOOL (PASCAL *DIALPROC)(DWORD, DWORD);
  73. DIALPROC dialProc = (DIALPROC)GetProcAddress(hNet,"InternetAutodial");
  74. if (dialProc)
  75. {
  76. retval = dialProc(1,0); //INTERNET_AUTODIAL_FORCE_ONLINE
  77. }
  78. } //end if connect
  79. } //end if not online, but with a modem
  80. } //end if connection proc available
  81. FreeLibrary(hNet);
  82. }
  83. return (retval);
  84. }
  85. INT_PTR CALLBACK ConDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  86. {
  87. static LPCDOPTDATA pOptionData = NULL;
  88. switch (message)
  89. {
  90. case WM_INITDIALOG :
  91. {
  92. pOptionData = (LPCDOPTDATA)lParam;
  93. SendDlgItemMessage(hwnd,IDC_RADIO_DOWNLOAD_ONE,BM_SETCHECK,1,0);
  94. RECT rectDialog;
  95. GetWindowRect(hwnd,&rectDialog);
  96. SetWindowPos(hwnd,
  97. GetParent(hwnd),
  98. (GetSystemMetrics(SM_CXSCREEN)/2) - ((rectDialog.right - rectDialog.left) /2),
  99. (GetSystemMetrics(SM_CYSCREEN)/2) - ((rectDialog.bottom - rectDialog.top) /2),
  100. 0,
  101. 0,
  102. SWP_NOSIZE);
  103. //title of dialog is a "format string" with room for a single char drive letter
  104. TCHAR szFormat[MAX_PATH];
  105. TCHAR szTitle[MAX_PATH];
  106. GetWindowText(hwnd,szFormat,sizeof(szFormat)/sizeof(TCHAR));
  107. wsprintf(szTitle,szFormat,g_Drive);
  108. SetWindowText(hwnd,szTitle);
  109. }
  110. break;
  111. case WM_COMMAND :
  112. {
  113. switch (LOWORD(wParam))
  114. {
  115. case (IDOK) :
  116. {
  117. if (SendDlgItemMessage(hwnd,IDC_RADIO_DOWNLOAD_ALL,BM_GETCHECK,0,0))
  118. {
  119. pOptionData->fDownloadPrompt = FALSE;
  120. }
  121. EndDialog(hwnd,CONNECTION_GETITNOW);
  122. }
  123. break;
  124. case (IDCANCEL) :
  125. {
  126. if (pOptionData->fBatchEnabled)
  127. {
  128. EndDialog(hwnd,CONNECTION_BATCH);
  129. }
  130. else
  131. {
  132. EndDialog(hwnd,CONNECTION_DONOTHING);
  133. }
  134. }
  135. break;
  136. case (IDC_DOWNLOAD_HELP) :
  137. {
  138. #ifndef DEBUG
  139. HtmlHelp(hwnd, TEXT("deluxcd.chm>main"), HH_DISPLAY_TOPIC, (DWORD_PTR) TEXT("CDX_overview.htm"));
  140. #endif
  141. }
  142. break;
  143. } // end switch on WM_COMMAND
  144. } //end case WM_COMMAND
  145. break;
  146. }
  147. return FALSE;
  148. }
  149. int ConnectionCheck(HWND hwndParent, void* pPassedOpt, TCHAR chDrive)
  150. {
  151. if (!pPassedOpt)
  152. {
  153. return CONNECTION_DONOTHING;
  154. }
  155. LPCDOPT pOpt = (LPCDOPT)pPassedOpt;
  156. LPCDOPTIONS pOptions = pOpt->GetCDOpts();
  157. LPCDOPTDATA pOptionData = pOptions->pCDData;
  158. if ((pOptionData->fDownloadPrompt) && (pOptionData->fDownloadEnabled))
  159. {
  160. //set global drive letter for dialog box
  161. g_Drive = chDrive;
  162. //no options selected, so prompt instead
  163. int nSelection = (int)DialogBoxParam(g_dllInst, MAKEINTRESOURCE(IDD_DIALOG_DOWNLOAD),
  164. hwndParent, ConDlgProc, (LPARAM)pOptionData );
  165. pOpt->UpdateRegistry();
  166. return nSelection;
  167. }
  168. if (pOptionData->fDownloadEnabled)
  169. {
  170. return CONNECTION_GETITNOW;
  171. }
  172. if (pOptionData->fBatchEnabled)
  173. {
  174. return CONNECTION_BATCH;
  175. }
  176. return CONNECTION_DONOTHING;
  177. }