// TODO: Add extra initialization here GetInfo(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }void CNetcardDlg::OnNextButton() { // TODO: Add your control notification handler code here ParseData(); }
#if !defined(AFX_NETCARDDLG_H__4EDE3D48_62BF_449F_BD3C_848D6D68C882__INCLUDED_)
#define AFX_NETCARDDLG_H__4EDE3D48_62BF_449F_BD3C_848D6D68C882__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// NetcardDlg.h : header file
///////////////////////////////////////////////////////////////////////////////
// CNetcardDlg dialogclass CNetcardDlg : public CDialog
{
// Construction
public:
void ParseData();
void GetInfo();
CNetcardDlg(CWnd* pParent = NULL); // standard constructor
CString m_type;
CString m_subnet;
CString m_PrimaryWinsServer;
CString m_dhcp;
// Dialog Data
//{{AFX_DATA(CNetcardDlg)
enum { IDD = IDD_NETCARD_DIALOG };
CButton m_buttonnext;
CString m_macaddress;
CString m_description;
CString m_IpAddress;
CString m_gateway;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CNetcardDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CNetcardDlg)
virtual BOOL OnInitDialog();
afx_msg void OnNextButton();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_NETCARDDLG_H__4EDE3D48_62BF_449F_BD3C_848D6D68C882__INCLUDED_)
// NetcardDlg.cpp : implementation file
//#include "stdafx.h"
#include "netmonitor.h"
#include "NetcardDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif//////////////////////////////////
PIP_ADAPTER_INFO pinfo=NULL;
unsigned long len=0;/////////////////////////////////////////////////////////////////////////////
// CNetcardDlg dialog
CNetcardDlg::CNetcardDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNetcardDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNetcardDlg)
m_description = _T("");
m_gateway = _T("");
m_IpAddress = _T("");
m_macaddress = _T("");
//}}AFX_DATA_INIT
}
void CNetcardDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNetcardDlg)
DDX_Control(pDX, IDC_NEXT_BUTTON, m_buttonnext);
DDX_Text(pDX, IDC_EDITMacAddress, m_macaddress);
DDX_Text(pDX, IDC_EDITDescription, m_description);
DDX_Text(pDX, IDC_EDITIPAddress, m_IpAddress);
DDX_Text(pDX, IDC_EDITGateway, m_gateway);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNetcardDlg, CDialog)
//{{AFX_MSG_MAP(CNetcardDlg)
ON_BN_CLICKED(IDC_NEXT_BUTTON, OnNextButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CNetcardDlg message handlersvoid CNetcardDlg::GetInfo()
{
if (pinfo!=NULL)
delete (pinfo);
unsigned long nError;
nError = GetAdaptersInfo(pinfo,&len);
if (nError==0)
{
ParseData();
}
if (nError==ERROR_NO_DATA)
{
AfxMessageBox("No adapter information exists for the local computer");
}
if (nError==ERROR_NOT_SUPPORTED)
{
AfxMessageBox("GetAdaptersInfo is not supported by the operating system running on the local computer");
}
if (nError==ERROR_BUFFER_OVERFLOW)
{
pinfo= (PIP_ADAPTER_INFO)malloc(len);
nError = GetAdaptersInfo(pinfo,&len);
if (nError==0)
{
ParseData();
}
}
return;
}void CNetcardDlg::ParseData()
{ if (pinfo!=NULL)
{
m_macaddress.Format("%02X:%02X:%02X:%02X:%02X:%02X",pinfo->Address[0],pinfo->Address[1],pinfo->Address[2],pinfo->Address[3],pinfo->Address[4],pinfo->Address[5]);
m_description = pinfo->Description;
m_type.Format("%d",pinfo->Type);
PIP_ADDR_STRING pAddressList = &(pinfo->IpAddressList);
m_IpAddress ="";
do
{
m_IpAddress += pAddressList->IpAddress.String;
pAddressList = pAddressList->Next;
if (pAddressList != NULL)
m_IpAddress +="\r\n";
} while (pAddressList != NULL); m_subnet.Format("%s",pinfo->IpAddressList.IpMask.String);
m_gateway.Format("%s",pinfo->GatewayList.IpAddress.String);
if (pinfo->HaveWins)
m_PrimaryWinsServer.Format("%s",pinfo->PrimaryWinsServer.IpAddress.String );
else
m_PrimaryWinsServer.Format("%s","N/A" );
if (pinfo->DhcpEnabled )
m_dhcp.Format("%s",pinfo->DhcpServer.IpAddress.String );
else
m_dhcp.Format("%s","N/A");
pinfo = pinfo->Next;
}
else
{
//m_buttonnext.EnableWindow(FALSE);
GetInfo();
m_buttonnext.EnableWindow();
}
UpdateData(FALSE);
}BOOL CNetcardDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
GetInfo();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}void CNetcardDlg::OnNextButton()
{
// TODO: Add your control notification handler code here
ParseData();
}