www.pudn.com > CraftFTP_gb.rar > DialnetPage.cpp
// DialnetPage.cpp : implementation file
//
#include "stdafx.h"
#include "CraftFTP.h"
#include "DialnetPage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialnetPage property page
const DWORD CDialnetPage::m_nHelpIDs[] =
{
IDC_RADIO_LAN, HIDC_RADIO_LAN,
IDC_RADIO_MONDEM, HIDC_RADIO_MONDEM,
IDC_COMBOBOXEX_RAS_ENTRY, HIDC_COMBOBOXEX_RAS_ENTRY,
IDC_EDIT_RAS_USERNAME, HIDC_EDIT_RAS_USERNAME,
IDC_EDIT_RAS_PASSWORD, HIDC_EDIT_RAS_PASSWORD,
IDC_EDIT_RAS_NUMBER, HIDC_EDIT_RAS_NUMBER,
IDC_SPIN_RAS_NUMBER, HIDC_EDIT_RAS_NUMBER,
IDC_EDIT_RAS_WAITNUM, HIDC_EDIT_RAS_WAITNUM,
IDC_SPIN_RAS_WAITNUM, HIDC_EDIT_RAS_WAITNUM,
IDC_CHECK_AUTO_RAS, HIDC_CHECK_AUTO_RAS,
IDC_CHECK_SHOW_RAS_STATUS, HIDC_CHECK_SHOW_RAS_STATUS,
IDC_EDIT_RAS_TITLE, HIDC_EDIT_RAS_TITLE,
IDC_BUTTON_RASCREATE, HIDC_BUTTON_RASCREATE,
IDC_BUTTON_RASEDIT, HIDC_BUTTON_RASEDIT,
IDC_BUTTON_RASREMOVE, HIDC_BUTTON_RASREMOVE,
0 , 0
};
IMPLEMENT_DYNCREATE(CDialnetPage, CPropertyPageExt)
CDialnetPage::CDialnetPage() : CPropertyPageExt(CDialnetPage::IDD)
{
//{{AFX_DATA_INIT(CDialnetPage)
m_szRasPassWord = _T("");
m_szRasUserName = _T("");
m_nWaitNum = 1;
m_szRasTitle = _T("");
m_nRasNumber = 5;
m_bAutoDial = TRUE;
m_bShowDialStatus = TRUE;
//}}AFX_DATA_INIT
m_pImageList = NULL;
m_bRadioLan = TRUE;
m_bRasEnteries = 0;
m_nRasIndex = 0;
m_szRasTitle = _T("Reestablish Connection...");
//注册表段名
m_szSection = _T("RasNetWork");
}
CDialnetPage::~CDialnetPage()
{
if(m_pImageList)
delete m_pImageList;
}
void CDialnetPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPageExt::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialnetPage)
DDX_Control(pDX, IDC_SPIN_RAS_WAITNUM, m_ctrlSpinWaitNum);
DDX_Control(pDX, IDC_SPIN_RAS_NUMBER, m_ctrlSpinRasNumber);
DDX_Control(pDX, IDC_COMBOBOXEX_RAS_ENTRY, m_wndRasComboBox);
DDX_Text(pDX, IDC_EDIT_RAS_PASSWORD, m_szRasPassWord);
DDX_Text(pDX, IDC_EDIT_RAS_USERNAME, m_szRasUserName);
DDX_Text(pDX, IDC_EDIT_RAS_WAITNUM, m_nWaitNum);
DDV_MinMaxUInt(pDX, m_nWaitNum, 0, 5);
DDX_Text(pDX, IDC_EDIT_RAS_TITLE, m_szRasTitle);
DDX_Text(pDX, IDC_EDIT_RAS_NUMBER, m_nRasNumber);
DDV_MinMaxUInt(pDX, m_nRasNumber, 2, 10);
DDX_Check(pDX, IDC_CHECK_AUTO_RAS, m_bAutoDial);
DDX_Check(pDX, IDC_CHECK_SHOW_RAS_STATUS, m_bShowDialStatus);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialnetPage, CPropertyPageExt)
//{{AFX_MSG_MAP(CDialnetPage)
ON_BN_CLICKED(IDC_RADIO_LAN, OnRadioLan)
ON_BN_CLICKED(IDC_RADIO_MONDEM, OnRadioMondem)
ON_CBN_SELCHANGE(IDC_COMBOBOXEX_RAS_ENTRY, OnSelchangeComboboxexRasEntry)
ON_BN_CLICKED(IDC_BUTTON_RASCREATE, OnButtonRasCreate)
ON_BN_CLICKED(IDC_BUTTON_RASEDIT, OnButtonRasEdit)
ON_BN_CLICKED(IDC_BUTTON_RASREMOVE, OnButtonRasRemove)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialnetPage message handlers
BOOL CDialnetPage::OnInitDialog()
{
CPropertyPageExt::OnInitDialog();
// TODO: Add extra initialization here
m_ctrlSpinRasNumber.SetBuddy(GetDlgItem(IDC_EDIT_RAS_NUMBER));
m_ctrlSpinRasNumber.SetRange(2, 10);
m_ctrlSpinRasNumber.SetPos(m_nRasNumber);
m_ctrlSpinWaitNum.SetBuddy(GetDlgItem(IDC_EDIT_RAS_WAITNUM));
m_ctrlSpinWaitNum.SetRange(0, 5);
m_ctrlSpinWaitNum.SetPos(m_nWaitNum);
m_oGroupFrame.SetFrame(this,IDC_STATIC_RASFRAMR,IDC_RADIO_MONDEM);
m_pImageList = new CImageList;
m_pImageList->Create(IDB_BITMAP_RAS,16, 1, RGB(255,0,255));
m_wndRasComboBox.SetImageList(m_pImageList);
ReadRasEntries();
if(m_bRadioLan)
{
CheckRadioButton(IDC_RADIO_LAN,IDC_RADIO_LAN,IDC_RADIO_LAN);
SendMessage(WM_COMMAND,IDC_RADIO_LAN);
}
else
{
CheckRadioButton(IDC_RADIO_MONDEM,IDC_RADIO_MONDEM,IDC_RADIO_MONDEM);
SendMessage(WM_COMMAND,IDC_RADIO_MONDEM);
}
if(m_bRasEnteries<1)
{
CWnd * pCtrl = GetDlgItem(IDC_RADIO_MONDEM);
pCtrl->EnableWindow(FALSE);
}
UpdateData(FALSE); // Update Data
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDialnetPage::OnRadioLan()
{
// TODO: Add your control notification handler code here
m_oGroupFrame.Enable(FALSE);
m_bRadioLan = TRUE;
if(m_bRasEnteries<1)
{
CWnd * pCtrl = GetDlgItem(IDC_RADIO_MONDEM);
pCtrl->EnableWindow(FALSE);
}
}
void CDialnetPage::OnRadioMondem()
{
// TODO: Add your control notification handler code here
m_oGroupFrame.Enable(TRUE);
m_bRadioLan = FALSE;
}
void CDialnetPage::ReadRasEntries()
{
DWORD dwSize = 0, dwEntries = 0;
RASENTRYNAME RasEntryName = {0};
RasEntryName.dwSize = sizeof(RASENTRYNAME);
RasEnumEntries(NULL, NULL, &RasEntryName, &dwSize, &dwEntries);
LPBYTE lpBuffer = new BYTE[dwSize];
LPRASENTRYNAME lpRasEntryName = (LPRASENTRYNAME)lpBuffer;
lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
DWORD dwRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &dwSize, &dwEntries);
if(dwEntries>0)
{
m_wndRasComboBox.ResetContent();
COMBOBOXEXITEM CBEItem;
CBEItem.mask = CBEIF_IMAGE|CBEIF_INDENT|CBEIF_SELECTEDIMAGE|CBEIF_TEXT|CBEIF_LPARAM;
CBEItem.cchTextMax = 0; // is ignored
CBEItem.iItem = -1;
CBEItem.iIndent = 0;
CBEItem.iSelectedImage = 0;
CBEItem.iImage = 0;
//连接数目
m_bRasEnteries = dwEntries;
for(DWORD i=0; iszEntryName;
VERIFY( m_wndRasComboBox.InsertItem( &CBEItem ) >= 0 );
}
if((UINT)m_nRasIndex>dwEntries-1)
m_nRasIndex = 0;
m_wndRasComboBox.SetCurSel(m_nRasIndex);
}
else
{
//没有可用的拨号连接
m_bRadioLan = TRUE;
m_bRasEnteries = 0;
CheckRadioButton(IDC_RADIO_LAN,IDC_RADIO_LAN,IDC_RADIO_LAN);
SendMessage(WM_COMMAND,IDC_RADIO_LAN);
}
delete lpBuffer;
}
void CDialnetPage::OnSelchangeComboboxexRasEntry()
{
// TODO: Add your control notification handler code here
m_nRasIndex = m_wndRasComboBox.GetCurSel();
CString szEntryName;
m_wndRasComboBox.GetLBText(m_wndRasComboBox.GetCurSel(),szEntryName);
BOOL bHasPass = FALSE;
RASDIALPARAMS * rasdialparams = new RASDIALPARAMS;
memset(rasdialparams,0,sizeof(RASDIALPARAMS));
if(RasGetEntryDialParams(szEntryName, rasdialparams, &bHasPass)==0)
{
if(bHasPass)
{
m_szRasUserName = rasdialparams->szUserName;
m_szRasPassWord = rasdialparams->szPassword;
UpdateData(FALSE);
}
}
delete rasdialparams;
}
BOOL CDialnetPage::OnKillActive()
{
// TODO: Add your specialized code here and/or call the base class
BOOL bRet = CPropertyPageExt::OnKillActive();
if( m_bRadioLan == FALSE )
{
if(m_szRasUserName.IsEmpty())
{
CWnd * pCtrl = GetDlgItem(IDC_EDIT_RAS_USERNAME);
pCtrl->SetFocus();
//AfxMessageBox("你需要输入拨号连接的用户名称!",MB_OK|MB_ICONSTOP);
AfxMessageBox("You must input your dial-up username!",MB_OK|MB_ICONSTOP);
return FALSE;
}
if(m_szRasPassWord.IsEmpty())
{
CWnd * pCtrl = GetDlgItem(IDC_EDIT_RAS_PASSWORD);
pCtrl->SetFocus();
//AfxMessageBox("你需要输入拨号连接的用户口令!",MB_OK|MB_ICONSTOP);
AfxMessageBox("You must input your dial-up password!",MB_OK|MB_ICONSTOP);
return FALSE;
}
}
return bRet;
}
void CDialnetPage::LoadValue()
{
CWinApp * theApp = AfxGetApp();
m_bRadioLan = theApp->GetProfileInt(m_szSection, _T("RasByLan"), TRUE);
m_nRasIndex = theApp->GetProfileInt(m_szSection, _T("RasIndex"), 0);
m_szRasUserName = theApp->GetProfileString(m_szSection, _T("UserName"));
m_szRasPassWord = theApp->GetProfileString(m_szSection, _T("PassWord"));
m_nRasNumber = theApp->GetProfileInt(m_szSection, _T("RasNumber"), 5);
m_nWaitNum = theApp->GetProfileInt(m_szSection, _T("WaitTimes"), 1);
m_bAutoDial = theApp->GetProfileInt(m_szSection, _T("AutoDial"), TRUE);
m_bShowDialStatus = theApp->GetProfileInt(m_szSection, _T("ShowStatus"), TRUE);
m_szRasTitle = theApp->GetProfileString(m_szSection, _T("ReRasTitle"), _T("Reestablish Connection..."));
}
void CDialnetPage::SaveValue()
{
CWinApp * theApp = AfxGetApp();
CString szEnrtyName;
m_wndRasComboBox.GetLBText(m_wndRasComboBox.GetCurSel(), szEnrtyName);
theApp->WriteProfileString(m_szSection, _T("EntryName"), szEnrtyName);
theApp->WriteProfileInt(m_szSection, _T("RasByLan"), m_bRadioLan);
theApp->WriteProfileInt(m_szSection, _T("RasIndex"), m_nRasIndex);
theApp->WriteProfileString(m_szSection, _T("UserName"), m_szRasUserName);
theApp->WriteProfileString(m_szSection, _T("PassWord"), m_szRasPassWord);
theApp->WriteProfileInt(m_szSection, _T("RasNumber"), m_nRasNumber);
theApp->WriteProfileInt(m_szSection, _T("WaitTimes"), m_nWaitNum);
theApp->WriteProfileInt(m_szSection, _T("AutoDial"), m_bAutoDial);
theApp->WriteProfileInt(m_szSection, _T("ShowStatus"), m_bShowDialStatus);
theApp->WriteProfileString(m_szSection, _T("ReRasTitle"), m_szRasTitle);
}
void CDialnetPage::OnButtonRasCreate()
{
// TODO: Add your control notification handler code here
CWaitCursor w;
CString szEnrtyName;
m_wndRasComboBox.GetLBText(m_wndRasComboBox.GetCurSel(), szEnrtyName);
RasCreatePhonebookEntry(m_hWnd, (LPCTSTR)szEnrtyName);
ReadRasEntries();
}
void CDialnetPage::OnButtonRasEdit()
{
// TODO: Add your control notification handler code here
CWaitCursor w;
CString szEnrtyName;
m_wndRasComboBox.GetLBText(m_wndRasComboBox.GetCurSel(), szEnrtyName);
RasEditPhonebookEntry(m_hWnd, NULL, (LPCTSTR)szEnrtyName);
ReadRasEntries();
}
void CDialnetPage::OnButtonRasRemove()
{
// TODO: Add your control notification handler code here
CString szEnrtyName;
m_wndRasComboBox.GetLBText(m_wndRasComboBox.GetCurSel(), szEnrtyName);
if(RasDeleteEntry(NULL, (LPCTSTR)szEnrtyName)==ERROR_SUCCESS)
{
m_szRasUserName = _T("");
m_szRasPassWord = _T("");
ReadRasEntries();
if(m_wndRasComboBox.GetCount()==0)
m_wndRasComboBox.ResetContent();
UpdateData(FALSE);
}
}