📄 mainfrm.cpp
字号:
m_wndList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
/*
for(int i=0;i<=10;i++)
{
int nItem=m_wndList.InsertItem(i,_T("测试的"));
for(int j=0;j<=6;j++)
{
CString str;
str.Format("%d行%d列",11-i,j+1);
m_wndList.SetItemText(nItem,j,str);
}
}
*/
m_wndMyBarRight.ModifyStyleEx(0,WS_EX_CLIENTEDGE);
m_wndBar1.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndBar1);
//创建工具栏上的下拉控件
int index = 0;
RECT rect;
//找到指定的工具项
/*while(m_wndToolBar.GetItemID(index)!=ID_TOOL_ZOOM)
index++;
m_wndToolBar.SetButtonInfo(index,ID_TOOL_ZOOM,TBBS_SEPARATOR,350);
m_wndToolBar.GetItemRect(index,&rect);
rect.bottom+=100;//如果不加上这语句,在win200下运行时组合筐会有问题
if(!m_wndToolBar.m_wndComboBox.Create(WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,
rect,(CWnd*)&m_wndToolBar,ID_TOOL_ZOOM))
{
TRACE0(" Fail to m_wndToolBar.m_wndComboBox.Create()..\n ");
return FALSE;
}
m_wndToolBar.m_wndComboBox.SetItemHeight(0,15);
m_wndToolBar.m_wndComboBox.SetFont(p_ParentFont,TRUE);
m_wndToolBar.m_wndComboBox.ShowWindow(SW_SHOW);
*/
while(m_wndBar1.GetItemID(index)!=ID_TOOL_ZOOM)
index++;
m_wndBar1.SetButtonInfo(index,ID_TOOL_ZOOM,TBBS_SEPARATOR,350);
m_wndBar1.GetItemRect(index,&rect);
rect.bottom+=100;//如果不加上这语句,在win200下运行时组合筐会有问题
if(!m_wndBar1.m_wndComboBox.Create(WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,
rect,(CWnd*)&m_wndBar1,ID_TOOL_ZOOM))
{
TRACE0(" Fail to m_wndBar1.m_wndComboBox.Create()..\n ");
return FALSE;
}
m_wndBar1.m_wndComboBox.SetItemHeight(0,15);
m_wndBar1.m_wndComboBox.SetFont(p_ParentFont,TRUE);
m_wndBar1.m_wndComboBox.ShowWindow(SW_SHOW);
rect.top+=5;
rect.left+=130;
rect.bottom=rect.top+10;
rect.right=rect.left+120;
pcap_if_t* alldevs,*d;
char errbuf[PCAP_ERRBUF_SIZE];
if(pcap_findalldevs(&alldevs,errbuf)==-1)
{
TRACE0("pcap_findalldevs Error!\n");
return false;
}
//m_wndToolBar.m_wndComboBox.AddString("选择适配器!");
for(d=alldevs;d;d=d->next)
{
if(d->description)
{
m_wndBar1.m_wndComboBox.AddString(d->description);
}
}
m_wndBar1.m_wndComboBox.SetCurSel(0);
CTime t=CTime::GetCurrentTime();
CString str=t.Format("%H:%M:%S");
CClientDC dc(this);
CSize sz=dc.GetTextExtent(str);
int sds=0;
sds=m_wndStatusBar.CommandToIndex(IDS_TIMER);
m_wndStatusBar.SetPaneInfo(sds,IDS_TIMER,SBPS_NORMAL,sz.cx);
m_wndStatusBar.SetPaneText(1,str);
SetTimer(1,1000,NULL);
// CG: The following line was added by the Splash Screen component. CSplashWnd::ShowSplashScreen(this);
NOTIFYICONDATA tnd;
tnd.cbSize=sizeof(NOTIFYICONDATA);
tnd.hWnd=this->m_hWnd;
tnd.uID=IDR_MAINFRAME;
tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage=MYWM_NOTIFYICON;
tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
strcpy(tnd.szTip,"网络入侵检测系统");
::Shell_NotifyIcon(NIM_ADD,&tnd);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
//cs.style=WS_POPUP;
//cs.dwExStyle|=WS_EX_TOOLWINDOW;
cs.cx=1024;
cs.cy=768;
cs.style&=~FWS_ADDTOTITLE;
cs.lpszName="网络入侵检测系统";
//cs.style&=~FWS_ADDTOTITLE;
//cs.lpszName="网络入侵检测系统";
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
//显示左边的控制 条
void CMainFrame::OnButtonshowleft()
{
// TODO: Add your command handler code here
ShowControlBar(&m_wndMyBarLeft,!m_wndMyBarLeft.IsVisible(),FALSE);
}
//显示下面的控制条
void CMainFrame::OnButtonshowbottom()
{
// TODO: Add your command handler code here
ShowControlBar(&m_wndMyBarBottom,!m_wndMyBarBottom.IsVisible(),FALSE);
}
void CMainFrame::OnUpdateButtonshowleft(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_wndMyBarLeft.IsVisible());
}
void CMainFrame::OnUpdateButtonshowbottom(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_wndMyBarBottom.IsVisible());
}
CEdit* CMainFrame::GetEdit()
{
return &m_wndEdit;
}
CTreeCtrl* CMainFrame::GetTree()
{
return &m_wndTree;
}
CListCtrl* CMainFrame::GetList()
{
return &m_wndList;
}
CComboBox* CMainFrame::GetComboBox()
{
CComboBox* p=&(m_wndBar1.m_wndComboBox);
return p;
}
void CMainFrame::AddToComboBox(CString str)
{
m_wndBar1.m_wndComboBox.AddString(str);
}
void CMainFrame::OnFileNew()
{
// TODO: Add your command handler code here
}
BOOL CMainFrame::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
return CFrameWnd::DestroyWindow();
}
//在关闭应用程序时首先做的事情
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
//获得文档指针
CIPControlDoc* pdoc=(CIPControlDoc*)this->GetActiveDocument();
while(pdoc->m_ThreadHandle!=NULL)
{
AfxMessageBox("请先停止捕获数据包!");
return;
}
//如果换成if,在包数据量大的时候会造成程序的死停
CFrameWnd::OnClose();
}
void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CFrameWnd::OnActivate(nState, pWndOther, bMinimized);
// TODO: Add your message handler code here
}
void CMainFrame::OnFileSave()
{
// TODO: Add your command handler code here
return;
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CTime t=CTime::GetCurrentTime();
CString str=t.Format("%H:%M:%S");
CClientDC dc(this);
CSize sz=dc.GetTextExtent(str);
int index=0;
index=m_wndStatusBar.CommandToIndex(IDS_TIMER);
m_wndStatusBar.SetPaneInfo(index,IDS_TIMER,SBPS_NORMAL,sz.cx);
m_wndStatusBar.SetPaneText(1,str);
CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::OnHelp()
{
// TODO: Add your command handler code here
LPCTSTR str="help.chm";
}
void CMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar==VK_RETURN)
{
//Onstart();
}
AfxMessageBox("aa");
CFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}
#include "Splash1.h"
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch(message)
{case MYWM_NOTIFYICON:
if(lParam==WM_LBUTTONDBLCLK)
{AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
}
else if(lParam==WM_RBUTTONDOWN)
{CMenu menu;
menu.LoadMenu(IDR_MENU);
CMenu* pMenu=menu.GetSubMenu(0);
CPoint pos;
GetCursorPos(&pos);
pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,pos.x,pos.y,AfxGetMainWnd());
pMenu->DeleteMenu(2,MF_BYPOSITION);
}
break;
case WM_SYSCOMMAND:
if(wParam==SC_MINIMIZE)
{AfxGetApp()->m_pMainWnd->ShowWindow(SW_HIDE);
return 0;
}
break;
}
return CFrameWnd::WindowProc(message, wParam, lParam);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -