如何获取无线网络信号强度。
获取上网本WIFI的信号强度,知道的给点源码参考一下。。谢谢
[解决办法]
利用 RConnectionMonitor 类。
//connect RConnectionMonitor monitor; monitor.ConnectL(); CleanupClosePushL(monitor); TRequestStatus status; TInt iSignalStrength; //get all wifi packets TPckgBuf<TConnMonNetworkNames> pkgNetworks; monitor.GetPckgAttribute(EBearerIdWLAN, 0, KNetworkNames, pkgNetworks, status); User::WaitForRequest(status); TInt packetCount = pkgNetworks().Count(); //find ssid in packets TBuf16<36> ssid16; ssid16.Copy(pkgNetworks().iNetwork[0].iName); //get signal strength iSignalStrength = (TInt) pkgNetworks().iNetwork[0].iSignalStrength;
[解决办法]
关键时候, 还是我来吧!
M$已经提供了相应的wlanapi, 在2009/2010中直接使用就行了:
void __fastcall TForm1::Button1Click(TObject *Sender){ DWORD dwError = ERROR_SUCCESS; DWORD dwNegotiatedVersion; HANDLE hClientHandle = NULL; dwError = WlanOpenHandle(WLAN_API_VERSION_1_0, NULL, &dwNegotiatedVersion, &hClientHandle); if (dwError != ERROR_SUCCESS) return; PWLAN_INTERFACE_INFO_LIST pInterfaceList = NULL; dwError = WlanEnumInterfaces(hClientHandle, NULL,&pInterfaceList); if ( dwError != ERROR_SUCCESS ) { WlanFreeMemory(pInterfaceList); return; } GUID &guid = pInterfaceList->InterfaceInfo[0].InterfaceGuid; PWLAN_AVAILABLE_NETWORK_LIST pWLAN_AVAILABLE_NETWORK_LIST = NULL; dwError = WlanGetAvailableNetworkList(hClientHandle, &guid, WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES, NULL, &pWLAN_AVAILABLE_NETWORK_LIST); if (dwError != ERROR_SUCCESS) { WlanFreeMemory(pInterfaceList); WlanFreeMemory(pWLAN_AVAILABLE_NETWORK_LIST); return; } if (pWLAN_AVAILABLE_NETWORK_LIST->dwNumberOfItems > 0) { wchar_t sz[256] = { 0 }; WLAN_AVAILABLE_NETWORK wlanAN = pWLAN_AVAILABLE_NETWORK_LIST[0].Network[0]; wsprintfW(sz, L"%s:%d", wlanAN.strProfileName, wlanAN.wlanSignalQuality); Memo1->Lines->Add(sz); } WlanFreeMemory(pInterfaceList); WlanFreeMemory(pWLAN_AVAILABLE_NETWORK_LIST);}