memoryscanDlg.cpp
上传用户:leon2013
上传日期:2007-01-10
资源大小:186k
文件大小:4k
源码类别:

杀毒

开发平台:

Visual C++

  1. // memoryscanDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "memoryscan.h"
  5. #include "memoryscanDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMemoryscanDlg dialog
  13. CMemoryscanDlg::CMemoryscanDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CMemoryscanDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CMemoryscanDlg)
  17. //}}AFX_DATA_INIT
  18. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  19. }
  20. void CMemoryscanDlg::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. //{{AFX_DATA_MAP(CMemoryscanDlg)
  24. DDX_Control(pDX, IDOK, btnOk);
  25. DDX_Control(pDX, IDC_MEMSCANPERCENT, memscanpercent);
  26. DDX_Control(pDX, IDC_SCANPROGRESS, scanprogress);
  27. DDX_Control(pDX, IDC_SCANNED, scanned);
  28. DDX_Control(pDX, IDC_PROCESSPROGRESS, processprogress);
  29. DDX_Control(pDX, IDC_PROCESSNAME, processname);
  30. DDX_Control(pDX, IDC_MEMSCANNED, memscanned);
  31. DDX_Control(pDX, IDC_INFECTIONS, infections);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(CMemoryscanDlg, CDialog)
  35. //{{AFX_MSG_MAP(CMemoryscanDlg)
  36. ON_WM_PAINT()
  37. ON_WM_QUERYDRAGICON()
  38. ON_WM_TIMER()
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CMemoryscanDlg message handlers
  43. BOOL CMemoryscanDlg::OnInitDialog()
  44. {
  45. CDialog::OnInitDialog();
  46. SetIcon(m_hIcon, TRUE); // Set big icon
  47. SetIcon(m_hIcon, FALSE); // Set small icon
  48. processprogress.SetRange(0,100);
  49. Start();
  50. SetTimer(1,200,NULL);
  51. return TRUE;  // return TRUE  unless you set the focus to a control
  52. }
  53. // If you add a minimize button to your dialog, you will need the code below
  54. //  to draw the icon.  For MFC applications using the document/view model,
  55. //  this is automatically done for you by the framework.
  56. void CMemoryscanDlg::OnPaint() 
  57. {
  58. if (IsIconic())
  59. {
  60. CPaintDC dc(this); // device context for painting
  61. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  62. // Center icon in client rectangle
  63. int cxIcon = GetSystemMetrics(SM_CXICON);
  64. int cyIcon = GetSystemMetrics(SM_CYICON);
  65. CRect rect;
  66. GetClientRect(&rect);
  67. int x = (rect.Width() - cxIcon + 1) / 2;
  68. int y = (rect.Height() - cyIcon + 1) / 2;
  69. // Draw the icon
  70. dc.DrawIcon(x, y, m_hIcon);
  71. }
  72. else
  73. {
  74. CDialog::OnPaint();
  75. }
  76. }
  77. HCURSOR CMemoryscanDlg::OnQueryDragIcon()
  78. {
  79. return (HCURSOR) m_hIcon;
  80. }
  81. void CMemoryscanDlg::OnTimer(UINT nIDEvent) 
  82. {
  83. if (nIDEvent==1) {
  84. CString s;
  85. int brk;
  86. /* process name */
  87. s=CurrentProcessName();
  88. if((brk=s.ReverseFind('\'))!=-1) s=s.Mid(brk+1);
  89. s.MakeLower();
  90. processname.SetWindowText(" "+s);
  91. /* scanned */
  92. s.Format("%d of %d ", Scanned(), processes.size());
  93. scanned.SetWindowText(s);
  94. /* infections */
  95. s.Format("%d ", Infections());
  96. infections.SetWindowText(s);
  97. /* memory scanned */
  98. s.Format("%d MB ", CurrentProcessPosition()/1024/1024 );
  99. memscanned.SetWindowText(s);
  100. if (CurrentProcessSize()) {
  101. /* process memory scan progress */
  102. s.Format("%6.1f%% ", (double)CurrentProcessPosition()*100/CurrentProcessSize() );
  103. memscanpercent.SetWindowText(s);
  104. /* update progress ctrl */
  105. processprogress.SetPos( CurrentProcessPosition()*100/CurrentProcessSize() );
  106. }
  107. /* global scan progress */
  108. scanprogress.SetRange(0,processes.size());
  109. scanprogress.SetPos( Scanned() );
  110. if (!Running()) {
  111. KillTimer(1);
  112. processname.SetWindowText(" Scan complete!");
  113. btnOk.SetWindowText("Close");
  114. memscanned.SetWindowText("");
  115. memscanpercent.SetWindowText("");
  116. processprogress.SetPos( 0 );
  117. scanprogress.SetPos( 100 );
  118. }
  119. }
  120. CDialog::OnTimer(nIDEvent);
  121. }
  122. void CMemoryscanDlg::OnOK() 
  123. {
  124. /* stop scanning memory */
  125. if (Running()) Stop();
  126. CDialog::OnOK();
  127. }