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

📄 thorclient2dlg.cpp

📁 802.1x认证客户端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	UpdateData(TRUE);

	if((m_username=="") || (m_password==""))
	{
		MessageBox("请输入用户名和密码!", "连接警告", MB_ICONWARNING);
		return;
	}
	

	strcpy(UserData.username, m_username);
	strcpy(UserData.password, m_password);
	m_ipaddress.GetAddress(UserData.ip[0], UserData.ip[1],
						   UserData.ip[2], UserData.ip[3]);
	UserData.autologin = m_autologin;
	UserData.rempwd = m_rempwd;

	GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_NETCONFIG)->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_USERNAME)->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(FALSE);
	GetDlgItem(IDC_IPADDRESS)->EnableWindow(FALSE);
	GetDlgItem(IDC_NIC)->EnableWindow(FALSE);
	GetDlgItem(IDC_CHECK_SAVEPWD)->EnableWindow(FALSE);
	GetDlgItem(IDC_CHECK_AUTO)->EnableWindow(FALSE);

	Dot1X->Connect(&UserData);
}

void CThorClient2Dlg::OnButtonDisconnect() 
{
	// TODO: Add your control notification handler code here
	Dot1X->Disconnect();
}

void CThorClient2Dlg::OnButtonNetconfig() 
{
	// TODO: Add your control notification handler code here
	CNetCfg dlg;

	dlg.m_morb = UserData.morb;
	dlg.m_dhcp = UserData.dhcp;
	dlg.m_multisend = UserData.multisend;
	dlg.m_updateip = UserData.updateip;
	dlg.m_relogin = UserData.relogin;

	if(dlg.DoModal() == IDOK)
	{
		UserData.morb = dlg.m_morb;
		UserData.dhcp = dlg.m_dhcp;
		UserData.multisend = dlg.m_multisend;
		UserData.updateip = dlg.m_updateip;
		UserData.relogin = dlg.m_relogin;
	}
}

void CThorClient2Dlg::OnButtonHelp() 
{
	// TODO: Add your control notification handler code here
	ShellExecute(NULL, "open", "http://thorqq.ys168.com", NULL, NULL, SW_SHOWNORMAL); 
	CAboutDlg().DoModal();
}

void CThorClient2Dlg::OnButtonMini() 
{
	// TODO: Add your control notification handler code here
	ShowWindow(SW_MINIMIZE);
	ShowWindow(SW_HIDE);
}

void CThorClient2Dlg::OnCheckAuto() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	UserData.autologin = m_autologin;
}

void CThorClient2Dlg::OnCheckSavepwd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	UserData.rempwd = m_rempwd;
}

void CThorClient2Dlg::OnDropdownNic()
{
	// TODO: Add your control notification handler code here
	CMyComboBox* Device=(CMyComboBox*)GetDlgItem(IDC_NIC);
	
	arrNicItem.RemoveAll();//清空数组
	Device->ResetContent();//清空复合框

/////////////////////////////////////
	PGAINFO pGAInfo;
//加载IP Helper API 所需的库文件
    HINSTANCE hInst;//实例句柄
    hInst=LoadLibrary("iphlpapi.dll");
    if(!hInst)
        AfxMessageBox("iphlpapi.dll not supported in this platform!\n");
    pGAInfo=(PGAINFO)GetProcAddress(hInst,"GetAdaptersInfo");
////------------------------------------》获得网卡数据
    PIP_ADAPTER_INFO pInfo=NULL, pInfoTemp=NULL;
    ULONG ulSize=0;
    pGAInfo(pInfo,&ulSize);//第一次调用,获取缓冲区大小
    pInfoTemp=pInfo=(PIP_ADAPTER_INFO)new(char[ulSize]);
    if( pGAInfo(pInfo,&ulSize) != ERROR_SUCCESS)
		return;

	DWORD dwLocalIP = 0;
	for( ; pInfo; pInfo=pInfo->Next)
	{
		Device->AddString(pInfo->Description);
		
		NICITEM nic;
		nic.nItem = pInfo->Index;
		strcpy(nic.name, "\\Device\\NPF_");
		strcat(nic.name, pInfo->AdapterName);
		strcpy(nic.description, pInfo->Description);
		for(int j=0; j<6; j++)
			nic.mac[j] = pInfo->Address[j];
		dwLocalIP = ::inet_addr(pInfo->IpAddressList.IpAddress.String);
		memcpy(nic.ip,  (unsigned  char*)&dwLocalIP, 4);	//get IP

		arrNicItem.Add(nic);
	}
	delete pInfoTemp;
/////////////////////////////////////////
/*	PIP_ADAPTER_INFO pInfo = NULL;
	ULONG ulLen = 0;

	// 为适配器结构申请内存
	::GetAdaptersInfo(pInfo,&ulLen);
	pInfo = (PIP_ADAPTER_INFO)::GlobalAlloc(GPTR, ulLen);

	// 取得本地适配器结构信息
	if(::GetAdaptersInfo(pInfo,&ulLen) ==  ERROR_SUCCESS)
	{
		for( ; pInfo; pInfo=pInfo->Next)
		{
			Device->AddString(pInfo->Description);
			
			NICITEM nic;
			nic.nItem = pInfo->Index;
			strcpy(nic.name, "\\Device\\NPF_");
			strcat(nic.name, pInfo->AdapterName);
			strcpy(nic.description, pInfo->Description);
			memcpy(nic.mac, pInfo->Address, 6);

			arrNicItem.Add(nic);
		}
	}
	::GlobalFree(pInfo);	
*////////////////////////////////////////////////
	Device->SetCurSel(Device->SelectString(0, UserData.nicdes) );
	OnSelchangeNic();
	
	return;
}

void CThorClient2Dlg::OnSelchangeNic() 
{
	// TODO: Add your control notification handler code here
	CMyComboBox* Device=(CMyComboBox*)GetDlgItem(IDC_NIC);
	//获得序号
	int nSel  = Device->GetCurSel();
	if(nSel>-1)
	{
		//获得网卡名称和MAC
		strcpy(UserData.nic, arrNicItem.GetAt(nSel).name);
		strcpy(UserData.nicdes, arrNicItem.GetAt(nSel).description);
		for(int i=0; i<6; i++)
			UserData.mac[i] = arrNicItem.GetAt(nSel).mac[i];
		m_ipaddress.SetAddress(arrNicItem.GetAt(nSel).ip[0], 
								arrNicItem.GetAt(nSel).ip[1], 
								arrNicItem.GetAt(nSel).ip[2], 
								arrNicItem.GetAt(nSel).ip[3]);
//		UpdateData(false);
	}	
}

LRESULT CThorClient2Dlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class

	if(message == WM_DOT1X)
	{
		GetDlgItem(IDC_STATIC_STATUS)->SetWindowText((char*)lParam);

		switch((char)wParam)
		{
		case 1:		Online();
					break;
			
		case -1:	Offline();
					Dot1X->ClosAdapter();
					break;

		case -2:	OnButtonConnect();
					break;
		default:	;
		}
	}

	return CDialog::WindowProc(message, wParam, lParam);
}



void CThorClient2Dlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if(nType == SIZE_MINIMIZED)
		OnButtonMini();
}

void CThorClient2Dlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if(GetDlgItem(IDC_BUTTON_DISCONNECT)->IsWindowEnabled())
	{
		MessageBox("请断开连接后再退出本程序!", "退出警告", MB_ICONWARNING|MB_OK);
		return;
	}
	CDialog::OnClose();
}

void CThorClient2Dlg::OnMenuOpen() 
{
	// TODO: Add your command handler code here
	ShowWindow(SW_NORMAL);	
	SetForegroundWindow();
}

void CThorClient2Dlg::OnMenuConnect() 
{
	// TODO: Add your command handler code here
	OnButtonConnect();
}

void CThorClient2Dlg::OnMenuDisconnect() 
{
	// TODO: Add your command handler code here
	OnButtonDisconnect();
}

void CThorClient2Dlg::OnMenuNetconfig() 
{
	// TODO: Add your command handler code here
	OnButtonNetconfig();
}

void CThorClient2Dlg::OnMenuAbout() 
{
	// TODO: Add your command handler code here
	CAboutDlg().DoModal();
}

void CThorClient2Dlg::OnMenuitQuit() 
{
	// TODO: Add your command handler code here
	SendMessage(WM_CLOSE, 0, 0);
}

void CThorClient2Dlg::OnUpdateMenuConnect(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(GetDlgItem(IDC_BUTTON_CONNECT)->IsWindowEnabled());
}

void CThorClient2Dlg::OnUpdateMenuDisconnect(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(GetDlgItem(IDC_BUTTON_DISCONNECT)->IsWindowEnabled());
}

void CThorClient2Dlg::OnUpdateMenuNetconfig(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(GetDlgItem(IDC_BUTTON_CONNECT)->IsWindowEnabled());
}

void CThorClient2Dlg::Online()
{
	trayIcon.SetIcon(IDI_ICONON);
	GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(FALSE);
}

void CThorClient2Dlg::Offline()
{
	trayIcon.SetIcon(IDI_ICONOFF);

	GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_NETCONFIG)->EnableWindow(TRUE);
	GetDlgItem(IDC_EDIT_USERNAME)->EnableWindow(TRUE);
	GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(TRUE);
	GetDlgItem(IDC_IPADDRESS)->EnableWindow(TRUE);
	GetDlgItem(IDC_NIC)->EnableWindow(TRUE);
	GetDlgItem(IDC_CHECK_SAVEPWD)->EnableWindow(TRUE);
	GetDlgItem(IDC_CHECK_AUTO)->EnableWindow(TRUE);

	if(UserData.dhcp == 1)
		RenewIp();
}


void CThorClient2Dlg::RenewIp()
{
	PGIINFO pGIInfo;
	PIRELEASEADDRESS pIReleaseAddress;
	PIRENEWADDRESS pIRenewAddress;
	//加载IP Helper API 所需的库文件
    HINSTANCE hInst;//实例句柄
    hInst=LoadLibrary("iphlpapi.dll");
    if(!hInst)
        AfxMessageBox("iphlpapi.dll not supported in this platform!\n");
	pGIInfo          = (PGIINFO)         GetProcAddress(hInst,"GetInterfaceInfo");
    pIReleaseAddress = (PIRELEASEADDRESS)GetProcAddress(hInst,"IpReleaseAddress");
    pIRenewAddress   = (PIRENEWADDRESS)  GetProcAddress(hInst,"IpRenewAddress");

	CMyComboBox* Device=(CMyComboBox*)GetDlgItem(IDC_NIC);
	//获得序号
	int nSel  = Device->GetCurSel();

	PIP_INTERFACE_INFO pInfo = 
			(PIP_INTERFACE_INFO)::GlobalAlloc(GPTR, sizeof(IP_INTERFACE_INFO));
	ULONG ulOutBufLen = sizeof(IP_INTERFACE_INFO);

	// 如果上面申请的内存不够的话,再重新申请
	if(pGIInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
	{
		::GlobalFree(pInfo);
		pInfo = (PIP_INTERFACE_INFO)::GlobalAlloc(GPTR, ulOutBufLen);
	}

	// 再次调用GetInterfaceInfo来获取我们实际需要的数据
	if(pGIInfo(pInfo, &ulOutBufLen) == NO_ERROR)
	{
		pIReleaseAddress(&pInfo->Adapter[nSel]);
		pIRenewAddress(&pInfo->Adapter[nSel]);
	}
	else
	{
		AfxMessageBox(" GetInterfaceInfo() failed!");
	}

	::GlobalFree(pInfo);
}

⌨️ 快捷键说明

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