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

📄 thorclient2dlg.cpp

📁 802.1x认证客户端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//ThorClient 802.1x (using WinPcap 3.2 alpha1)
//Download: http://thorqq.ys168.com 
//E-mail:   thorqq@163.com 
//Author:   Thorqq
/////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ThorClient2.h"
#include "ThorClient2Dlg.h"
#include "netcfg.h"
#include "iphlpapi.h"

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

#define WM_MY_TRAY_NOTIFICATION WM_USER+100

typedef DWORD(CALLBACK *PGAINFO)(PIP_ADAPTER_INFO,PULONG);//GetAdaptersInfo
typedef DWORD(CALLBACK *PGIINFO)(PIP_INTERFACE_INFO,PULONG);//GetInterfaceInfo
typedef DWORD(CALLBACK *PIRELEASEADDRESS)(PIP_ADAPTER_INDEX_MAP);//IpReleaseAddress
typedef DWORD(CALLBACK *PIRENEWADDRESS)(PIP_ADAPTER_INDEX_MAP);//IpRenewAddress
/////////////////////////////////////////////////////////////////////////////
// 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)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CThorClient2Dlg dialog

CThorClient2Dlg::CThorClient2Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CThorClient2Dlg::IDD, pParent),trayIcon(IDR_MENU),DataFile(&UserData)
{
	//{{AFX_DATA_INIT(CThorClient2Dlg)
	m_password = _T("");
	m_username = _T("");
	m_rempwd = FALSE;
	m_autologin = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDI_ICONON);
}

void CThorClient2Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CThorClient2Dlg)
	DDX_Control(pDX, IDC_NIC, m_nic);
	DDX_Control(pDX, IDC_IPADDRESS, m_ipaddress);
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_password);
	DDX_Text(pDX, IDC_EDIT_USERNAME, m_username);
	DDX_Check(pDX, IDC_CHECK_SAVEPWD, m_rempwd);
	DDX_Check(pDX, IDC_CHECK_AUTO, m_autologin);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CThorClient2Dlg, CDialog)
	//{{AFX_MSG_MAP(CThorClient2Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_CONNECT, OnButtonConnect)
	ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, OnButtonDisconnect)
	ON_BN_CLICKED(IDC_BUTTON_NETCONFIG, OnButtonNetconfig)
	ON_BN_CLICKED(IDC_BUTTON_HELP, OnButtonHelp)
	ON_BN_CLICKED(IDC_BUTTON_MINI, OnButtonMini)
	ON_BN_CLICKED(IDC_CHECK_AUTO, OnCheckAuto)
	ON_BN_CLICKED(IDC_CHECK_SAVEPWD, OnCheckSavepwd)
	ON_WM_SIZE()
	ON_COMMAND(ID_MENU_OPEN, OnMenuOpen)
	ON_COMMAND(ID_MENU_CONNECT, OnMenuConnect)
	ON_COMMAND(ID_MENU_DISCONNECT, OnMenuDisconnect)
	ON_COMMAND(ID_MENU_ABOUT, OnMenuAbout)
	ON_COMMAND(ID_MENUIT_QUIT, OnMenuitQuit)
	ON_CBN_DROPDOWN(IDC_NIC, OnDropdownNic)
	ON_CBN_SELCHANGE(IDC_NIC, OnSelchangeNic)
	ON_COMMAND(ID_MENU_NETCONFIG, OnMenuNetconfig)
	ON_UPDATE_COMMAND_UI(ID_MENU_CONNECT, OnUpdateMenuConnect)
	ON_UPDATE_COMMAND_UI(ID_MENU_DISCONNECT, OnUpdateMenuDisconnect)
	ON_UPDATE_COMMAND_UI(ID_MENU_NETCONFIG, OnUpdateMenuNetconfig)
	ON_WM_INITMENUPOPUP()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CThorClient2Dlg message handlers

BOOL CThorClient2Dlg::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);

	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);
		
			pSysMenu->AppendMenu(MF_STRING, SC_MINIMIZE, "最小化");
			pSysMenu->AppendMenu(MF_STRING, SC_MAXIMIZE, "最大化");
			pSysMenu->AppendMenu(MF_STRING, SC_RESTORE, "Restore");

			ModifyStyle( 0, WS_MINIMIZEBOX );
		}
	}

	// 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
	
	// TODO: Add extra initialization here
	GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(false);
	
	trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);
	trayIcon.SetIcon(IDI_ICONOFF);

	DataFile.Load();
	
	m_username = UserData.username;
	m_password = UserData.password;
	m_ipaddress.SetAddress(UserData.ip[0], UserData.ip[1], 
		UserData.ip[2], UserData.ip[3]);

	CMyComboBox* Nic = (CMyComboBox*)GetDlgItem(IDC_NIC);
	Nic->AddString(UserData.nicdes);
	Nic->SetCurSel(0);
	Nic->SetDroppedWidth(224);

	m_autologin = UserData.autologin;
	m_rempwd    = UserData.rempwd;

	UpdateData(false);

	Dot1X = new CDot1X(m_hWnd);
	if(m_autologin)
		OnButtonConnect();

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

void CThorClient2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.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 CThorClient2Dlg::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();
	}
}

void CThorClient2Dlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
{
    ASSERT(pPopupMenu != NULL);
    // Check the enabled state of various menu items.

    CCmdUI state;
    state.m_pMenu = pPopupMenu;
    ASSERT(state.m_pOther == NULL);
    ASSERT(state.m_pParentMenu == NULL);

    // Determine if menu is popup in top-level menu and set m_pOther to
    // it if so (m_pParentMenu == NULL indicates that it is secondary popup).
    HMENU hParentMenu;
    if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
        state.m_pParentMenu = pPopupMenu;    // Parent == child for tracking popup.
    else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
    {
        CWnd* pParent = this;
           // Child windows don't have menus--need to go to the top!
        if (pParent != NULL &&
           (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
        {
           int nIndexMax = ::GetMenuItemCount(hParentMenu);
           for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
           {
				if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
				{
					// When popup is found, m_pParentMenu is containing menu.
					state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
					break;
				}
			}
        }
    }

    state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
    for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
      state.m_nIndex++)
    {
        state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
        if (state.m_nID == 0)
           continue; // Menu separator or invalid cmd - ignore it.

        ASSERT(state.m_pOther == NULL);
        ASSERT(state.m_pMenu != NULL);
        if (state.m_nID == (UINT)-1)
        {
           // Possibly a popup menu, route to first item of that popup.
           state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
           if (state.m_pSubMenu == NULL ||
            (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
            state.m_nID == (UINT)-1)
           {
            continue;       // First item of popup can't be routed to.
           }
           state.DoUpdate(this, TRUE);   // Popups are never auto disabled.
        }
        else
        {
           // Normal menu item.
           // Auto enable/disable if frame window has m_bAutoMenuEnable
           // set and command is _not_ a system command.
           state.m_pSubMenu = NULL;
           state.DoUpdate(this, FALSE);
        }

        // Adjust for menu deletions and additions.
        UINT nCount = pPopupMenu->GetMenuItemCount();
        if (nCount < state.m_nIndexMax)
        {
			state.m_nIndex -= (state.m_nIndexMax - nCount);
			while (state.m_nIndex < nCount &&
			pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
			{
				state.m_nIndex++;
			}
		}
        state.m_nIndexMax = nCount;
    }
}

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

LRESULT CThorClient2Dlg::OnTrayNotification(WPARAM wp, LPARAM lp)
{
//	UINT uMouseMsg = (UINT) lp;
		
//	switch (uMouseMsg)
//	{
//		case WM_MOUSEMOVE:		
//			trayIcon.ShowBalloonTip("欢迎使用Thor802.1x客户端\nE-mail:thorqq@163.com\nQQ:471098909",
//				"Thor 802.1x", 1, NIIF_INFO);
//		default: break;
//	}

	// let tray icon do default stuff
	return trayIcon.OnTrayNotification(wp, lp);
}

void CThorClient2Dlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	DataFile.Save();
	delete Dot1X;
}

void CThorClient2Dlg::OnButtonConnect() 
{
	// TODO: Add your control notification handler code here

⌨️ 快捷键说明

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