⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wifidemodlg.cpp

📁 Wince下通过ndisuio使用wifi卡的示例
💻 CPP
字号:
// WifiDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WifiDemo.h"
#include "WifiDemoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CWifiDemoDlg dialog

CWifiDemoDlg::CWifiDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWifiDemoDlg::IDD, pParent), m_nCounter(0)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWifiDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CWifiDemoDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
	ON_WM_SIZE()
#endif
	//}}AFX_MSG_MAP
    ON_WM_TIMER()
END_MESSAGE_MAP()


// CWifiDemoDlg message handlers

BOOL CWifiDemoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
    CListCtrl* pList = (CListCtrl*)this->GetDlgItem(IDC_LIST_APS);
    pList->InsertColumn(0, _T("SSID"), 0, 100);
    pList->InsertColumn(1, _T("Signal"), 0, 100);

    if (!this->m_wlanUtil.Init())
        MessageBox(this->m_wlanUtil.GetLastErrorMsg());
    SetTimer(1, 5000, NULL);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CWifiDemoDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
	if (AfxIsDRAEnabled())
	{
		DRA::RelayoutDialog(
			AfxGetResourceHandle(), 
			this->m_hWnd, 
			DRA::GetDisplayMode() != DRA::Portrait ? 
			MAKEINTRESOURCE(IDD_WIFIDEMO_DIALOG_WIDE) : 
			MAKEINTRESOURCE(IDD_WIFIDEMO_DIALOG));
	}
}
#endif


void CWifiDemoDlg::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: Add your message handler code here and/or call default
    this->m_nCounter++;
    INT     nSignal = -100;
    if (this->m_wlanUtil.IsInit())
    {
        ///< refresh SSID
        BYTE    szSsid[51] = "";
        memset(szSsid, 0, 51);
        if (this->m_wlanUtil.GetSsid(this->m_wlanUtil.GetFirstDeviceName(), szSsid, 50))
        {
            this->SetDlgItemTextW(IDC_EDIT_SSID, this->m_wlanUtil.SsidToString(szSsid).c_str());
        }
        else
        {
            this->SetDlgItemTextW(IDC_EDIT_INFO, this->m_wlanUtil.GetLastErrorMsg());
        }

        ///< refresh signal strength
        if (this->m_wlanUtil.GetSignalStrength(this->m_wlanUtil.GetFirstDeviceName(), &nSignal))
        {
            std::wstring    strTmp = this->m_wlanUtil.SignalStrengthToString(nSignal);
            TCHAR           szTmp[20] = _T("");
            _stprintf(szTmp, _T("(%d)"), nSignal);
            strTmp.append(szTmp);
            this->SetDlgItemTextW(IDC_EDIT_SIGNAL, strTmp.c_str());
        }
        else
        {
            this->SetDlgItemTextW(IDC_EDIT_INFO, this->m_wlanUtil.GetLastErrorMsg());
        }
    }
    if (m_nCounter == 3)
    {
        ///< scan for available APs
        if (!this->m_wlanUtil.ScanForBSSIDList(this->m_wlanUtil.GetFirstDeviceName()))
        {
            this->SetDlgItemTextW(IDC_EDIT_INFO, this->m_wlanUtil.GetLastErrorMsg());
        }
    }
    else if (m_nCounter > 4)
    {
        ///< refresh available APs
        wifi::CAvailableAPList  aps;
        if (this->m_wlanUtil.GetBSSIDList(this->m_wlanUtil.GetFirstDeviceName(), &aps))
        {
            CListCtrl* pList = (CListCtrl*)this->GetDlgItem(IDC_LIST_APS);
            pList->DeleteAllItems();

            for (size_t i = 0; i < aps.m_vectBssid.size(); i++)
            {
                pList->InsertItem(i, this->m_wlanUtil.SsidToString(aps.m_vectBssid[i].Ssid.Ssid, aps.m_vectBssid[i].Ssid.SsidLength).c_str());
                TCHAR   szTmp[20] = _T("");
                _stprintf(szTmp, _T("%d"), aps.m_vectBssid[i].Rssi);
                pList->SetItemText(i, 1, this->m_wlanUtil.SignalStrengthToString(aps.m_vectBssid[i].Rssi).append(szTmp).c_str());
            }
        }
        else
        {
            this->SetDlgItemTextW(IDC_EDIT_INFO, this->m_wlanUtil.GetLastErrorMsg());
        }
        TCHAR   szTmp[30] = _T("");
        _stprintf(szTmp, _T("List:%d - Vect:%d"), aps.m_bssidList.NumberOfItems, aps.m_vectBssid.size());
        SetDlgItemText(IDC_EDIT_INFO, szTmp);
        m_nCounter = 0;
    }

    CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -