📄 xxxlogondlg.cpp
字号:
#include "stdafx.h"
#include "xxxlogon.h"
#include "xxxlogonDlg.h"
#include "lm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma comment(lib,"netapi32")
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()
/////////////////////////////////////////////////////////////////////////////
// CXxxlogonDlg dialog
CXxxlogonDlg::CXxxlogonDlg(CWnd* pParent /*=NULL*/)
: CDialog(CXxxlogonDlg::IDD, pParent),
m_pMySocket(NULL),
m_pListenSocket(NULL),
m_fNetLogon(TRUE)
{
//{{AFX_DATA_INIT(CXxxlogonDlg)
m_strLog = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CXxxlogonDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXxxlogonDlg)
DDX_Text(pDX, IDC_EDITLOG, m_strLog);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CXxxlogonDlg, CDialog)
//{{AFX_MSG_MAP(CXxxlogonDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BNETLOGON, OnBnetlogon)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXxxlogonDlg message handlers
BOOL CXxxlogonDlg::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
m_pListenSocket = new CListenSocket(this);
ASSERT(m_pListenSocket);
if(m_pListenSocket->Create(4567,SOCK_STREAM,FD_CLOSE |FD_ACCEPT)){
if(m_pListenSocket->Listen(5))
return TRUE;
}
AfxMessageBox(_T("I can't begin listening on 4567 port,please re-start!!!"),MB_OK | MB_ICONSTOP);
ExitProcess(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CXxxlogonDlg::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 CXxxlogonDlg::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 CXxxlogonDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CXxxlogonDlg::OnBnetlogon()
{
m_fNetLogon =!m_fNetLogon;
if(m_fNetLogon)
GetDlgItem(IDC_BNETLOGON)->SetWindowText(_T("DisNetLogon"));
else
GetDlgItem(IDC_BNETLOGON)->SetWindowText(_T("EnNetLogon"));
}
VOID CXxxlogonDlg::ProcessPendingAccept()
{
if(m_pMySocket){
m_pMySocket->Close();
delete m_pMySocket;
m_pMySocket = NULL;
}
m_pMySocket = new CMySocket(this);
ASSERT(m_pMySocket);
if(m_pListenSocket->Accept(*m_pMySocket)){
m_pMySocket->AsyncSelect(FD_READ | FD_CLOSE);
}
else{
delete m_pMySocket;
m_pMySocket = NULL;
AfxMessageBox(_T("What's wrong with Accept funtion,please re-start it!!!"),MB_OK | MB_ICONSTOP);
ExitProcess(0);
}
}
VOID CXxxlogonDlg::ProcessPendingClose()
{
ASSERT(m_pMySocket);
m_pMySocket->Close();
delete m_pMySocket;
m_pMySocket = NULL;
}
int _split_string(char *p_str,
char **pp_vectors,
int ivector,
char *p_delimiter,
char *p_terminater = NULL
)
{
char chr;
char *p_vector;
char *p_itr,*p_hdr;
int len;
int iv;
int i;
char c_map[256];
for ( i = 0; i < ivector; ++i){
pp_vectors[i] = NULL;
}
//
// Initialize c_map
//
for (i = 0; i < 256 ; ++i){
c_map[i] = 0;
}
if (p_delimiter){
while (*p_delimiter){
c_map[*p_delimiter++] = 1;
}
}
else {
c_map[' '] = 1;
c_map['\t'] = 1;
c_map['\r'] = 1;
c_map['\n'] = 1;
}
if (p_terminater){
while (*p_terminater){
c_map[*p_terminater++] = 2;
}
}
c_map['\0'] = 2;
p_itr = p_str;
p_hdr = NULL;
iv = 0;
len = 0;
while ( ( chr = *p_itr) ){
if (iv >= ivector){
return iv;
}
if ( 2 == c_map[chr]){
break;
}
if ( 1 == c_map[chr] ){
if (0 != len && p_hdr ){
*p_itr = '\0';
p_vector = strdup(p_hdr);
if (p_vector){
pp_vectors[iv++] = p_vector;
}
else {
*p_itr = chr;
return iv;
}
*p_itr = chr;
}
len = 0;
p_hdr = NULL;
}
else {
if (NULL == p_hdr){
p_hdr = p_itr;
}
++len;
}
++p_itr;
}
if (len && p_hdr){
if (iv < ivector){
*p_itr = '\0';
p_vector = strdup(p_hdr);
if (p_vector){
pp_vectors[iv++] = p_vector;
}
*p_itr = chr;
}
}
return iv;
}
#include <iphlpapi.h>
BOOL CXxxlogonDlg::GetHostInfo(char *p_szHost,char *p_szip,char *p_szmac)
{
hostent *p_host;
DWORD i;
DWORD ie;
BYTE eaddr[6];
DWORD dwIP;
char *p_itr;
BOOL fGet;
p_host = gethostbyname(p_szHost);
if (!p_host){
return FALSE;
}
i = 0;
fGet = FALSE;
while ( (p_itr = p_host->h_addr_list[i]) ){
dwIP = *(DWORD*)p_itr;
ie = 6;
if (NO_ERROR == SendARP(dwIP,0,(DWORD*)eaddr,&ie)){
if (6 != ie){
return FALSE;
}
fGet = TRUE;
break;
}
++i;
}
if (!fGet){
return FALSE;
}
p_itr = inet_ntoa(*(in_addr*)&dwIP);
if (!p_itr){
return FALSE;
}
strcpy(p_szip,p_itr);
sprintf(p_szmac,"%02x %02x %02x %02x %02x %02x",
eaddr[0],
eaddr[1],
eaddr[2],
eaddr[3],
eaddr[4],
eaddr[5]
);
return TRUE;
}
VOID CXxxlogonDlg::ProcessPendingRecv(int nErrCode)
{
char buf[512];
char ansibuf[512];
WCHAR *p;
char *p_v[20];
int iv,i;
char p_szmac[100];
char p_szip[100];
SYSTEMTIME sysTime;
char p_sztime[300];
GetLocalTime(&sysTime);
sprintf(p_sztime,"%d year %d month %d day %d hour %d minute %d second\r\n",
sysTime.wYear,
sysTime.wMonth,
sysTime.wDay,
sysTime.wHour,
sysTime.wMinute,
sysTime.wSecond
);
TRACE(p_sztime);
::memset(buf,0,512);
::memset(ansibuf,0,512);
i = m_pMySocket->Receive(buf,512,0);
if(0 == i || SOCKET_ERROR == i){
m_pMySocket->Close();
delete m_pMySocket;
m_pMySocket = NULL;
return ;
}
buf[i] = '\0';
p = (WCHAR*)buf;
::WideCharToMultiByte(CP_ACP,
0,
p,
-1,
ansibuf,
512,
NULL,
NULL);
TRACE(ansibuf);
iv = _split_string(ansibuf,p_v,20,"\r\n");
if ( 4 != iv){
for (i = 0;i < iv;++i){
free(p_v[i]);
}
m_pMySocket->Send("OK OK",4);
return ;
}
CString strTmp = _T("");
strTmp = "Domain:";
strTmp += p_v[0];
strTmp += "\r\n";
strTmp += "Username:";
strTmp += p_v[1];
strTmp += "\r\n";
strTmp += "FullName:";
strTmp += p_v[2];
strTmp += "\r\n";
strTmp += "Workstation:";
strTmp += p_v[3];
strTmp += "\r\n";
if (GetHostInfo(p_v[3],p_szip,p_szmac)){
strTmp += "IP Address:";
strTmp += p_szip;
strTmp += "\r\n";
strTmp += "Mac Address:";
strTmp += p_szmac;
strTmp += "\r\n";
}
strTmp += "Time:";
strTmp += p_sztime;
strTmp += "\r\n";
m_strLog += strTmp;
m_strLog +=_T("\r\n\r\n");
UpdateData(FALSE);
if(IDYES == AfxMessageBox(m_strLog,MB_YESNO)){
m_pMySocket->Send("ok ok",4);
}
else {
m_pMySocket->Send("NO NO",5);
}
for (i = 0;i < iv;++i){
free(p_v[i]);
}
}
void CXxxlogonDlg::OnClose()
{
if(m_pListenSocket){
m_pListenSocket->Close();
delete m_pListenSocket;
}
if(m_pMySocket){
m_pMySocket->Close();
delete m_pMySocket;
}
CDialog::OnClose();
}
void CXxxlogonDlg::OnBnClickedOk()
{
FILE *pf;
pf = fopen("c:\\logdata.txt","ab");
if (pf){
fwrite(m_strLog.GetBuffer(),1,m_strLog.GetLength(),pf);
m_strLog.ReleaseBuffer();
fclose(pf);
}
return;
}
void CXxxlogonDlg::OnBnClickedCancel()
{
FILE *pf = fopen("c:\\logdata.txt","ab");
if (pf){
fwrite(m_strLog.GetBuffer(),1,m_strLog.GetLength(),pf);
m_strLog.ReleaseBuffer();
fclose(pf);
}
OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -