📄 dddlqserverdlg.cpp
字号:
// ddDlqServerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ddDlqServer.h"
#include "ddDlqServerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "FileOperation.h"
#include "AdManage.h"
#include "VpnServer.h"
#include "UserManage.h"
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
extern CDdDlqServerApp theApp;
void ddGlSend2Client(SOCKET sckt, CString sData);
// 客户连接列表
SOCKET m_arClient[MAX_SOCKET]; // 套节字数组
int m_nClient; // 上述数组的大小
bool bNotExitSendAD;
UINT ddGlSendAD(LPVOID pParam);
// 定义网络事件通知消息
#define WM_MYSOCKET WM_USER + 123
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()
/////////////////////////////////////////////////////////////////////////////
// CDdDlqServerDlg dialog
CDdDlqServerDlg::CDdDlqServerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDdDlqServerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDdDlqServerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDdDlqServerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDdDlqServerDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDdDlqServerDlg, CDialog)
//{{AFX_MSG_MAP(CDdDlqServerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_BTN_EXITSERV, OnBtnExitserv)
ON_BN_CLICKED(IDC_BTN_AD, OnBtnAdvManage)
ON_BN_CLICKED(IDC_BTN_VPNSERVER, OnBtnVpnServer)
ON_BN_CLICKED(IDC_BTN_USER, OnBtnUser)
ON_MESSAGE(WM_MYSOCKET, OnMySocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDdDlqServerDlg message handlers
BOOL CDdDlqServerDlg::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);
}
}
// 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
// 创建状态栏,设置它的属性
m_bar.Create(WS_CHILD|WS_VISIBLE|SBS_SIZEGRIP, CRect(0, 0, 0, 0), this, 101);
m_bar.SetBkColor(RGB(0xa6, 0xca, 0xf0)); // 背景色
int arWidth[] = { 200, -1 };
m_bar.SetParts(2, arWidth); // 分栏
m_bar.SetText(" vpn虚拟拨号管理软件试用版", 1, 0); // 第一个栏的文本
m_bar.SetText(" 空闲", 0, 0); // 第二个栏的文本
CString Database, FilePath, executeSQL;// = "E:\\das software\\ddDlqServer\\ddvpndb.mdb";
int index;
Database = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=";
FilePath = ddGetAppFileName();
index = FilePath.ReverseFind('\\');
FilePath = FilePath.Left(index) + "\\ddvpndb.mdb";
Database += FilePath;
BOOL bb = theApp.adoDatabase.Open(Database, _T(""), _T(""));
executeSQL = "select * from ddAdv order by adSerial";
//bb = adoRcdSet.Open(executeSQL, CADORecordset::openTable);
//adoRcdSet = CADORecordset(&adoDatabase);
//bb = adoRcdSet.Open(executeSQL, CADORecordset::openStoredProc);
theApp.adoRstAdv = CADORecordset();
//openUnknown = 0,
//openQuery = 1,
//openTable = 2,
//openStoredProc = 3
bb = theApp.adoRstAdv.Open(theApp.adoDatabase.m_pConnection, executeSQL, CADORecordset::openUnknown);
/*theApp.adoRstAdv.MoveFirst();
long ll = theApp.adoRstAdv.GetFieldCount();//得到字段的数量
ll = theApp.adoRstAdv.GetRecordCount();
int ise;
CString str;
while(!theApp.adoRstAdv.IsEOF())
{
theApp.adoRstAdv.GetFieldValue("adSerial", ise);
theApp.adoRstAdv.GetFieldValue("adContent", str);
theApp.adoRstAdv.GetFieldValue("adDate", str);
//adoRstAdv.Edit();
//adoRstAdv.SetFieldValue("adDate", str+"8");
//adoRstAdv.Update();
theApp.adoRstAdv.MoveNext();
}*/
//adoRstAdv.MoveLast();
//adoRstAdv.MovePrevious();
//adoRstAdv.Delete();
//adoRstAdv.MoveLast();
//adoRstAdv.AddNew();
//adoRstAdv.SetFieldValue("adSerial", 123);
//str=_T("dsfge54");
//adoRstAdv.SetFieldValue("adContent", str);
//str=_T("975927");
//adoRstAdv.SetFieldValue("adDate", str);
//adoRstAdv.Update();
executeSQL = "select * from ddServer order by servName";
theApp.adoRstServer = CADORecordset();
bb = theApp.adoRstServer.Open(theApp.adoDatabase.m_pConnection, executeSQL, CADORecordset::openUnknown);
executeSQL = "select * from ddUser order by ddUserName";
theApp.adoRstUser = CADORecordset();
bb = theApp.adoRstUser.Open(theApp.adoDatabase.m_pConnection, executeSQL, CADORecordset::openUnknown);
theApp.glGetAllServer();
//theApp.glGetUsedServer();
theApp.glGetAllUser();
bNotExitSendAD = true;
AfxBeginThread(&ddGlSendAD, 0);
// 初始化监听套节字和连接列表
m_socket = INVALID_SOCKET;
m_nClient = 0;
// 下面是取得本地IP地址的过程,将它显示在状态栏的第一个分栏中
// 取得本机名称
char szHost[256];
::gethostname(szHost, 256);
// 通过本机名称取得地址信息
HOSTENT* pHost = gethostbyname(szHost);
if(pHost != NULL)
{
CString sIP;
// 得到第一个IP地址
in_addr *addr =(in_addr*) *(pHost->h_addr_list);
// 显示给用户
sIP.Format(" 本机IP:%s", inet_ntoa(addr[0]));
m_bar.SetText(sIP, 0, 0);
}
ddStartServer();
return TRUE;
}
void CDdDlqServerDlg::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 CDdDlqServerDlg::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 CDdDlqServerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDdDlqServerDlg::OnOK()
{
//CDialog::OnOK();
}
void CDdDlqServerDlg::OnCancel()
{
//CDialog::OnCancel();
}
void CDdDlqServerDlg::OnBtnExitserv()
{
// TODO: Add your control notification handler code here
ddCloseAllSocket();
CDialog::OnCancel();
}
void CDdDlqServerDlg::OnBtnAdvManage()
{
// TODO: Add your control notification handler code here
CAdManage dlg;
dlg.DoModal();
}
BOOL CDdDlqServerDlg::DestroyWindow()
{
// 程序退出时要卸载的资源
bNotExitSendAD = false;
theApp.adoRstAdv.Close();
theApp.adoRstServer.Close();
theApp.adoRstUser.Close();
theApp.adoDatabase.Close();
return CDialog::DestroyWindow();
}
void CDdDlqServerDlg::OnBtnVpnServer()
{
// TODO: Add your control notification handler code here
CVpnServer dlg;
dlg.DoModal();
}
void CDdDlqServerDlg::OnBtnUser()
{
// TODO: Add your control notification handler code here
CUserManage dlg;
dlg.DoModal();
}
UINT ddGlSendAD(LPVOID pParam)
{
CDdDlqServerDlg *pDlg = (CDdDlqServerDlg *)AfxGetMainWnd();
CString str;
while(bNotExitSendAD)
{
WaitForSingleObject(theApp.g_hAdEvent, INFINITE);
theApp.adoRstAdv.MoveLast();
theApp.adoRstAdv.GetFieldValue("adContent", str);
str.Insert(0, TCHAR(0X80));
for(int i=0; i<m_nClient; i++)
ddGlSend2Client(m_arClient[i], str);
Sleep(1);
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -