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.

366 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: S A U I . C P P
  7. //
  8. // Contents: Shared Access connection object UI
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 16 Oct 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "ncnetcon.h"
  18. #include "saui.h"
  19. #include "ncreg.h"
  20. #include "nsres.h"
  21. extern const WCHAR c_szNetCfgHelpFile[];
  22. static const WCHAR c_szShowIcon[] = L"Show Icon";
  23. static const WCHAR c_szSharedAccessClientKeyPath[] = L"System\\CurrentControlSet\\Control\\Network\\SharedAccessConnection";
  24. CSharedAccessPage::CSharedAccessPage(
  25. IUnknown* punk,
  26. INetCfg* pnc,
  27. INetConnection* pconn,
  28. BOOLEAN fReadOnly,
  29. BOOLEAN fNeedReboot,
  30. BOOLEAN fAccessDenied,
  31. const DWORD * adwHelpIDs)
  32. {
  33. m_pconn = pconn; // REVIEW addref?
  34. m_pnc = pnc;
  35. m_punk = punk;
  36. m_fReadOnly = fReadOnly;
  37. m_adwHelpIDs = adwHelpIDs;
  38. m_fNetcfgInUse = FALSE;
  39. m_pNetSharedAccessConnection = NULL;
  40. }
  41. //+---------------------------------------------------------------------------
  42. //
  43. // Member: CSharedAccessPage::~CSharedAccessPage
  44. //
  45. // Purpose: Destroys the CSharedAccessPage object
  46. //
  47. // Arguments:
  48. // (none)
  49. //
  50. // Returns: Nothing
  51. //
  52. // Author: danielwe 25 Feb 1998
  53. //
  54. // Notes:
  55. //
  56. CSharedAccessPage::~CSharedAccessPage()
  57. {
  58. if (m_pnc)
  59. {
  60. INetCfgLock * pnclock;
  61. if (SUCCEEDED(m_pnc->QueryInterface(IID_INetCfgLock,
  62. (LPVOID *)&pnclock)))
  63. {
  64. (VOID)pnclock->ReleaseWriteLock();
  65. ReleaseObj(pnclock);
  66. }
  67. }
  68. if(NULL != m_pNetSharedAccessConnection)
  69. {
  70. ReleaseObj(m_pNetSharedAccessConnection);
  71. }
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Member: CSharedAccessPage::OnInitDialog
  76. //
  77. // Purpose: Handles the WM_INITDIALOG message
  78. //
  79. // Arguments:
  80. // uMsg []
  81. // wParam []
  82. // lParam []
  83. // bHandled []
  84. //
  85. // Returns: TRUE
  86. //
  87. // Author: danielwe 29 Oct 1997
  88. //
  89. // Notes:
  90. //
  91. LRESULT CSharedAccessPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  92. LPARAM lParam, BOOL& bHandled)
  93. {
  94. HRESULT hr;
  95. // set the text field
  96. NETCON_PROPERTIES* pProperties;
  97. hr = m_pconn->GetProperties(&pProperties);
  98. if(SUCCEEDED(hr))
  99. {
  100. SetDlgItemText(IDC_EDT_Adapter, pProperties->pszwDeviceName);
  101. FreeNetconProperties(pProperties);
  102. }
  103. // set the icon
  104. int cx = GetSystemMetrics(SM_CXSMICON);
  105. int cy = GetSystemMetrics(SM_CYSMICON);
  106. HICON hIcon = (HICON) LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_CFI_SAH_LAN), IMAGE_ICON, cx, cy, LR_DEFAULTCOLOR);
  107. if(NULL != hIcon)
  108. {
  109. SendDlgItemMessage(IDI_Device_Icon, STM_SETICON, reinterpret_cast<WPARAM>(hIcon), 0);
  110. ::ShowWindow(GetDlgItem(IDI_Device_Icon), SW_SHOW);
  111. }
  112. ASSERT(NULL == m_pNetSharedAccessConnection); // make sure we don't leak a ref
  113. hr = HrQIAndSetProxyBlanket(m_pconn, &m_pNetSharedAccessConnection);
  114. if (SUCCEEDED(hr))
  115. {
  116. SHAREDACCESSCON_INFO ConnectionInfo;
  117. hr = m_pNetSharedAccessConnection->GetInfo(SACIF_ICON, &ConnectionInfo);
  118. if (SUCCEEDED(hr))
  119. {
  120. CheckDlgButton(IDC_CHK_ShowIcon, ConnectionInfo.fShowIcon);
  121. }
  122. // released in destructor
  123. }
  124. return TRUE;
  125. }
  126. //+---------------------------------------------------------------------------
  127. //
  128. // Member: CSharedAccessPage::OnContextMenu
  129. //
  130. // Purpose: When right click a control, bring up help
  131. //
  132. // Arguments: Standard command parameters
  133. //
  134. // Returns: Standard return
  135. //
  136. LRESULT
  137. CSharedAccessPage::OnContextMenu(UINT uMsg,
  138. WPARAM wParam,
  139. LPARAM lParam,
  140. BOOL& fHandled)
  141. {
  142. if (m_adwHelpIDs != NULL)
  143. {
  144. ::WinHelp(m_hWnd,
  145. c_szNetCfgHelpFile,
  146. HELP_CONTEXTMENU,
  147. (ULONG_PTR)m_adwHelpIDs);
  148. }
  149. return 0;
  150. }
  151. //+---------------------------------------------------------------------------
  152. //
  153. // Member: CSharedAccessPage::OnHelp
  154. //
  155. // Purpose: When drag context help icon over a control, bring up help
  156. //
  157. // Arguments: Standard command parameters
  158. //
  159. // Returns: Standard return
  160. //
  161. LRESULT
  162. CSharedAccessPage::OnHelp( UINT uMsg,
  163. WPARAM wParam,
  164. LPARAM lParam,
  165. BOOL& fHandled)
  166. {
  167. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  168. Assert(lphi);
  169. if ((m_adwHelpIDs != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  170. {
  171. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  172. c_szNetCfgHelpFile,
  173. HELP_WM_HELP,
  174. (ULONG_PTR)m_adwHelpIDs);
  175. }
  176. return 0;
  177. }
  178. //+---------------------------------------------------------------------------
  179. //
  180. // Member: CSharedAccessPage::OnDestroy
  181. //
  182. // Purpose: Called when the dialog page is destroyed
  183. //
  184. // Arguments:
  185. // uMsg []
  186. // wParam []
  187. // lParam []
  188. // bHandled []
  189. //
  190. // Returns:
  191. //
  192. // Author: danielwe 2 Feb 1998
  193. //
  194. // Notes:
  195. //
  196. LRESULT CSharedAccessPage::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam,
  197. BOOL& bHandled)
  198. {
  199. HICON hIcon;
  200. hIcon = reinterpret_cast<HICON>(SendDlgItemMessage(IDI_Device_Icon, STM_GETICON, 0, 0));
  201. if (hIcon)
  202. {
  203. DestroyIcon(hIcon);
  204. }
  205. return 0;
  206. }
  207. //+---------------------------------------------------------------------------
  208. //
  209. // Member: CSharedAccessPage::OnApply
  210. //
  211. // Purpose: Called when the Networking page is applied
  212. //
  213. // Arguments:
  214. // idCtrl []
  215. // pnmh []
  216. // bHandled []
  217. //
  218. // Returns:
  219. //
  220. // Author: danielwe 29 Oct 1997
  221. //
  222. // Notes:
  223. //
  224. LRESULT CSharedAccessPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  225. {
  226. HRESULT hr = S_OK;
  227. if(NULL != m_pNetSharedAccessConnection)
  228. {
  229. SHAREDACCESSCON_INFO ConnectionInfo = {0};
  230. ConnectionInfo.fShowIcon = IsDlgButtonChecked(IDC_CHK_ShowIcon);
  231. hr = m_pNetSharedAccessConnection->SetInfo(SACIF_ICON, &ConnectionInfo);
  232. }
  233. return 0;
  234. }
  235. //+---------------------------------------------------------------------------
  236. //
  237. // Member: CSharedAccessPage::OnCancel
  238. //
  239. // Purpose: Called when the Networking page is cancelled.
  240. //
  241. // Arguments:
  242. // idCtrl []
  243. // pnmh []
  244. // bHandled []
  245. //
  246. // Returns:
  247. //
  248. // Author: danielwe 3 Jan 1998
  249. //
  250. // Notes: Added the check to see if we are in the middle of
  251. // installing components, in which case we can't
  252. // uninitialize INetCfg (Raid #258690).
  253. //
  254. LRESULT CSharedAccessPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  255. {
  256. AssertSz(m_pnc, "I need a NetCfg object!");
  257. if (!m_fNetcfgInUse)
  258. {
  259. (VOID) m_pnc->Uninitialize();
  260. }
  261. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, m_fNetcfgInUse);
  262. return m_fNetcfgInUse;
  263. }
  264. LRESULT CSharedAccessPage::OnClicked (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  265. {
  266. if (wID != IDC_PSB_Settings)
  267. return bHandled = FALSE;
  268. /* new improved way:
  269. get upnp service from INetSharedAccessConnection
  270. call hnetcfg's HNetGetSharingServicesPage
  271. create the property page
  272. */
  273. NETCON_MEDIATYPE MediaType;
  274. NETCON_PROPERTIES* pProperties;
  275. HRESULT hr = m_pconn->GetProperties(&pProperties);
  276. if (SUCCEEDED(hr))
  277. {
  278. MediaType = pProperties->MediaType;
  279. FreeNetconProperties(pProperties);
  280. }
  281. else
  282. {
  283. return bHandled = FALSE;
  284. }
  285. if ((MediaType != NCM_SHAREDACCESSHOST_LAN) &&
  286. (MediaType != NCM_SHAREDACCESSHOST_RAS) )
  287. return bHandled = FALSE;
  288. BOOL b = FALSE;
  289. CComPtr<IUPnPService> spUPS = NULL;
  290. hr = m_pNetSharedAccessConnection->GetService (
  291. MediaType == NCM_SHAREDACCESSHOST_LAN ?
  292. SAHOST_SERVICE_WANIPCONNECTION :
  293. SAHOST_SERVICE_WANPPPCONNECTION,
  294. &spUPS);
  295. if (spUPS) {
  296. // must run-time load "HNetGetSharingServicesPage",
  297. // else netshell.dll and hnetcfg.dll are cross-linked.
  298. HINSTANCE hinstDll = LoadLibrary (TEXT("hnetcfg.dll"));
  299. if (!hinstDll)
  300. hr = HRESULT_FROM_WIN32 (GetLastError());
  301. else {
  302. HRESULT (APIENTRY *pfnHNetGetSharingServicesPage)(IUPnPService *, PROPSHEETPAGE *);
  303. pfnHNetGetSharingServicesPage = (HRESULT (APIENTRY *)(IUPnPService *, PROPSHEETPAGE *))
  304. GetProcAddress (hinstDll, "HNetGetSharingServicesPage");
  305. if (!pfnHNetGetSharingServicesPage)
  306. hr = HRESULT_FROM_WIN32 (GetLastError());
  307. else {
  308. PROPSHEETPAGE psp;
  309. ZeroMemory (&psp, sizeof(psp));
  310. psp.dwSize = sizeof(psp);
  311. psp.lParam = (LPARAM)m_hWnd; // double-secret place to hang owner window (will get wiped)
  312. hr = pfnHNetGetSharingServicesPage (spUPS, &psp);
  313. if (SUCCEEDED(hr)) {
  314. b = TRUE;
  315. PROPSHEETHEADER psh;
  316. ZeroMemory (&psh, sizeof(psh));
  317. psh.dwSize = PROPSHEETHEADER_V1_SIZE;
  318. psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP;
  319. psh.hwndParent = m_hWnd;
  320. psh.pszCaption = (LPCTSTR)MAKEINTRESOURCE (IDS_SHAREDACCESSSETTINGS);
  321. psh.hInstance = _Module.GetResourceInstance();
  322. psh.nPages = 1;
  323. psh.ppsp = &psp;
  324. PropertySheet (&psh);
  325. }
  326. }
  327. FreeLibrary (hinstDll);
  328. }
  329. }
  330. return b;
  331. }