PPC中如何找到正在使用中的网络(转)

  《PPC中如何判断网络已经连接或者断开》中已经说明了如何判断PPC的网络是否连接和断开,本篇文章讲讲如何枚举出当前的网络状态,并找到正在使用中的网络。一个比较简单的应用就是当接到系统连接到网络的通知之后,需要判断是免费网络还是收费网络,之后再作相应处理。一般免费网络就是WIFI和ActiveSync,收费网络就是CMNET和CMWAP。下面的代码就来判断当前连接的网络究竟是什么网络,要做到这一点,需要使用一个函数ConnMgrQueryDetailedStatus,这个函数可以得到网络的详细信息,从他的dwType中可得到网络的类别,dwSubtype可以知道具体的网络类型。具体代码如下,写的已经是比较详细了,如有问题可以在17feixiang.com上留言。
    CONNMGR_CONNECTION_DETAILED_STATUS *StatusBuffer;
    CONNMGR_CONNECTION_DETAILED_STATUS *StatusBufferTemp;
    DWORD                              pcbBufferSize = 0;
    ConnMgrQueryDetailedStatus(NULL, &pcbBufferSize);
    StatusBuffer = (CONNMGR_CONNECTION_DETAILED_STATUS *)new BYTE[pcbBufferSize];
    ConnMgrQueryDetailedStatus(StatusBuffer, &pcbBufferSize);
    StatusBufferTemp = StatusBuffer;
    while(StatusBufferTemp != NULL)
    {
        if(StatusBufferTemp-〉dwConnectionStatus == CONNMGR_STATUS_CONNECTED)
        {
            if(StatusBufferTemp-〉dwType == CM_CONNTYPE_NIC)
            {
                switch(StatusBufferTemp-〉dwSubtype)
                {
                case CM_CONNSUBTYPE_NIC_WIFI :
                    MessageBox(_T("WIFI"));
                    break;
                case CM_CONNSUBTYPE_NIC_ETHERNET :
                    break;
                }
            }
            if(StatusBufferTemp-〉dwType == CM_CONNTYPE_CELLULAR)
            {
                switch(StatusBufferTemp-〉dwSubtype)
                {
                case CM_CONNSUBTYPE_CELLULAR_CSD :
                    break;
                case CM_CONNSUBTYPE_CELLULAR_GPRS :
                    MessageBox(_T("GPRS"));
                    break;
                case CM_CONNSUBTYPE_CELLULAR_1XRTT :
                    MessageBox(_T("1XRTT"));
                    break;
                case CM_CONNSUBTYPE_CELLULAR_1XEVDO :
                    MessageBox(_T("1XEVDO"));
                    break;
                case CM_CONNSUBTYPE_CELLULAR_1XEVDV :
                    break;
                case CM_CONNSUBTYPE_CELLULAR_EDGE :
                    MessageBox(_T("EDGE"));
                    break;
                case CM_CONNSUBTYPE_CELLULAR_UMTS :
                    break;
                case CM_CONNSUBTYPE_CELLULAR_VOICE :
                    MessageBox(_T("VOICE"));
                    break;
                case CM_CONNSUBTYPE_CELLULAR_PTT :
                    break;
                //case CM_CONNSUBTYPE_CELLULAR_HSDPA :
                //    break;
                }
            }
            if(StatusBufferTemp-〉dwType == CM_CONNTYPE_PROXY)
            {
                switch(StatusBufferTemp-〉dwSubtype)
                {
                case CM_CONNSUBTYPE_PROXY_WAP :
                    MessageBox(_T("WAP"));
                    break;
                case CM_CONNSUBTYPE_PROXY_HTTP :
                    MessageBox(_T("HTTP"));
                    break;
                }
            }
            if(StatusBufferTemp-〉dwType == CM_CONNTYPE_PC)
            {
                switch(StatusBufferTemp-〉dwSubtype)
                {
                case CM_CONNSUBTYPE_PC_DESKTOPPASSTHROUGH :
                    MessageBox(_T("ACTIVESYNC"));
                    break;
                case CM_CONNSUBTYPE_PC_UNKNOWN :
                    break;
                }
            }
        }
        StatusBufferTemp = StatusBufferTemp-〉pNext;
    }
    delete StatusBuffer;

posted @ 2010-01-30 09:37  木瓜脑袋  阅读(520)  评论(0编辑  收藏  举报