4 /// {7007ACC5-3202-11D1-AAD2-00805FC1270E}
5 /// open network properties and wlan properties
17 DWORD dwCharacteristics
;
19 INetCfgComponent
*pNCfgComp
;
20 UINT NumPropDialogOpen
;
21 }NET_ITEM
, *PNET_ITEM
;
25 INetConnectionPropertyUi2
*lpVtbl
;
26 INetLanConnectionUiInfo
* lpLanConUiInfoVtbl
;
27 INetConnectionConnectUi
* lpNetConnectionConnectUi
;
28 INetConnection
* pCon
;
29 INetCfgLock
*NCfgLock
;
31 NETCON_PROPERTIES
* pProperties
;
33 }INetConnectionPropertyUiImpl
, *LPINetConnectionPropertyUiImpl
;
35 static __inline LPINetConnectionPropertyUiImpl
impl_from_NetLanConnectionUiInfo(INetLanConnectionUiInfo
*iface
)
37 return (LPINetConnectionPropertyUiImpl
)((char *)iface
- FIELD_OFFSET(INetConnectionPropertyUiImpl
, lpLanConUiInfoVtbl
));
40 static __inline LPINetConnectionPropertyUiImpl
impl_from_NetConnectionConnectUi(INetConnectionConnectUi
*iface
)
42 return (LPINetConnectionPropertyUiImpl
)((char *)iface
- FIELD_OFFSET(INetConnectionPropertyUiImpl
, lpNetConnectionConnectUi
));
47 InitializePropertySheetPage(LPWSTR resname
, DLGPROC dlgproc
, LPARAM lParam
, LPWSTR szTitle
)
51 memset(&ppage
, 0x0, sizeof(PROPSHEETPAGEW
));
52 ppage
.dwSize
= sizeof(PROPSHEETPAGEW
);
53 ppage
.dwFlags
= PSP_DEFAULT
;
54 ppage
.u
.pszTemplate
= resname
;
55 ppage
.pfnDlgProc
= dlgproc
;
56 ppage
.lParam
= lParam
;
57 ppage
.hInstance
= netshell_hInstance
;
60 ppage
.dwFlags
|= PSP_USETITLE
;
61 ppage
.pszTitle
= szTitle
;
63 return CreatePropertySheetPageW(&ppage
);
67 AddItemToListView(HWND hDlgCtrl
, PNET_ITEM pItem
, LPWSTR szName
, BOOL bChecked
)
71 ZeroMemory(&lvItem
, sizeof(lvItem
));
72 lvItem
.mask
= LVIF_TEXT
| LVIF_PARAM
;
73 lvItem
.pszText
= szName
;
74 lvItem
.lParam
= (LPARAM
)pItem
;
75 lvItem
.iItem
= ListView_GetItemCount(hDlgCtrl
);
76 lvItem
.iItem
= SendMessageW(hDlgCtrl
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvItem
);
77 ListView_SetCheckState(hDlgCtrl
, lvItem
.iItem
, bChecked
);
81 GetINetCfgComponent(INetCfg
* pNCfg
, INetConnectionPropertyUiImpl
* This
, INetCfgComponent
** pOut
)
85 INetCfgComponent
* pNCg
;
87 IEnumNetCfgComponent
* pEnumCfg
;
89 hr
= INetCfg_EnumComponents(pNCfg
, &GUID_DEVCLASS_NET
, &pEnumCfg
);
95 while(IEnumNetCfgComponent_Next(pEnumCfg
, 1, &pNCg
, &Fetched
) == S_OK
)
97 hr
= INetCfgComponent_GetDisplayName(pNCg
, &pName
);
100 if (!_wcsicmp(pName
, This
->pProperties
->pszwDeviceName
))
103 IEnumNetCfgComponent_Release(pEnumCfg
);
106 CoTaskMemFree(pName
);
108 INetCfgComponent_Release(pNCg
);
110 IEnumNetCfgComponent_Release(pEnumCfg
);
115 EnumComponents(HWND hDlgCtrl
, INetConnectionPropertyUiImpl
* This
, INetCfg
* pNCfg
, const GUID
* CompGuid
, UINT Type
)
118 IEnumNetCfgComponent
* pENetCfg
;
119 INetCfgComponent
*pNCfgComp
, *pAdapterCfgComp
;
120 INetCfgComponentBindings
* pCompBind
;
122 DWORD dwCharacteristics
;
123 LPOLESTR pDisplayName
, pHelpText
;
127 hr
= INetCfg_EnumComponents(pNCfg
, CompGuid
, &pENetCfg
);
130 INetCfg_Release(pNCfg
);
133 while(IEnumNetCfgComponent_Next(pENetCfg
, 1, &pNCfgComp
, &Num
) == S_OK
)
135 hr
= INetCfgComponent_GetCharacteristics(pNCfgComp
, &dwCharacteristics
);
136 if (SUCCEEDED(hr
) && (dwCharacteristics
& NCF_HIDDEN
))
138 INetCfgComponent_Release(pNCfgComp
);
143 hr
= INetCfgComponent_GetDisplayName(pNCfgComp
, &pDisplayName
);
144 hr
= INetCfgComponent_GetHelpText(pNCfgComp
, &pHelpText
);
145 bChecked
= TRUE
; //ReactOS hack
146 hr
= INetCfgComponent_QueryInterface(pNCfgComp
, &IID_INetCfgComponentBindings
, (LPVOID
*)&pCompBind
);
149 if (GetINetCfgComponent(pNCfg
, This
, &pAdapterCfgComp
))
151 hr
= INetCfgComponentBindings_IsBoundTo(pCompBind
, pAdapterCfgComp
);
156 INetCfgComponent_Release(pAdapterCfgComp
);
157 INetCfgComponentBindings_Release(pCompBind
);
160 pItem
= CoTaskMemAlloc(sizeof(NET_ITEM
));
163 pItem
->dwCharacteristics
= dwCharacteristics
;
164 pItem
->szHelp
= pHelpText
;
166 pItem
->pNCfgComp
= pNCfgComp
;
167 pItem
->NumPropDialogOpen
= 0;
170 AddItemToListView(hDlgCtrl
, pItem
, pDisplayName
, bChecked
);
171 CoTaskMemFree(pDisplayName
);
173 IEnumNetCfgComponent_Release(pENetCfg
);
178 InitializeLANPropertiesUIDlg(HWND hwndDlg
, INetConnectionPropertyUiImpl
* This
)
182 INetCfgLock
* pNCfgLock
;
183 HWND hDlgCtrl
= GetDlgItem(hwndDlg
, IDC_COMPONENTSLIST
);
190 SendDlgItemMessageW(hwndDlg
, IDC_NETCARDNAME
, WM_SETTEXT
, 0, (LPARAM
)This
->pProperties
->pszwDeviceName
);
191 if (This
->pProperties
->dwCharacter
& NCCF_SHOW_ICON
)
193 /* check show item on taskbar*/
194 SendDlgItemMessageW(hwndDlg
, IDC_SHOWTASKBAR
, BM_SETCHECK
, BST_CHECKED
, 0);
196 if (This
->pProperties
->dwCharacter
& NCCF_NOTIFY_DISCONNECTED
)
198 /* check notify item */
199 SendDlgItemMessageW(hwndDlg
, IDC_NOTIFYNOCONNECTION
, BM_SETCHECK
, BST_CHECKED
, 0);
202 memset(&lc
, 0, sizeof(LV_COLUMN
));
203 lc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_FMT
;
204 lc
.fmt
= LVCFMT_FIXED_WIDTH
;
205 if (GetClientRect(hDlgCtrl
, &rc
))
207 lc
.mask
|= LVCF_WIDTH
;
208 lc
.cx
= rc
.right
- rc
.left
;
211 (void)SendMessageW(hDlgCtrl
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&lc
);
212 dwStyle
= (DWORD
) SendMessage(hDlgCtrl
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
213 dwStyle
= dwStyle
| LVS_EX_FULLROWSELECT
| LVS_EX_CHECKBOXES
;
214 SendMessage(hDlgCtrl
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, dwStyle
);
218 hr
= CoCreateInstance(&CLSID_CNetCfg
, NULL
, CLSCTX_INPROC_SERVER
, &IID_INetCfg
, (LPVOID
*)&pNCfg
);
222 hr
= INetCfgLock_QueryInterface(pNCfg
, &IID_INetCfgLock
, (LPVOID
*)&pNCfgLock
);
223 hr
= INetCfgLock_AcquireWriteLock(pNCfgLock
, 100, L
"", &pDisplayName
);
226 CoTaskMemFree(pDisplayName
);
230 This
->NCfgLock
= pNCfgLock
;
231 hr
= INetCfg_Initialize(pNCfg
, NULL
);
234 INetCfg_Release(pNCfg
);
238 EnumComponents(hDlgCtrl
, This
, pNCfg
, &GUID_DEVCLASS_NETCLIENT
, NET_TYPE_CLIENT
);
239 EnumComponents(hDlgCtrl
, This
, pNCfg
, &GUID_DEVCLASS_NETSERVICE
, NET_TYPE_SERVICE
);
240 EnumComponents(hDlgCtrl
, This
, pNCfg
, &GUID_DEVCLASS_NETTRANS
, NET_TYPE_PROTOCOL
);
243 ZeroMemory(&li
, sizeof(li
));
244 li
.mask
= LVIF_STATE
;
245 li
.stateMask
= (UINT
)-1;
246 li
.state
= LVIS_FOCUSED
|LVIS_SELECTED
;
247 (void)SendMessageW(hDlgCtrl
, LVM_SETITEMW
, 0, (LPARAM
)&li
);
251 ShowNetworkComponentProperties(
253 INetConnectionPropertyUiImpl
* This
)
259 INetCfgComponent
* pNCfgComp
;
262 hDlgCtrl
= GetDlgItem(hwndDlg
, IDC_COMPONENTSLIST
);
263 Count
= ListView_GetItemCount(hDlgCtrl
);
267 ZeroMemory(&lvItem
, sizeof(LVITEMW
));
268 lvItem
.mask
= LVIF_PARAM
| LVIF_STATE
;
269 lvItem
.stateMask
= (UINT
)-1;
270 for (Index
= 0; Index
< Count
; Index
++)
272 lvItem
.iItem
= Index
;
273 if (SendMessageW(hDlgCtrl
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
))
275 if (lvItem
.state
& LVIS_SELECTED
)
280 if (!(lvItem
.state
& LVIS_SELECTED
))
285 pItem
= (PNET_ITEM
)lvItem
.lParam
;
286 pNCfgComp
= (INetCfgComponent
*) pItem
->pNCfgComp
;
287 hr
= INetCfgComponent_RaisePropertyUi(pNCfgComp
, GetParent(hwndDlg
), NCRP_QUERY_PROPERTY_UI
, (IUnknown
*)This
);
290 hr
= INetCfgComponent_RaisePropertyUi(pNCfgComp
, GetParent(hwndDlg
), NCRP_SHOW_PROPERTY_UI
, (IUnknown
*)This
);
308 INetConnectionPropertyUiImpl
* This
;
319 page
= (PROPSHEETPAGE
*)lParam
;
320 This
= (INetConnectionPropertyUiImpl
*)page
->lParam
;
321 InitializeLANPropertiesUIDlg(hwndDlg
, This
);
322 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)This
);
325 lppl
= (LPNMLISTVIEW
) lParam
;
326 lppsn
= (LPPSHNOTIFY
) lParam
;
327 if (lppsn
->hdr
.code
== PSN_APPLY
)
329 This
= (INetConnectionPropertyUiImpl
*)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
332 hr
= INetCfg_Apply(This
->pNCfg
);
334 return PSNRET_INVALID
;
337 if (SendDlgItemMessageW(hwndDlg
, IDC_SHOWTASKBAR
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
343 if (StringFromCLSID(&This
->pProperties
->guidId
, &pStr
) == ERROR_SUCCESS
)
345 swprintf(szKey
, L
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", pStr
);
347 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szKey
, 0, KEY_WRITE
, &hKey
) == ERROR_SUCCESS
)
349 RegSetValueExW(hKey
, L
"ShowIcon", 0, REG_DWORD
, (LPBYTE
)&dwShowIcon
, sizeof(DWORD
));
354 return PSNRET_NOERROR
;
357 else if (lppsn
->hdr
.code
== PSN_CANCEL
)
359 This
= (INetConnectionPropertyUiImpl
*)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
362 hr
= INetCfg_Cancel(This
->pNCfg
);
364 return PSNRET_NOERROR
;
366 return PSNRET_INVALID
;
368 return PSNRET_NOERROR
;
371 if (lppl
->hdr
.code
== LVN_ITEMCHANGING
)
373 ZeroMemory(&li
, sizeof(li
));
374 li
.mask
= LVIF_PARAM
;
375 li
.iItem
= lppl
->iItem
;
376 if (!SendMessageW(lppl
->hdr
.hwndFrom
, LVM_GETITEMW
, 0, (LPARAM
)&li
))
379 pItem
= (PNET_ITEM
)li
.lParam
;
383 if (!(lppl
->uOldState
& LVIS_FOCUSED
) && (lppl
->uNewState
& LVIS_FOCUSED
))
385 /* new focused item */
386 if (pItem
->dwCharacteristics
& NCF_NOT_USER_REMOVABLE
)
387 EnableWindow(GetDlgItem(hwndDlg
, IDC_UNINSTALL
), FALSE
);
389 EnableWindow(GetDlgItem(hwndDlg
, IDC_UNINSTALL
), TRUE
);
391 if (pItem
->dwCharacteristics
& NCF_HAS_UI
)
392 EnableWindow(GetDlgItem(hwndDlg
, IDC_PROPERTIES
), TRUE
);
394 EnableWindow(GetDlgItem(hwndDlg
, IDC_PROPERTIES
), FALSE
);
396 SendDlgItemMessageW(hwndDlg
, IDC_DESCRIPTION
, WM_SETTEXT
, 0, (LPARAM
)pItem
->szHelp
);
401 if (LOWORD(wParam
) == IDC_PROPERTIES
)
403 This
= (INetConnectionPropertyUiImpl
*) GetWindowLongPtr(hwndDlg
, DWLP_USER
);
404 ShowNetworkComponentProperties(hwndDlg
, This
);
415 INetConnectionPropertyUi2_fnQueryInterface(
416 INetConnectionPropertyUi2
* iface
,
421 INetConnectionPropertyUiImpl
* This
= (INetConnectionPropertyUiImpl
*)iface
;
424 if (IsEqualIID (iid
, &IID_IUnknown
) ||
425 IsEqualIID (iid
, &IID_INetConnectionPropertyUi
) ||
426 IsEqualIID (iid
, &IID_INetConnectionPropertyUi2
))
429 IUnknown_AddRef(iface
);
432 else if (IsEqualIID(iid
, &IID_INetLanConnectionUiInfo
))
434 *ppvObj
= &This
->lpLanConUiInfoVtbl
;
435 IUnknown_AddRef(iface
);
438 else if (IsEqualIID(iid
, &IID_INetConnectionConnectUi
))
440 *ppvObj
= &This
->lpNetConnectionConnectUi
;
441 IUnknown_AddRef(iface
);
445 StringFromCLSID(iid
, &pStr
);
446 MessageBoxW(NULL
, pStr
, L
"INetConnectionPropertyUi_fnQueryInterface", MB_OK
);
448 return E_NOINTERFACE
;
454 INetConnectionPropertyUi2_fnAddRef(
455 INetConnectionPropertyUi2
* iface
)
457 INetConnectionPropertyUiImpl
* This
= (INetConnectionPropertyUiImpl
*)iface
;
458 ULONG refCount
= InterlockedIncrement(&This
->ref
);
466 INetConnectionPropertyUi2_fnRelease(
467 INetConnectionPropertyUi2
* iface
)
469 INetConnectionPropertyUiImpl
* This
= (INetConnectionPropertyUiImpl
*)iface
;
470 ULONG refCount
= InterlockedDecrement(&This
->ref
);
476 INetCfg_Uninitialize(This
->pNCfg
);
477 INetCfg_Release(This
->pNCfg
);
481 INetCfgLock_Release(This
->NCfgLock
);
483 if (This
->pProperties
)
485 NcFreeNetconProperties(This
->pProperties
);
487 CoTaskMemFree (This
);
495 INetConnectionPropertyUi2_fnSetConnection(
496 INetConnectionPropertyUi2
* iface
,
497 INetConnection
*pCon
)
499 INetConnectionPropertyUiImpl
* This
= (INetConnectionPropertyUiImpl
*)iface
;
505 INetConnection_Release(This
->pCon
);
508 INetConnection_AddRef(This
->pCon
);
515 INetConnectionPropertyUi2_fnAddPages(
516 INetConnectionPropertyUi2
* iface
,
518 LPFNADDPROPSHEETPAGE pfnAddPage
,
521 HPROPSHEETPAGE hProp
;
524 INITCOMMONCONTROLSEX initEx
;
525 INetConnectionPropertyUiImpl
* This
= (INetConnectionPropertyUiImpl
*)iface
;
528 initEx
.dwSize
= sizeof(initEx
);
529 initEx
.dwICC
= ICC_LISTVIEW_CLASSES
;
530 if(!InitCommonControlsEx(&initEx
))
533 hr
= INetConnection_GetProperties(This
->pCon
, &This
->pProperties
);
537 hProp
= InitializePropertySheetPage(MAKEINTRESOURCEW(IDD_NETPROPERTIES
), LANPropertiesUIDlg
, (LPARAM
)This
, This
->pProperties
->pszwName
);
540 ret
= (*pfnAddPage
)(hProp
, lParam
);
547 DestroyPropertySheetPage(hProp
);
556 INetConnectionPropertyUi2_fnGetIcon(
557 INetConnectionPropertyUi2
* iface
,
564 static const INetConnectionPropertyUi2Vtbl vt_NetConnectionPropertyUi
=
566 INetConnectionPropertyUi2_fnQueryInterface
,
567 INetConnectionPropertyUi2_fnAddRef
,
568 INetConnectionPropertyUi2_fnRelease
,
569 INetConnectionPropertyUi2_fnSetConnection
,
570 INetConnectionPropertyUi2_fnAddPages
,
571 INetConnectionPropertyUi2_fnGetIcon
,
577 INetLanConnectionUiInfo_fnQueryInterface(
578 INetLanConnectionUiInfo
* iface
,
582 INetConnectionPropertyUiImpl
* This
= impl_from_NetLanConnectionUiInfo(iface
);
583 return INetConnectionPropertyUi_QueryInterface((INetConnectionPropertyUi
*)This
, iid
, ppvObj
);
589 INetLanConnectionUiInfo_fnAddRef(
590 INetLanConnectionUiInfo
* iface
)
592 INetConnectionPropertyUiImpl
* This
= impl_from_NetLanConnectionUiInfo(iface
);
593 return INetConnectionPropertyUi_AddRef((INetConnectionPropertyUi
*)This
);
599 INetLanConnectionUiInfo_fnRelease(
600 INetLanConnectionUiInfo
* iface
)
602 INetConnectionPropertyUiImpl
* This
= impl_from_NetLanConnectionUiInfo(iface
);
603 return INetConnectionPropertyUi_Release((INetConnectionPropertyUi
*)This
);
609 INetLanConnectionUiInfo_fnGetDeviceGuid(
610 INetLanConnectionUiInfo
* iface
,
613 INetConnectionPropertyUiImpl
* This
= impl_from_NetLanConnectionUiInfo(iface
);
614 CopyMemory(pGuid
, &This
->pProperties
->guidId
, sizeof(GUID
));
618 static const INetLanConnectionUiInfoVtbl vt_NetLanConnectionUiInfo
=
620 INetLanConnectionUiInfo_fnQueryInterface
,
621 INetLanConnectionUiInfo_fnAddRef
,
622 INetLanConnectionUiInfo_fnRelease
,
623 INetLanConnectionUiInfo_fnGetDeviceGuid
,
629 INetConnectionConnectUi_fnQueryInterface(
630 INetConnectionConnectUi
* iface
,
634 INetConnectionPropertyUiImpl
* This
= impl_from_NetConnectionConnectUi(iface
);
635 return INetConnectionPropertyUi_QueryInterface((INetConnectionPropertyUi
*)This
, iid
, ppvObj
);
641 INetConnectionConnectUi_fnAddRef(
642 INetConnectionConnectUi
* iface
)
644 INetConnectionPropertyUiImpl
* This
= impl_from_NetConnectionConnectUi(iface
);
645 return INetConnectionPropertyUi_AddRef((INetConnectionPropertyUi
*)This
);
651 INetConnectionConnectUi_fnRelease(
652 INetConnectionConnectUi
* iface
)
654 INetConnectionPropertyUiImpl
* This
= impl_from_NetConnectionConnectUi(iface
);
655 return INetConnectionPropertyUi_Release((INetConnectionPropertyUi
*)This
);
661 INetConnectionConnectUi_fnSetConnection(
662 INetConnectionConnectUi
* iface
,
663 INetConnection
* pCon
)
665 INetConnectionPropertyUiImpl
* This
= impl_from_NetConnectionConnectUi(iface
);
667 INetConnection_Release(This
->pCon
);
673 INetConnection_AddRef(pCon
);
680 INetConnectionConnectUi_fnConnect(
681 INetConnectionConnectUi
* iface
,
685 INetConnectionPropertyUiImpl
* This
= impl_from_NetConnectionConnectUi(iface
);
688 return E_POINTER
; //FIXME
691 if (dwFlags
& NCUC_NO_UI
)
693 return INetConnection_Connect(This
->pCon
);
702 INetConnectionConnectUi_fnDisconnect(
703 INetConnectionConnectUi
* iface
,
708 swprintf(szBuffer
, L
"INetConnectionConnectUi_fnDisconnect flags %x\n", dwFlags
);
709 MessageBoxW(NULL
, szBuffer
, NULL
, MB_OK
);
715 static const INetConnectionConnectUiVtbl vt_NetConnectionConnectUi
=
717 INetConnectionConnectUi_fnQueryInterface
,
718 INetConnectionConnectUi_fnAddRef
,
719 INetConnectionConnectUi_fnRelease
,
720 INetConnectionConnectUi_fnSetConnection
,
721 INetConnectionConnectUi_fnConnect
,
722 INetConnectionConnectUi_fnDisconnect
,
728 HRESULT WINAPI
LanConnectUI_Constructor (IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
730 INetConnectionPropertyUiImpl
* This
;
736 return CLASS_E_NOAGGREGATION
;
738 This
= (INetConnectionPropertyUiImpl
*) CoTaskMemAlloc(sizeof (INetConnectionPropertyUiImpl
));
740 return E_OUTOFMEMORY
;
745 This
->NCfgLock
= NULL
;
746 This
->pProperties
= NULL
;
747 This
->lpVtbl
= (INetConnectionPropertyUi2
*)&vt_NetConnectionPropertyUi
;
748 This
->lpLanConUiInfoVtbl
= (INetLanConnectionUiInfo
*)&vt_NetLanConnectionUiInfo
;
749 This
->lpNetConnectionConnectUi
= (INetConnectionConnectUi
*)&vt_NetConnectionConnectUi
;
751 if (!SUCCEEDED (INetConnectionPropertyUi2_fnQueryInterface ((INetConnectionPropertyUi2
*)This
, riid
, ppv
)))
753 IUnknown_Release((IUnknown
*)This
);
754 return E_NOINTERFACE
;
757 IUnknown_Release((IUnknown
*)This
);