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

📄 vpndialerdlg.cpp

📁 VPN拨号程序源码(from sourceforge.net)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// VPNDialerDlg.cpp : implementation file
//

/*******************************************************************************
 *                                                                             *
 *  This file is part of VPNDialer.                                            *
 *                                                                             *
 *  VPNDialer is free software; you can redistribute it and/or modify          *
 *  it under the terms of the GNU General Public License as published by       *
 *  the Free Software Foundation; either version 2 of the License, or          *
 *  (at your option) any later version.                                        *
 *                                                                             *
 *  VPNDialer is distributed in the hope that it will be useful,               *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 *  GNU General Public License for more details.                               *
 *                                                                             *
 *  You should have received a copy of the GNU General Public License          *
 *  along with VPNDialer; if not, write to the Free Software                   *
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  *
 *                                                                             *
 *  Copyright (c) 2003 Evidian GmbH, written by Thomas Kriener                 *
 *                                                                             *
 *******************************************************************************/

#include "stdafx.h"
#include "VPNDialer.h"
#include "VPNDialerDlg.h"
#include "ConfigDialog.h"
#include "DebugDialog.h"
#include "VPNConfig.h"
#include "RASHelper.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVPNDialerDlg dialog

CVPNDialerDlg::CVPNDialerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CVPNDialerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CVPNDialerDlg)
	m_log = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CVPNDialerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVPNDialerDlg)
	DDX_Control(pDX, IDCANCEL, m_buttonCancel);
	DDX_Control(pDX, IDC_BUTTON_DISCONNECT, m_buttonDisconnect);
	DDX_Control(pDX, IDOK, m_buttonConnect);
	DDX_Control(pDX, IDC_COMBO_CONNECTIONS, m_connectionCtrl);
	DDX_Text(pDX, IDC_LOG, m_log);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CVPNDialerDlg, CDialog)
	//{{AFX_MSG_MAP(CVPNDialerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, OnButtonDisconnect)
	ON_MESSAGE(MYWM_UPDATEDISPLAY, OnUpdateDisplay)
	ON_BN_CLICKED(IDC_BUTTON_STATUS, OnButtonStatus)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVPNDialerDlg message handlers

BOOL CVPNDialerDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	ASSERT((IDM_CONFIG & 0xFFF0) == IDM_CONFIG);
	ASSERT(IDM_CONFIG < 0xF000);
	ASSERT((IDM_DEBUG & 0xFFF0) == IDM_DEBUG);
	ASSERT(IDM_DEBUG < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		CString strConfigMenu;
		CString strDebugMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		strConfigMenu.LoadString(IDS_CONFIGMENU);
		strDebugMenu.LoadString(IDS_DEBUGMENU);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_DEBUG, strDebugMenu);
			pSysMenu->AppendMenu(MF_STRING, IDM_CONFIG, strConfigMenu);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// Read out Connections
	for(int i=0;i<m_vpnConfig.m_vpnSessions.GetSize();i++)
	{
		m_connectionCtrl.AddString(m_vpnConfig.m_vpnSessions[i].m_name);
	}

	m_connectionCtrl.SetCurSel(0);

	// We are offline first
	m_online=false;
	m_rasSession.InitRAS();
	m_l2tpSession.InitRAS();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CVPNDialerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else if ((nID & 0xFFF0) == IDM_CONFIG)
	{
		CConfigDialog dlg;
		dlg.m_vpnConfig=&m_vpnConfig;
		dlg.DoModal();

		m_connectionCtrl.ResetContent();
		for(int i=0;i<m_vpnConfig.m_vpnSessions.GetSize();i++)
		{
			m_connectionCtrl.AddString(m_vpnConfig.m_vpnSessions[i].m_name);
		}
		m_connectionCtrl.SetCurSel(0);

		UpdateData(FALSE);
	}
	else if ((nID & 0xFFF0) == IDM_DEBUG)
	{
		CDebugDialog dlg;
		dlg.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CVPNDialerDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CVPNDialerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CVPNDialerDlg::OnOK() 
{
	BeginWaitCursor(); // display the hourglass cursor
	m_connectionCtrl.EnableWindow(FALSE);
	m_buttonConnect.EnableWindow(FALSE);
	m_buttonCancel.EnableWindow(FALSE);
	AfxBeginThread(EstablishSession,this);
}

void CVPNDialerDlg::OnButtonDisconnect() 
{
	m_online=false;
	m_buttonCancel.EnableWindow(FALSE);
	m_buttonDisconnect.EnableWindow(FALSE);

	if(m_rasSession.IsConnected())
		m_rasSession.HangUp();
	if(m_l2tpSession.IsConnected())
		m_l2tpSession.HangUp();

	m_vpnConfig.RemoveIPSec();

	m_connectionCtrl.EnableWindow(TRUE);
	m_buttonConnect.EnableWindow(TRUE);
	m_buttonCancel.EnableWindow(TRUE);
}

UINT CVPNDialerDlg::EstablishSession(LPVOID pParam)
{
	CVPNDialerDlg* dlg;
	int            sessionNr;
	CVPNSession    actSession;
	CString        ipsectool;
	CString        my_ip, my_l2tpip, testIp;
	int            i;
	DWORD          dialState;
	CString        tmp;
	int            dialTry;
	BOOL           exitDialLoop;

⌨️ 快捷键说明

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