void OnBnClickedButtonStatus() { int power_status; CString str; SYSTEM_POWER_STATUS_EX stat; GetSystemPowerStatusEx(&stat, TRUE); //if (stat.BatteryLifePercent > 100) //return ; //else power_status = stat.BatteryLifePercent; str.Format(L"%d",power_status); //wsprintf(str,L"%d",power_status); m_edit1.SetWindowTextW(str); } void OnBnClickedButtonWifi() { HANDLE hNdis = ::CreateFile( NDISUIO_DEVICE_NAME, GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, (HANDLE)INVALID_HANDLE_VALUE ); //DEVICE NAME UCHAR cbQueryBuffer[ 1024 ]; PNDISUIO_QUERY_BINDING pQueryBinding; DWORD dwBytesReturned = 0; TCHAR* pDeviceName; pQueryBinding = (PNDISUIO_QUERY_BINDING)&cbQueryBuffer[ 0 ]; pQueryBinding->BindingIndex = 0; if ( ::DeviceIoControl( hNdis, IOCTL_NDISUIO_QUERY_BINDING, (LPVOID)&cbQueryBuffer[ 0 ], sizeof(NDISUIO_QUERY_BINDING), (LPVOID)&cbQueryBuffer[ 0 ], sizeof(cbQueryBuffer), &dwBytesReturned, NULL ) == TRUE ) { pDeviceName = (TCHAR*)( cbQueryBuffer + pQueryBinding->DeviceNameOffset ); } #if 0 //CONNECT STATUS NIC_STATISTICS nicStatistics = { 0 }; BOOL bConnected = FALSE; nicStatistics.ptcDeviceName = pDeviceName; if ( ::DeviceIoControl( hNdis, IOCTL_NDISUIO_NIC_STATISTICS, NULL, 0, &nicStatistics, sizeof(NIC_STATISTICS), &dwBytesReturned, NULL ) == TRUE ) { if( nicStatistics.MediaState == MEDIA_STATE_CONNECTED ) m_edit1.SetWindowTextW(L"Connected"); else m_edit1.SetWindowTextW(L"not connect"); } #endif NDISUIO_QUERY_OID ndisQueryOid = { 0 }; int nDb = 0; ndisQueryOid.Oid = OID_802_11_RSSI; ndisQueryOid.ptcDeviceName = pDeviceName; if ( ::DeviceIoControl( hNdis, IOCTL_NDISUIO_QUERY_OID_VALUE, (LPVOID)&ndisQueryOid, sizeof(ndisQueryOid), (LPVOID)&ndisQueryOid, sizeof(ndisQueryOid), &dwBytesReturned, NULL ) == TRUE ) { ::CopyMemory( &nDb, &ndisQueryOid.Data[ 0 ], sizeof(ULONG) ); } CString str; str.Format(L"%d",ndisQueryOid.Data[ 0 ]); m_edit1.SetWindowTextW(str); CloseHandle(hNdis); } |