HRESULT WINAPI CNetConnectionPropertyUi::AddPages( HWND hwndParent, LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam) { HPROPSHEETPAGE hProp; BOOL ret; HRESULT hr = E_FAIL; INITCOMMONCONTROLSEX initEx; initEx.dwSize = sizeof(initEx); initEx.dwICC = ICC_LISTVIEW_CLASSES; if(!InitCommonControlsEx(&initEx)) return E_FAIL; hr = pCon->GetProperties(&pProperties); if (FAILED(hr)) return hr; hProp = InitializePropertySheetPage(MAKEINTRESOURCEW(IDD_NETPROPERTIES), LANPropertiesUIDlg, (LPARAM)this, pProperties->pszwName); if (hProp) { ret = (*pfnAddPage)(hProp, lParam); if (ret) { hr = NOERROR; } else { DestroyPropertySheetPage(hProp); } } return hr; }
HRESULT CLanStatus::InitializeNetTaskbarNotifications() { NOTIFYICONDATAW nid; HWND hwndDlg; INetConnectionManager *pNetConMan; IEnumNetConnection *pEnumCon; INetConnection *pNetCon; NETCON_PROPERTIES* pProps; HRESULT hr; ULONG Count; ULONG Index; NOTIFICATION_ITEM * pItem, *pLast = NULL; LANSTATUSUI_CONTEXT * pContext; TRACE("InitializeNetTaskbarNotifications\n"); if (m_pHead) { pItem = m_pHead; while (pItem) { hr = pItem->pNet->GetProperties(&pProps); if (SUCCEEDED(hr)) { ZeroMemory(&nid, sizeof(nid)); nid.cbSize = sizeof(nid); nid.uID = pItem->uID; nid.hWnd = pItem->hwndDlg; nid.uFlags = NIF_STATE; if (pProps->dwCharacter & NCCF_SHOW_ICON) nid.dwState = 0; else nid.dwState = NIS_HIDDEN; nid.dwStateMask = NIS_HIDDEN; Shell_NotifyIconW(NIM_MODIFY, &nid); NcFreeNetconProperties(pProps); } pItem = pItem->pNext; } return S_OK; } /* get an instance to of IConnectionManager */ //hr = CoCreateInstance(&CLSID_ConnectionManager, NULL, CLSCTX_INPROC_SERVER, &IID_INetConnectionManager, (LPVOID*)&pNetConMan); hr = INetConnectionManager_Constructor(NULL, IID_INetConnectionManager, (LPVOID*)&pNetConMan); if (FAILED(hr)) { ERR("INetConnectionManager_Constructor failed\n"); return hr; } hr = pNetConMan->EnumConnections(NCME_DEFAULT, &pEnumCon); if (FAILED(hr)) { ERR("EnumConnections failed\n"); pNetConMan->Release(); return hr; } Index = 1; do { hr = pEnumCon->Next(1, &pNetCon, &Count); if (hr == S_OK) { TRACE("new connection\n"); pItem = static_cast<NOTIFICATION_ITEM*>(CoTaskMemAlloc(sizeof(NOTIFICATION_ITEM))); if (!pItem) break; pContext = static_cast<LANSTATUSUI_CONTEXT*>(CoTaskMemAlloc(sizeof(LANSTATUSUI_CONTEXT))); if (!pContext) { CoTaskMemFree(pItem); break; } ZeroMemory(pContext, sizeof(LANSTATUSUI_CONTEXT)); pContext->uID = Index; pContext->pNet = pNetCon; pItem->uID = Index; pItem->pNext = NULL; pItem->pNet = pNetCon; hwndDlg = CreateDialogParamW(netshell_hInstance, MAKEINTRESOURCEW(IDD_STATUS), NULL, LANStatusDlg, (LPARAM)pContext); if (hwndDlg) { ZeroMemory(&nid, sizeof(nid)); nid.cbSize = sizeof(nid); nid.uID = Index++; nid.uFlags = NIF_MESSAGE; nid.uVersion = 3; nid.uCallbackMessage = WM_SHOWSTATUSDLG; nid.hWnd = hwndDlg; hr = pNetCon->GetProperties(&pProps); if (SUCCEEDED(hr)) { CopyMemory(&pItem->guidItem, &pProps->guidId, sizeof(GUID)); if (!(pProps->dwCharacter & NCCF_SHOW_ICON)) { nid.dwState = NIS_HIDDEN; nid.dwStateMask = NIS_HIDDEN; nid.uFlags |= NIF_STATE; } if (pProps->Status == NCS_MEDIA_DISCONNECTED || pProps->Status == NCS_DISCONNECTED || pProps->Status == NCS_HARDWARE_DISABLED) nid.hIcon = LoadIcon(netshell_hInstance, MAKEINTRESOURCE(IDI_NET_OFF)); else if (pProps->Status == NCS_CONNECTED) nid.hIcon = LoadIcon(netshell_hInstance, MAKEINTRESOURCE(IDI_NET_IDLE)); if (nid.hIcon) nid.uFlags |= NIF_ICON; wcscpy(nid.szTip, pProps->pszwName); nid.uFlags |= NIF_TIP; } pContext->hwndStatusDlg = hwndDlg; pItem->hwndDlg = hwndDlg; if (Shell_NotifyIconW(NIM_ADD, &nid)) { if (pLast) pLast->pNext = pItem; else m_pHead = pItem; pLast = pItem; Index++; } else { ERR("Shell_NotifyIconW failed\n"); CoTaskMemFree(pItem); } if (nid.uFlags & NIF_ICON) DestroyIcon(nid.hIcon); } else ERR("CreateDialogParamW failed\n"); } } while (hr == S_OK); m_lpNetMan = pNetConMan; pEnumCon->Release(); return S_OK; }