www.pudn.com > ProcessProtect.rar > testprocessprotectDlg.cpp
// testprocessprotectDlg.cpp : implementation file
//
#include "stdafx.h"
#include "testprocessprotect.h"
#include "testprocessprotectDlg.h"
#include "ProcessProtect.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestprocessprotectDlg dialog
CTestprocessprotectDlg::CTestprocessprotectDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestprocessprotectDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestprocessprotectDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestprocessprotectDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestprocessprotectDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestprocessprotectDlg, CDialog)
//{{AFX_MSG_MAP(CTestprocessprotectDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_RELEASE, OnButtonRelease)
ON_BN_CLICKED(IDC_BUTTON_INIT, OnButtonInit)
ON_BN_CLICKED(IDC_BUTTON_ADD_PROTECT, OnButtonAddProtect)
ON_BN_CLICKED(IDC_BUTTON_REMOVE_PROTECT, OnButtonRemoveProtect)
ON_BN_CLICKED(IDC_BUTTON_LAST_ERROR, OnButtonLastError)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestprocessprotectDlg message handlers
BOOL CTestprocessprotectDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CTestprocessprotectDlg::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 CTestprocessprotectDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestprocessprotectDlg::OnButtonInit()
{
if(!ProcessProtect_Init())
{
MessageBox("初始化进程保护模块失败") ;
}
}
void CTestprocessprotectDlg::OnButtonRelease()
{
ProcessProtect_Release() ;
return ;
}
void CTestprocessprotectDlg::OnButtonAddProtect()
{
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1) ;
CString strProcessId ;
pEdit->GetWindowText(strProcessId) ;
DWORD dwProcessId = ::atoi(strProcessId.GetBuffer(0)) ;
m_userhandle = ProcessProtect_AddProcessId(dwProcessId) ;
if(m_userhandle == (HANDLE)-1)
{
MessageBox("添加需要保护的进程ID失败。") ;
}
return ;
}
void CTestprocessprotectDlg::OnButtonRemoveProtect()
{
if(!ProcessProtect_RemoveProecessId(m_userhandle))
{
MessageBox("没有要删除的进程保护ID") ;
}
}
void CTestprocessprotectDlg::OnButtonLastError()
{
CString strLastError ;
DWORD dwLastError = ProcessProtect_GetLastError() ;
switch(dwLastError)
{
case 0:
strLastError = "没有错误" ;
break ;
case PROCESSPROTECTE_INITIALIZE_FAILS:
strLastError = "进程保护模块初始化失败" ;
break ;
case PROCESSPROTECTE_EXSITING_PROCESSID:
strLastError = "要加入的保护进程ID已添加" ;
break ;
case PROCESSPROTECTE_PROTECTING_QUEUE_FULL:
strLastError = "进程保护队列已满,不能加入新的进程ID" ;
break ;
case PROCESSPROTECTE_NOT_FOUND_PROCESSID:
strLastError = "找不到指定的进程ID" ;
break ;
case PROCESSPROTECTE_INVALID_PROCESSID:
strLastError = "传入的进程ID无效" ;
break ;
case PROCESSPROTECTE_OUTOF_MEMORY:
strLastError = "内存不够" ;
break ;
case PROCESSPROTECTE_INITIALIZED:
strLastError = "保护进程模块已初始化" ;
break ;
case PROCESSPROTECTE_OWNER_PROCESSID:
strLastError = "要添加的保护进程ID是自身进程" ;
break ;
default:
strLastError = "未知错误" ;
break ;
}
MessageBox(strLastError) ;
}
#pragma comment(linker,"/export:getvalue=_getvalue@4")
extern "C" int __stdcall getvalue(int a)
{
return a ;
}