XXXXDlg.cpp
上传用户:gzdongxi
上传日期:2007-07-05
资源大小:30k
文件大小:10k
- // XXXXDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "XXXX.h"
- #include "XXXXDlg.h"
- #include "TLHELP32.H"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- HWND hwnd;
- HWND IWANT;
- HWND m_hwndFind[100] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
- int m_num = 0 ;
- TCHAR m_store[MAX_PATH];
- TCHAR m_name[MAX_PATH];
- TCHAR m_strClass[MAX_PATH];
- TCHAR m_FilePath[MAX_PATH];
- TCHAR m_FileName[24];
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CXXXXDlg dialog
- CXXXXDlg::CXXXXDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CXXXXDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CXXXXDlg)
- m_fileName = _T("C:\Program Files\Tencent\QQ\QQ.exe");//作者的qq目录,你可以把隐藏窗口的代码去掉,自己在程序里设置
- online=false;
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CXXXXDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CXXXXDlg)
- DDX_Text(pDX, IDC_EDIT1, m_fileName);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CXXXXDlg, CDialog)
- //{{AFX_MSG_MAP(CXXXXDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- ON_WM_TIMER()
- ON_WM_SIZE()
- ON_MESSAGE(WM_HOTKEY, OnHotKey)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CXXXXDlg message handlers
- BOOL CXXXXDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 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
-
- RegisterHotKey(this->m_hWnd,1001,MOD_CONTROL|MOD_ALT,'z');
- RegisterHotKey(this->m_hWnd,1002,MOD_CONTROL|MOD_ALT,'Z');
- // TODO: Add extra initialization here
- CDialog::OnInitDialog();
- PostMessage(WM_SIZE,0,0);///这是增加的一句隐藏对话框,
- SetTimer(1,30000,NULL);//计时器开始工作,30秒
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CXXXXDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 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 CXXXXDlg::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 CXXXXDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CXXXXDlg::OnButton1() //枚举进程iD,通过对比枚举的窗口获得的程序ID,直接找到qq句柄,不管它有没有标题栏
- {
-
- DWORD pID=0;
- DWORD ProcessID[50];
- CString kkk[50];
- HANDLE SnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- PROCESSENTRY32* info=new PROCESSENTRY32;
- PROCESSENTRY32 ProcessInfo;//声明进程信息变量
- ProcessInfo.dwSize=sizeof(ProcessInfo);//设置ProcessInfo的大小
- BOOL Status=Process32First(SnapShot,&ProcessInfo);//返回系统中第一个进程的信息
-
- int m_nProcess=0;
- while(Status)
- {
- CString s,str1,str2;
- s.Format("%d",ProcessInfo.cntThreads);
- str1.Format("%s",ProcessInfo.szExeFile);
- str1=ProcessInfo.szExeFile;
- kkk[m_nProcess]=ProcessInfo.szExeFile;
- ProcessID[m_nProcess]=ProcessInfo.th32ProcessID;
- if(str1=="QQ.exe")//***.exe就是你要结束的进程的名称
- {
- ::EnumWindows(CXXXXDlg::EnumWindowsProc,NULL);
- for(int i = 0;i <=m_num;i++)
- {
- HWND m_wnd = m_hwndFind[i];
- ::GetWindowText(m_wnd,m_store,128);
- ::GetClassName(m_wnd,m_strClass,MAX_PATH-1);
- ::GetWindowThreadProcessId(m_wnd,&pID);
- if(ProcessID[m_nProcess]==pID)
- {
- IWANT=m_wnd;
- settext();
- }
- }
-
- }
- Status=Process32Next(SnapShot,&ProcessInfo);
- m_nProcess++;
- }
-
- }
- BOOL CXXXXDlg::EnumWindowsProc(HWND hWnd, LPARAM lParam)
- {
- //be sure the current window is visible
- if(::GetWindowLong(hWnd,GWL_STYLE)& WS_VISIBLE)
- {
- m_hwndFind[m_num] = hWnd;//record the HWND handle into array
- m_num++;//count start
- }
- return 1;
- }
- void CXXXXDlg::settext()
- {
- HWND hwndname = ::FindWindowEx( IWANT, NULL, "ComboBox", NULL );//查找ComboBox句柄
- if(hwndname==NULL)
- return;
- CString Message;
- Message="12447886";//号码
- if(::GetForegroundWindow()!=IWANT)
- ::SetForegroundWindow(IWANT);
-
- keybd_event(49,0,0,0); //按下1 因为没细致去研究,所以采用逐个输入密码的方式输入,请自己把密码转ASCI码
- keybd_event(49,0,2,0); //释放
- keybd_event(48,0,0,0); //按下0
- keybd_event(48,0,2,0); //释放
- keybd_event(49,0,0,0); //按下1
- keybd_event(49,0,2,0); //释放
- keybd_event(56,0,0,0); //
- keybd_event(56,0,2,0); //释放
-
- ::SetFocus(hwndname);//定位到号码框,QQ2004以后的密码edit框我定位不到,所以只能先这样
- //因为,在一台机器上登录过后,光标首先停在password框,所以就用keybd_event输入密码
- //然后定位到号码框,输入号码QQ2005,QQ2004测试通过,以前的版本更容易,可以直接定位密码框
- //自己用spy++找吧~~
-
- ::SendMessage(hwndname, WM_SETTEXT, Message.GetLength(), (LPARAM)Message.GetBuffer(Message.GetLength()));
- keybd_event(VK_RETURN,0,0,0); //按下回车
- keybd_event(VK_RETURN,0,2,0); //释放
-
- }
- void CXXXXDlg::OnButton2()
- {
- // TODO: Add your control notification handler code here
- CFileDialog OpenDlg(true);
- OpenDlg.m_ofn.lpstrFilter="QQ Files*.exe ";
- if(OpenDlg.DoModal()==IDOK){
- m_fileName=OpenDlg.GetPathName();
- UpdateData(false);
- }
- ShellExecute(0,NULL,m_fileName,NULL,NULL,SW_NORMAL);
- }
- void CXXXXDlg::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- OnButton3();
- CDialog::OnTimer(nIDEvent);
- }
- void CXXXXDlg::OnButton3()
- {
- SYSTEMTIME SysTime;
- CString StrCurTime,str;
- ::GetLocalTime(&SysTime);
- StrCurTime.Format("%d%d%d",SysTime.wHour,SysTime.wMinute,SysTime.wSecond);
- str=StrCurTime.Left(2);
- int x=atoi(str);
- if(x==23&&!online)//如果现在是11点
- {
- online=true;
- close();//关闭其他qq
- ::Sleep(200);
- ShellExecute(0,NULL,m_fileName,NULL,NULL,SW_NORMAL);
- ::Sleep(15000);//停止2秒,等待QQ正常运行
- OnButton1();
- }
- if(x>81&&online)//如果是早上八点多,qq开着
- {
- online=false;
- close();//关闭其他qq
- }
- }
- void CXXXXDlg::close()//枚举进程关闭qq程序,
- {
- DWORD ProcessID[50];
- CString kkk[50];
- HANDLE SnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- PROCESSENTRY32* info=new PROCESSENTRY32;
- PROCESSENTRY32 ProcessInfo;//????????
- ProcessInfo.dwSize=sizeof(ProcessInfo);//??ProcessInfo???
- //?????????????
- BOOL Status=Process32First(SnapShot,&ProcessInfo);
- int m_nProcess=0;
- while(Status)
- {
- CString s,str1,str2;
- s.Format("%d",ProcessInfo.cntThreads);
- str1.Format("%s",ProcessInfo.szExeFile);
- str1=ProcessInfo.szExeFile;
- kkk[m_nProcess]=ProcessInfo.szExeFile;
- ProcessID[m_nProcess]=ProcessInfo.th32ProcessID;
- if(str1=="QQ.exe")//***.exe????????????
- {
- HANDLE ProcessHandle;
- ProcessHandle=OpenProcess (PROCESS_ALL_ACCESS,FALSE,ProcessID[m_nProcess]);
- TerminateProcess(ProcessHandle,0);
- }
- Status=Process32Next(SnapShot,&ProcessInfo);
- m_nProcess++;
- }
- }
- void CXXXXDlg::OnSize(UINT nType, int cx, int cy) //隐藏对话框
- {
- //CDialog::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- ShowWindow(SW_HIDE); ///隐藏对话框
- }
- LRESULT CXXXXDlg::OnHotKey(WPARAM wParam, LPARAM lParam)
- {
- MessageBox("孙鹏程的QQ程序正常运行","QQ");//设置热键让自己方便看看程序是不是在运行
- return 1;
- }