📄 ccamscdlg.cpp
字号:
// CCAMSCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CCAMSC.h"
#include "CCAMSCDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CCAMSCDlg dialog
CCAMSCDlg::CCAMSCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCAMSCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCAMSCDlg)
m_StrCpuUsage = _T("");
m_StrNowtime = _T("");
m_Port = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCAMSCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCAMSCDlg)
DDX_Control(pDX, IDC_BUTTON_connect, m_CtrlConnect);
DDX_Control(pDX, IDC_BUTTON_Capture, m_CtrlCapture);
DDX_Control(pDX, IDC_COMBO_NIC, m_CtrlComboBoxNIC);
DDX_Control(pDX, IDC_COMBO_Driver, m_CtrlComboBoxDriver);
DDX_Control(pDX, IDC_EDIT_Port, m_CtrlPort);
DDX_Control(pDX, IDC_IPADDRESS, m_CtrlIpAddress);
DDX_Control(pDX, IDC_LIST_Activities, m_CtrlList);
DDX_Text(pDX, IDC_STATIC_CUPUSAGE, m_StrCpuUsage);
DDX_Text(pDX, IDC_STATIC_NOWTIME, m_StrNowtime);
DDX_Text(pDX, IDC_EDIT_Port, m_Port);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCAMSCDlg, CDialog)
//{{AFX_MSG_MAP(CCAMSCDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(IDC_MENU_EXIT, OnMenuExit)
ON_COMMAND(IDR_MENU_ABOUT, OnMenuAbout)
ON_COMMAND(IDC_MENU_SHOW, OnMenuShow)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_Capture, OnStartCapture)
ON_BN_CLICKED(IDC_BUTTON_connect, OnConnectServer)
ON_COMMAND(ID_MENU_Help, OnMENUHelp)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_USER_TRAY_NOTIFICATION,OnTrayNotification)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCAMSCDlg message handlers
BOOL CCAMSCDlg::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
//creat initialization trayIcon
m_trayIcon.Create(this, WM_USER_TRAY_NOTIFICATION, "CCAMSC",m_hIcon, IDR_MENU_TRAY);
//read set.ini
TCHAR exeFullPath[_MAX_PATH];
CString T_CStr_FileName="";
GetModuleFileName(NULL,exeFullPath,_MAX_PATH);
for(int i=0;exeFullPath[i]!='\0';i++)//TCHAR to CString
T_CStr_FileName+=exeFullPath[i];
int T_StrStart=T_CStr_FileName.ReverseFind('\\');//cat appName
CString t_StrEXE=T_CStr_FileName.Mid(T_StrStart+1);
T_CStr_FileName.Replace(t_StrEXE,"sets.ini");//add create File name
char inBuf[10]={' '};
int nField0,nField1,nField2,nField3;
GetPrivateProfileString ("Server", "nField0", "192", inBuf, 10, T_CStr_FileName);
nField0=atoi(inBuf);
GetPrivateProfileString ("Server", "nField1", "168", inBuf, 10, T_CStr_FileName);
nField1=atoi(inBuf);
GetPrivateProfileString ("Server", "nField2", "0", inBuf, 10, T_CStr_FileName);
nField2=atoi(inBuf);
GetPrivateProfileString ("Server", "nField3", "1", inBuf,10, T_CStr_FileName);
nField3=atoi(inBuf);
m_CtrlIpAddress.SetAddress(nField0, nField1,nField2, nField3 );
GetPrivateProfileString ("Server", "Port", "5530", inBuf, 10, T_CStr_FileName);
m_Port=atoi(inBuf);
//find all the drives
char szDrives[129];
if ( !GetLogicalDriveStrings( sizeof(szDrives) - 1, szDrives ) )
//szDrives中的内容: a:\<null>c:\<null>d:\<null>e:\<null>f:\<null>g:\<null><null>
{
MessageBox("Error Getting Logical DriveStrings!") ;
}
char* pDrive = szDrives;
while( *pDrive )
{
m_CtrlComboBoxDriver.AddString(pDrive);
pDrive += strlen( pDrive ) + 1; //注意,strlen(pDrive)==3 // Good!!!!!!
}
// m_CtrlComboBoxDriver.GetCurSel()
//get the NIC
m_MailProbe.initallize();
for( i=0;i<=m_MailProbe.devnum-1;i++)
m_CtrlComboBoxNIC.AddString(m_MailProbe.devdesc[i]);
m_CtrlComboBoxDriver.SetCurSel(0);
m_CtrlComboBoxNIC.SetCurSel(0);
m_CtrlCapture.EnableWindow(false);
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCAMSCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else if ((nID & 0xFFF0)==SC_CLOSE){
//OnClose();本来这个是关闭的 这里也改为隐藏。
ShowWindow(SW_HIDE);
}
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 CCAMSCDlg::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 CCAMSCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
LONG CCAMSCDlg::OnTrayNotification(WPARAM wparam, LPARAM lparam)
{
switch ( lparam )// The tray icon sent us a message. Let's see what it is
{
/*case WM_CONTEXTMENU:
TRACE( "WM_CONTEXTMENU\n" );*/
case WM_RBUTTONDOWN:
{// popu menu
CMenu oMenu;
if (oMenu.LoadMenu(IDR_MENU_TRAY))
{
CMenu* pPopup = oMenu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CPoint oPoint;
if (IsWindowVisible())// 根据对话框窗口的显示/隐藏状态修改菜单名称
oMenu.ModifyMenu(IDC_MENU_SHOW,MF_STRING,IDC_MENU_SHOW,"&Hide");
else
oMenu.ModifyMenu(IDC_MENU_SHOW,MF_STRING,IDC_MENU_SHOW,"&Show");
// 确定鼠标位置以便在该位置附近显示菜单
GetCursorPos( &oPoint );
SetForegroundWindow();
pPopup->TrackPopupMenu(
TPM_LEFTALIGN | TPM_RIGHTBUTTON,
oPoint.x, oPoint.y, this);
}
}
break;
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
ShowWindow(SW_SHOW);
break;
}
return 0;
}
void CCAMSCDlg::OnMenuExit()
{
// TODO: Add your command handler code here
OnOK();
}
void CCAMSCDlg::OnMenuAbout()
{
// TODO: Add your command handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
void CCAMSCDlg::OnMenuShow()
{
// TODO: Add your command handler code here
if (!IsWindowVisible()) {
ShowWindow(SW_SHOW);
}
else
ShowWindow(SW_HIDE);
}
void CCAMSCDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
NowTime= CTime::GetCurrentTime();
m_StrCpuUsage.Format("%3d",(UINT)m_CpuProbe.getUsage());
m_StrNowtime=NowTime.Format(_T("%H:%M:%S"));
if(nIDEvent==1){
m_StrNowtime="\n"+m_StrNowtime+" CPU "+m_StrCpuUsage;
std::string CpuInfo=m_StrNowtime;
m_TcpSend.SendBuff(CpuInfo);
//m_CtrlList.AddString(CpuInfo.c_str());
m_MailProbe.CheckMail();
}
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
BOOL CCAMSCDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DestroyWindow();
}
void CCAMSCDlg::OnDestroy()
{
CDialog::OnDestroy();
KillTimer(0);
KillTimer(1);
// TODO: Add your message handler code here
}
void CCAMSCDlg::OnStartCapture()
{
// TODO: Add your control notification handler code
static flag=1;
///////start capture
if (flag) {
SetTimer(0,1000,NULL);
SetTimer(1,3000,NULL);
m_CpuProbe.StartAgent();
NICid=m_CtrlComboBoxNIC.GetCurSel();
m_CtrlComboBoxDriver.GetWindowText(m_monDriver);
if((hProbeThread[0]=CreateThread( 0,0,(LPTHREAD_START_ROUTINE)StartProccessProbe,this,0,0 ))!=NULL)
m_CtrlList.AddString("Proccess Probe thread start succeed !");
else
m_CtrlList.AddString("Proccess Probe thread start failed !");
if( (hProbeThread[1]=CreateThread(0,0,(LPTHREAD_START_ROUTINE)StartMailProbe,this,0,0))!=NULL)
m_CtrlList.AddString("Mail Probe thread start succeed !");
else
m_CtrlList.AddString("Mail Probe thread start failed !");
if( (hProbeThread[2]=CreateThread(0,0,(LPTHREAD_START_ROUTINE)StartFileProbe,this,0,0))!=NULL)
m_CtrlList.AddString("File Probe thread start succeed!");
else
m_CtrlList.AddString("File Probe thread start failed!");
if( (hProbeThread[3]=CreateThread(0,0,(LPTHREAD_START_ROUTINE)StartPacketProbe,this,0,0))!=NULL)
m_CtrlList.AddString("Packet Probe thread start succeed !");
else
m_CtrlList.AddString("Packet Probe thread start failed !");
m_CtrlCapture.SetWindowText("Stop Capture");
flag=0;
}
//////stop capture
else{
if (TerminateThread(hProbeThread[0],0))
m_CtrlList.AddString("Proccess Probe thread Terminated !");
else
m_CtrlList.AddString("Proccess Probe thread not Terminated !");
if (TerminateThread(hProbeThread[1],0))
m_CtrlList.AddString("Mail Probe thread Terminated !");
else
m_CtrlList.AddString("Mail Probe thread not Terminated !");
if (TerminateThread(hProbeThread[2],0))
m_CtrlList.AddString("File Probe thread Terminated !");
else
m_CtrlList.AddString("File Probe thread not Terminated !");
if (TerminateThread(hProbeThread[3],0))
m_CtrlList.AddString("Packet Probe thread Terminated !");
else
m_CtrlList.AddString("Packet Probe thread not Terminated !");
KillTimer(0);
KillTimer(1);
m_CtrlCapture.SetWindowText("Capture");
// m_CtrlConnect.EnableWindow(true);
flag=1;
}
}
DWORD CCAMSCDlg::StartFileProbe(LPVOID lParam)
{
CCAMSCDlg * l_Dlgobj= (CCAMSCDlg * ) lParam;
// std::string t_str
l_Dlgobj->m_FileProbe.Run(l_Dlgobj->m_monDriver);
// FileProbe.Close();
return 1;
}
DWORD CCAMSCDlg::StartPacketProbe(LPVOID lParam)
{
CCAMSCDlg * l_Dlgobj= (CCAMSCDlg * ) lParam;
ProbePacket l_ProbePacket;
l_ProbePacket.StartProbe(l_Dlgobj->NICid);
return 1;
}
DWORD CCAMSCDlg::StartMailProbe(LPVOID lParam)
{
CCAMSCDlg * l_Dlgobj= (CCAMSCDlg * ) lParam;
if (PtrBuffWrite->len>2800) {
l_Dlgobj->m_TcpSend.SendBuff("buff_full");
}
else
l_Dlgobj->m_MailProbe.StartProbe(l_Dlgobj->NICid);
return 1;
}
DWORD CCAMSCDlg::StartProccessProbe(LPVOID lParam)
{
CCAMSCDlg * l_Dlgobj= (CCAMSCDlg * ) lParam;
l_Dlgobj->m_ProcessProbe.Run();
return 1;
}
void CCAMSCDlg::OnConnectServer()
{
// TODO: Add your control notification handler code here
UpdateData(true);
BYTE nField0,nField1,nField2,nField3;
if (m_CtrlIpAddress.IsBlank()) {
MessageBox("Server Ip is need!");
return;
}
m_CtrlIpAddress.GetAddress( nField0, nField1, nField2, nField3 );
CString t_CStrIpAddress;
t_CStrIpAddress.Format("%d.%d.%d.%d",nField0,nField1,nField2,nField3);
std::string t_strIpAddree=t_CStrIpAddress;
char l_IpAddrees[20]={'\0'};
strcpy(l_IpAddrees, t_strIpAddree.c_str());
m_TcpSend.StartSock();
m_TcpSend.CreateSocket();
if(m_TcpSend.CallServer(l_IpAddrees,m_Port)){
m_CtrlList.AddString("Connect Server succeed !");
//save Server iP and port to set.ini
TCHAR exeFullPath[_MAX_PATH];
CString T_CStr_FileName="";
GetModuleFileName(NULL,exeFullPath,_MAX_PATH);
for(int i=0;exeFullPath[i]!='\0';i++)//TCHAR to CString
T_CStr_FileName+=exeFullPath[i];
int T_StrStart=T_CStr_FileName.ReverseFind('\\');//cat appName
CString t_StrEXE=T_CStr_FileName.Mid(T_StrStart+1);
T_CStr_FileName.Replace(t_StrEXE,"sets.ini");//add create File name
t_CStrIpAddress.Format("%d",nField0);
::WritePrivateProfileString("Server","nField0",t_CStrIpAddress,T_CStr_FileName);
t_CStrIpAddress.Format("%d",nField1);
::WritePrivateProfileString("Server","nField1",t_CStrIpAddress,T_CStr_FileName);
t_CStrIpAddress.Format("%d",nField2);
::WritePrivateProfileString("Server","nField2",t_CStrIpAddress,T_CStr_FileName);
t_CStrIpAddress.Format("%d",nField3);
::WritePrivateProfileString("Server","nField3",t_CStrIpAddress,T_CStr_FileName);
t_CStrIpAddress.Format("%d",m_Port);
::WritePrivateProfileString("Server","Port",t_CStrIpAddress,T_CStr_FileName) ;
m_CtrlConnect.EnableWindow(false);
m_CtrlCapture.EnableWindow(true);
}
else{
m_CtrlList.AddString("Connect Server fail ! Please reset and try again!");
}
}
void CCAMSCDlg::OnMENUHelp()
{
// TODO: Add your command handler code here
ShellExecute(NULL,"open","hh.exe", "CCAMSHelp.chm","",SW_SHOW );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -