|
Posted on 2010-05-17 16:43 S.l.e!ep.¢% 阅读(414) 评论(0) 编辑 收藏 引用 所属分类: VC
-
-
-
-
#include "stdafx.h"
-
#include "DNS_Browser.h"
-
#include "DNS_BrowserDlg.h"
-
#include ".\dns_browserdlg.h"
-
-
#ifdef _DEBUG
-
#define new DEBUG_NEW
-
#endif
-
-
-
-
-
class
CAboutDlg :
public
CDialog
-
{
-
public
:
-
CAboutDlg();
-
-
enum
{ IDD = IDD_ABOUTBOX };
-
-
protected
:
-
virtual
void
DoDataExchange(CDataExchange* pDX);
-
-
-
protected
:
-
DECLARE_MESSAGE_MAP()
-
};
-
-
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
-
{
-
}
-
-
void
CAboutDlg::DoDataExchange(CDataExchange* pDX)
-
{
-
CDialog::DoDataExchange(pDX);
-
}
-
-
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
-
END_MESSAGE_MAP()
-
-
-
-
-
-
-
CDNS_BrowserDlg::CDNS_BrowserDlg(CWnd* pParent
)
-
: CDialog(CDNS_BrowserDlg::IDD, pParent)
-
{
-
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
-
}
-
-
void
CDNS_BrowserDlg::DoDataExchange(CDataExchange* pDX)
-
{
-
CDialog::DoDataExchange(pDX);
-
DDX_Control(pDX, IDC_LIST1, m_listDNS);
-
}
-
-
BEGIN_MESSAGE_MAP(CDNS_BrowserDlg, CDialog)
-
ON_WM_SYSCOMMAND()
-
ON_WM_PAINT()
-
ON_WM_QUERYDRAGICON()
-
-
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
-
END_MESSAGE_MAP()
-
-
-
-
-
BOOL
CDNS_BrowserDlg::OnInitDialog()
-
{
-
CDialog::OnInitDialog();
-
-
-
-
-
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
-
ASSERT(IDM_ABOUTBOX < 0xF000);
-
-
CMenu* pSysMenu = GetSystemMenu(FALSE);
-
if
(pSysMenu != NULL)
-
{
-
CString strAboutMenu;
-
strAboutMenu.LoadString(IDS_ABOUTBOX);
-
if
(!strAboutMenu.IsEmpty())
-
{
-
pSysMenu->AppendMenu(MF_SEPARATOR);
-
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
-
}
-
}
-
-
-
-
SetIcon(m_hIcon, TRUE);
-
SetIcon(m_hIcon, FALSE);
-
-
-
-
return
TRUE;
-
}
-
-
void
CDNS_BrowserDlg::OnSysCommand(
UINT
nID,
LPARAM
lParam)
-
{
-
if
((nID & 0xFFF0) == IDM_ABOUTBOX)
-
{
-
CAboutDlg dlgAbout;
-
dlgAbout.DoModal();
-
}
-
else
-
{
-
CDialog::OnSysCommand(nID, lParam);
-
}
-
}
-
-
-
-
-
-
void
CDNS_BrowserDlg::OnPaint()
-
{
-
if
(IsIconic())
-
{
-
CPaintDC dc(
this
);
-
-
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast
<
WPARAM
>(dc.GetSafeHdc()), 0);
-
-
-
int
cxIcon = GetSystemMetrics(SM_CXICON);
-
int
cyIcon = GetSystemMetrics(SM_CYICON);
-
CRect rect;
-
GetClientRect(&rect);
-
int
x = (rect.Width() - cxIcon + 1) / 2;
-
int
y = (rect.Height() - cyIcon + 1) / 2;
-
-
-
dc.DrawIcon(x, y, m_hIcon);
-
}
-
else
-
{
-
CDialog::OnPaint();
-
}
-
}
-
-
-
HCURSOR
CDNS_BrowserDlg::OnQueryDragIcon()
-
{
-
return
static_cast
<
HCURSOR
>(m_hIcon);
-
}
-
-
void
CDNS_BrowserDlg::OnBnClickedButton1()
-
{
-
-
LONG
lRtn;
-
HKEY
hMainKey;
-
TCHAR
szParameters[256];
-
-
_tcscpy(szParameters,_T(
"SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters"
));
-
-
-
-
m_listDNS.ResetContent();
-
-
HKEY
hNetCard = NULL;
-
-
-
lRtn = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T(
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards"
),0,KEY_READ,&hNetCard);
-
if
(lRtn != ERROR_SUCCESS)
-
{
-
if
(hNetCard != NULL)
-
::RegCloseKey(hNetCard);
-
return
;
-
}
-
-
DWORD
dwSubKeyNum = 0,dwSubKeyLen = 256;
-
-
lRtn = ::RegQueryInfoKey(hNetCard,NULL,NULL,NULL,&dwSubKeyNum,&dwSubKeyLen,
-
NULL,NULL,NULL,NULL,NULL,NULL);
-
if
(lRtn == ERROR_SUCCESS)
-
{
-
-
LPTSTR
lpszKeyName =
new
TCHAR
[dwSubKeyLen + 1];
-
DWORD
dwSize;
-
for
(
int
i = 0; i < (
int
)dwSubKeyNum; i++)
-
{
-
TCHAR
szServiceName[256];
-
HKEY
hNewKey;
-
DWORD
dwType = REG_SZ,dwDataSize = 256;
-
dwSize = dwSubKeyLen + 1;
-
::RegEnumKeyEx(hNetCard,i,lpszKeyName,&dwSize,NULL,NULL,NULL,NULL);
-
lRtn = ::RegOpenKeyEx(hNetCard,lpszKeyName,0,KEY_READ,&hNewKey);
-
if
(lRtn == ERROR_SUCCESS)
-
{
-
dwDataSize = 256;
-
lRtn = ::RegQueryValueEx(hNewKey,_T(
"ServiceName"
),NULL,&dwType,(
LPBYTE
)szServiceName,&dwDataSize);
-
if
(lRtn == ERROR_SUCCESS)
-
{
-
TCHAR
szNewKey[256];
-
wsprintf(szNewKey,_T(
"%s\\Interfaces\\%s"
),szParameters,szServiceName);
-
HKEY
hTcpKey;
-
lRtn = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,szNewKey,0,KEY_READ,&hTcpKey);
-
if
(lRtn == ERROR_SUCCESS)
-
{
-
dwDataSize = 256;
-
::RegQueryValueEx(hTcpKey,_T(
"NameServer"
),NULL,&dwType,(
LPBYTE
)m_CardsNameServer[i],&dwDataSize);
-
m_listDNS.AddString(m_CardsNameServer[i]);
-
}
-
::RegCloseKey(hTcpKey);
-
}
-
}
-
::RegCloseKey(hNewKey);
-
}
-
delete
[] lpszKeyName;
-
}
-
::RegCloseKey(hNetCard);
-
}
|