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

📄 winipcfgdlg.cpp

📁 Windows NT 4.0 had WIPCfg32.exe, and Windows 95/98/ME had WinIPCfg.exe. For some reason, this utilit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			}
			MessageBox(sError);
			return;
		}
		break;
	}

		// Get a usable pointer
	IP_ADAPTER_INFO *pIPAI = (IP_ADAPTER_INFO *)m_byteAdapterBuf;

	// Reset the combobox
	m_cbNetCard.ResetContent();

	// pIPAI is a pointer to a linked list of IP_ADAPTER_INFO structures.
	// The last valid one has it's "Next" member set to NULL.
	// Just walk the chain...
	// fix: mpauley 11/2005
	while ( pIPAI != NULL )
	{
		CString sName = pIPAI->Description;
		int nAdd = m_cbNetCard.AddString(sName);
		m_cbNetCard.SetItemData(nAdd, (DWORD_PTR)pIPAI);

		pIPAI = pIPAI->Next;
	}


	/*
	// Add each entry to the combobox
	int nCount = (int)(ulSize/sizeof(IP_ADAPTER_INFO));
	for(int i = 0; i < nCount; ++i)
	{
		CString sName = pIPAI[i].Description;
		m_cbNetCard.AddString(sName);
		m_cbNetCard.SetItemData(i, (DWORD_PTR)&pIPAI[i]);
	}
	*/
	
}

void CWinIPCfgDlg::CleanupNICs(void)
{
	int nCount = m_cbNetCard.GetCount();
	for(int i = 0; i < nCount; ++i)
	{
		 // Deleted below when main buffer is zapped
		//IP_ADAPTER_INFO *pIPAI = (IP_ADAPTER_INFO *)m_cbNetCard.GetItemData(i);
		//if( pIPAI )
		//	delete pIPAI;
		 // Set NULL so Windows doesn't do anything funky
		m_cbNetCard.SetItemData(i, NULL);
	}

	 // Clean up the NIC card data buffer
	if( m_byteAdapterBuf != NULL )
	{
		delete [] m_byteAdapterBuf;
		m_byteAdapterBuf = NULL;
	}
}

void CWinIPCfgDlg::OnCbnSelchangeComboNetcard()
{
	// Get the current combobox index
	int iSel = (int)m_cbNetCard.GetCurSel();
	if( iSel < 0 ) return;

	 // Get the data pointer
	IP_ADAPTER_INFO *pIPAI = (IP_ADAPTER_INFO *)m_cbNetCard.GetItemData(iSel);

	CString sTmp, sTmp2;
	UINT i;

	 // Build the NIC address
	sTmp = _T("");
	for(i = 0; i < pIPAI->AddressLength; ++i)
	{
		sTmp2.Format(_T("%02X"), pIPAI->Address[i]);
		sTmp += sTmp2;
		if( i < pIPAI->AddressLength-1)
			sTmp += _T("-");
	}
	m_textAdapterAddress.SetWindowText(sTmp);
	 // Show the IP address
	sTmp = pIPAI->IpAddressList.IpAddress.String;
	m_textIPAddress.SetWindowText(sTmp);
	 // Show the IP Mask
	sTmp = pIPAI->IpAddressList.IpMask.String;
	m_textSubnetMask.SetWindowText(sTmp);
	 // Show the IP Gateway
	sTmp = pIPAI->GatewayList.IpAddress.String;
	m_textGateway.SetWindowText(sTmp);

	 // Get the type of connection
	switch(pIPAI->Type)
	{
	case MIB_IF_TYPE_ETHERNET:  sTmp.LoadString(IDS_MIB_IF_TYPE_ETHERNET); break;
	case MIB_IF_TYPE_TOKENRING: sTmp.LoadString(IDS_MIB_IF_TYPE_TOKENRING); break;
	case MIB_IF_TYPE_FDDI:      sTmp.LoadString(MIB_IF_TYPE_FDDI); break;
	case MIB_IF_TYPE_PPP:       sTmp.LoadString(MIB_IF_TYPE_PPP); break;
	case MIB_IF_TYPE_LOOPBACK:  sTmp.LoadString(MIB_IF_TYPE_LOOPBACK); break;
	case MIB_IF_TYPE_SLIP:      sTmp.LoadString(MIB_IF_TYPE_SLIP); break;
	case MIB_IF_TYPE_OTHER:      
	default:
		sTmp.LoadString(IDS_MIB_IF_TYPE_OTHER); break;
	}
	m_textType.SetWindowText(sTmp);

	 // Show the DHCP address
	if( pIPAI->DhcpEnabled )
	{
		sTmp = pIPAI->DhcpServer.IpAddress.String;
		m_textDHCPServer.SetWindowText(sTmp);
	}
	else
		m_textDHCPServer.SetWindowText(_T(""));

	 // Show the WINS
	if( pIPAI->DhcpEnabled )
	{
		sTmp = pIPAI->PrimaryWinsServer.IpAddress.String;
		m_textWINSPrimary.SetWindowText(sTmp);
		sTmp = pIPAI->SecondaryWinsServer.IpAddress.String;
		m_textWINSSecondary.SetWindowText(sTmp);
	}
	else
	{
		m_textWINSPrimary.SetWindowText(_T(""));
		m_textWINSSecondary.SetWindowText(_T(""));
	}

	 // Show the DHCP Lease
	if( pIPAI->DhcpEnabled )
	{
		sTmp = ctime(&pIPAI->LeaseObtained);
		sTmp.TrimRight();
		m_textLeaseObtained.SetWindowText(sTmp);
		sTmp = ctime(&pIPAI->LeaseExpires);
		sTmp.TrimRight();
		m_textLeaseExpires.SetWindowText(_T(""));
	}
	else
	{
		m_textLeaseObtained.SetWindowText(_T(""));
		m_textLeaseExpires.SetWindowText(_T(""));
	}

	 // Enable the proper buttons
	GetDlgItem(ID_RELEASE)->EnableWindow(pIPAI->DhcpEnabled);
	GetDlgItem(ID_RELEASEALL)->EnableWindow(pIPAI->DhcpEnabled);
	GetDlgItem(ID_RENEW)->EnableWindow(pIPAI->DhcpEnabled);
	GetDlgItem(ID_RENEWALL)->EnableWindow(pIPAI->DhcpEnabled);
}

void CWinIPCfgDlg::OnBnClickedButtonDNSServers()
{
	 // Next DNS server in the list
	++m_nDNSPtr;
	if( m_nDNSPtr >= m_slDNS.GetCount() )
		m_nDNSPtr = 0;

	 // Find entry index
	int nCount = 0;
	POSITION Pos = m_slDNS.GetHeadPosition();
	while(Pos)
	{
		CString sPos = m_slDNS.GetNext(Pos);
		 // Is this it?
		if( nCount == m_nDNSPtr )
		{
			 // Yup, so fill it in
			m_textDNSServer.SetWindowText(sPos);
			break;
		}
		++nCount;
	}
}

 // Release Button
 //
 // Release the DHCP license for the current adapter
 //
void CWinIPCfgDlg::OnBnClickedRelease()
{
	 // Which adapter
	int iSel = (int)m_cbNetCard.GetCurSel();
	if( iSel < 0 ) 
		return;

	 // Get the pointer
	IP_ADAPTER_INFO *pIPAI = (IP_ADAPTER_INFO *)m_cbNetCard.GetItemData(iSel);

	 // DHCP?
	if( pIPAI->DhcpEnabled )
	{
		 // Get the INDEX_MAP entry
		IP_ADAPTER_INDEX_MAP IPmap;
		IPmap.Index = pIPAI->Index;
		mbstowcs(IPmap.Name, pIPAI->AdapterName, sizeof(IPmap.Name)/sizeof(WCHAR));

		 // Release the address
		IpReleaseAddress(&IPmap);

		 // Update the screen
		{
			// Get the current name
			CString sName = pIPAI[iSel].Description;
			// Refill with new data
			GetNICs();
			// Go back to current item
			iSel = m_cbNetCard.FindString(-1, sName);
			m_cbNetCard.SetCurSel(iSel);
			// Redraw
			OnCbnSelchangeComboNetcard();
		}
	}
}

void CWinIPCfgDlg::OnBnClickedReleaseall()
{
	 // Get the currently selected NIC
	int iSel = (int)m_cbNetCard.GetCurSel();
	if( iSel < 0 ) 
		return;

	 // How many NICs?
	int nCount = (int)m_cbNetCard.GetCount();
	CString sSel;

	for(int i = 0; i < nCount; ++i)
	{
		 // Get the pointer
		IP_ADAPTER_INFO *pIPAI = (IP_ADAPTER_INFO *)m_cbNetCard.GetItemData(i);

		 // DHCP on the card?
		if( pIPAI->DhcpEnabled )
		{
			 // Get the pointer
			IP_ADAPTER_INDEX_MAP IPmap;
			IPmap.Index = pIPAI->Index;
			mbstowcs(IPmap.Name, pIPAI->AdapterName, sizeof(IPmap.Name)/sizeof(WCHAR));

			 // Release it?
			IpReleaseAddress(&IPmap);

			 // Is it the current card?
			if( i == iSel )
				 // Get the current name
				sSel = pIPAI[iSel].Description;
		}
	}
	// Refill with new data
	GetNICs();
	if( !sSel.IsEmpty() )
	{
		// Go back to current item
		iSel = m_cbNetCard.FindString(-1, sSel);
		m_cbNetCard.SetCurSel(iSel);
	}
	// Redraw
	OnCbnSelchangeComboNetcard();
}

void CWinIPCfgDlg::OnBnClickedRenew()
{
	 // Get the currently selected NIC
	int iSel = (int)m_cbNetCard.GetCurSel();
	if( iSel < 0 ) 
		return;

	 // Get the pointer
	IP_ADAPTER_INFO *pIPAI = (IP_ADAPTER_INFO *)m_cbNetCard.GetItemData(iSel);

	 // DHCP?
	if( pIPAI->DhcpEnabled )
	{
		 // Get the INDEX_MAP
		IP_ADAPTER_INDEX_MAP IPmap;
		IPmap.Index = pIPAI->Index;
		mbstowcs(IPmap.Name, pIPAI->AdapterName, sizeof(IPmap.Name)/sizeof(WCHAR));

		 // Renew the license
		IpRenewAddress(&IPmap);

		 // Update the NIC info
		{
			// Get the current name
			CString sName = pIPAI[iSel].Description;
			// Refill with new data
			GetNICs();
			// Go back to current item
			iSel = m_cbNetCard.FindString(-1, sName);
			m_cbNetCard.SetCurSel(iSel);
			// Redraw
			OnCbnSelchangeComboNetcard();
		}
	}
}

void CWinIPCfgDlg::OnBnClickedRenewall()
{
	 // Get the currently selected NIC
	int iSel = (int)m_cbNetCard.GetCurSel();
	if( iSel < 0 ) 
		return;

	 // How many NICs?
	int nCount = (int)m_cbNetCard.GetCount();
	CString sSel;

	for(int i = 0; i < nCount; ++i)
	{
		 // Get the pointer
		IP_ADAPTER_INFO *pIPAI = (IP_ADAPTER_INFO *)m_cbNetCard.GetItemData(i);

		 // DHCP?
		if( pIPAI->DhcpEnabled )
		{
			IP_ADAPTER_INDEX_MAP IPmap;
			IPmap.Index = pIPAI->Index;
			mbstowcs(IPmap.Name, pIPAI->AdapterName, sizeof(IPmap.Name)/sizeof(WCHAR));

			IpRenewAddress(&IPmap);

			if( i == iSel )
				 // Get the current name
				sSel = pIPAI[iSel].Description;
		}
	}
	// Refill with new data
	GetNICs();
	if( !sSel.IsEmpty() )
	{
		// Go back to current item
		iSel = m_cbNetCard.FindString(-1, sSel);
		m_cbNetCard.SetCurSel(iSel);
	}
	// Redraw
	OnCbnSelchangeComboNetcard();
}

⌨️ 快捷键说明

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