MainFrm.cpp
上传用户:xuemeng126
上传日期:2022-07-05
资源大小:454k
文件大小:7k
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "BehaviorMon.h"
- #include "BehaviorMonView.h"
- #include "MainFrm.h"
- #include <afxdlgs.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(ID_MENUITEM_HOOK, OnMenuitemHook)
- ON_COMMAND(ID_MENUITEM_PROCESSNAME, OnMenuitemProcessname)
- ON_COMMAND(ID_TOOLBAR_BUTTON_CLEAR, OnToolbarButtonClear)
- ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
- ON_COMMAND(ID_MENUITEM_UNHOOK, OnMenuitemUnhook)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
-
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
-
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
-
- CToolTipCtrl tooltipctrl;
- CRect rect;
- CToolBarCtrl *toolbarctrl=(CToolBarCtrl*)&m_wndToolBar.GetToolBarCtrl();
- toolbarctrl->EnableButton(ID_TOOLBAR_BUTTON_CLEAR,TRUE);
- // tooltipctrl.Create(this, TTS_ALWAYSTIP);
- // m_wndToolBar.GetToolBarCtrl().GetItemRect(8, rect);
- // tooltipctrl.AddTool(&m_wndToolBar,"test", rect, ID_TOOLBAR_BUTTON_CLEAR);
- // tooltipctrl.Activate(TRUE);
- // toolbarctrl->SetToolTips(&tooltipctrl);
- // CToolTipCtrl* aa = toolbarctrl->GetToolTips()->;
- // aa->UpdateTipText("dkdkd",&m_wndToolBar,ID_TOOLBAR_BUTTON_CLEAR);
- // tooltipctrl.Create(this, TTS_ALWAYSTIP);
- // m_wndToolBar.GetToolBarCtrl().GetItemRect(8, rect);
- // tooltipctrl.AddTool(&m_wndToolBar,"test", rect, ID_TOOLBAR_BUTTON_CLEAR);
- // tooltipctrl.UpdateTipText("test",&m_wndToolBar,ID_TOOLBAR_BUTTON_CLEAR);
- // tooltipctrl.Activate(TRUE);
- //
- // toolbarctrl->EnableToolTips();
- // toolbarctrl->SetToolTips(&tooltipctrl);
- //设置标题
- //SendMessage(WM_SYSCOMMAND, SC_ZOOM, 0);
- this->SetWindowText("程序行为监控器 BehaviorMon http://hi.baidu.com/shineastdh");
-
- 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 &= ~FWS_ADDTOTITLE;
- cs.cx = 800;
- cs.cy = 600;
- 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
- BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- // TODO: Add your specialized code here and/or call the base class
- return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
- }
- void CMainFrame::OnMenuitemHook()
- {
- // TODO: Add your command handler code here
- CFrameWnd * pFrameWnd=(CFrameWnd*)AfxGetMainWnd();
- CBehaviorMonView * pView=(CBehaviorMonView *)pFrameWnd->GetActiveFrame()->GetActiveView();
- pView->OnButtonHook();
- }
- void CMainFrame::OnMenuitemUnhook()
- {
- // TODO: Add your command handler code here
- CFrameWnd * pFrameWnd=(CFrameWnd*)AfxGetMainWnd();
- CBehaviorMonView * pView=(CBehaviorMonView *)pFrameWnd->GetActiveFrame()->GetActiveView();
- pView->OnButtonUnhook();
- }
- CString CMainFrame::ShowSelectDirectoryDlg(const CString & strDlgTitle)
- {
- char szDir[MAX_PATH];
- BROWSEINFO bi;
- ITEMIDLIST *pidl;
-
- bi.hwndOwner = this->m_hWnd;
- bi.pidlRoot = NULL;
- bi.pszDisplayName = szDir;
- bi.lpszTitle = strDlgTitle;
- bi.ulFlags = BIF_RETURNONLYFSDIRS;
- bi.lpfn = NULL;
- bi.lParam = 0;
- bi.iImage = 0;
-
- pidl = SHBrowseForFolder(&bi);
- if(pidl == NULL)
- return _T("");
- if(!SHGetPathFromIDList(pidl, szDir))
- return _T("");
- return CString(szDir);
- }
- void CMainFrame::OnMenuitemProcessname()
- {
- //ShowSelectDirectoryDlg("SSS");
- /*CFileDialog(
- BOOL bOpenFileDialog,
- LPCTSTR lpszDefExt = NULL,
- LPCTSTR lpszFileName = NULL,
- DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- LPCTSTR lpszFilter = NULL,
- CWnd* pParentWnd = NULL );*/
- static char BASED_CODE szFilter[] = "Exe Files (*.exe)|*.exe|All Files (*.*)|*.*||";
- CFileDialog *dialog_processname= new CFileDialog(TRUE,
- NULL,
- NULL,
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- szFilter,
- NULL);
- dialog_processname->DoModal();
- CString filename=dialog_processname->GetPathName();
- if(filename.GetLength()==0)
- {
- AfxMessageBox("请选定要监控的文件!n");
- OnMenuitemProcessname();
- }
- else
- AfxMessageBox("选定文件将被行为监控!n"+filename);
- //得到选择的exe文件名后,告诉驱动来监控该程序的行为
- CFrameWnd * pFrameWnd=(CFrameWnd*)AfxGetMainWnd();
- CBehaviorMonView * pView=(CBehaviorMonView *)pFrameWnd->GetActiveFrame()->GetActiveView();
- pView->tell_driver_processname(filename);
- }
- void CMainFrame::OnToolbarButtonClear()
- {
- // TODO: Add your command handler code here
- CFrameWnd * pFrameWnd=(CFrameWnd*)AfxGetMainWnd();
- CBehaviorMonView * pView=(CBehaviorMonView *)pFrameWnd->GetActiveFrame()->GetActiveView();
- pView->clear_list();
- }
- void CMainFrame::OnFileOpen()
- {
- // TODO: Add your command handler code here
- static char BASED_CODE szFilter[] = "Exe Files (*.exe)|*.exe|All Files (*.*)|*.*||";
- CFileDialog *dialog_processname= new CFileDialog(TRUE,
- NULL,
- NULL,
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- szFilter,
- NULL);
- dialog_processname->DoModal();
- CString filename=dialog_processname->GetPathName();
- if(filename.GetLength()==0)
- {
- AfxMessageBox("请选定要监控的文件!n");
- OnMenuitemProcessname();
- }
- else
- AfxMessageBox("选定文件将被行为监控!n"+filename);
- //得到选择的exe文件名后,告诉驱动来监控该程序的行为
- CFrameWnd * pFrameWnd=(CFrameWnd*)AfxGetMainWnd();
- CBehaviorMonView * pView=(CBehaviorMonView *)pFrameWnd->GetActiveFrame()->GetActiveView();
- pView->tell_driver_processname(filename);
- }