取得 wince 剩余电量和wifi信号强度

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:29   2556   0

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);

}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP