www.gusucode.com > VC++实现QQ自动登陆器源程序-源码程序 > VC++实现QQ自动登陆器源程序-源码程序\code\QQLoginDlg.cpp

    //Download by http://www.NewXing.com
// QQLoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "QQLogin.h"
#include "QQLoginDlg.h"
#include "GetHash.h"
#include "AddNum.h"
#include "Lregedit.h"
#include "Set.h"
#include  <io.h>
#include <string>
#include <queue>

using namespace std;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CQQLoginDlg dialog

CQQLoginDlg::CQQLoginDlg(CWnd* pParent /*=NULL*/)
: CDialog(CQQLoginDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CQQLoginDlg)
	// 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 CQQLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQQLoginDlg)
	DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CQQLoginDlg, CDialog)
//{{AFX_MSG_MAP(CQQLoginDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_ABOUT, OnButtonAbout)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_MESSAGE(QQ_ADDNUM,OnAddNum)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
ON_BN_CLICKED(IDC_BUTTON_SET, OnButtonSet)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQQLoginDlg message handlers

BOOL CQQLoginDlg::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
	
	// TODO: Add extra initialization here
	m_ListCtrl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
	m_ListCtrl.InsertColumn(0,"QQ号码",LVCFMT_CENTER,70);
	m_ListCtrl.InsertColumn(1,"状态",LVCFMT_CENTER,40);
	m_ListCtrl.InsertColumn(2,"登陆日期",LVCFMT_CENTER,90);
	
	m_ListCtrl.SetExtendedStyle(m_ListCtrl.GetExtendedStyle() | 
		LVS_EX_CHECKBOXES |
		LVS_EX_FULLROWSELECT);
	
	InitList();
	

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CQQLoginDlg::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 CQQLoginDlg::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 CQQLoginDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CQQLoginDlg::OnButtonAbout() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();
}

void CQQLoginDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	
	Lregedit regedit;
	string strPath=regedit.ReadValue
		(
		HKEY_LOCAL_MACHINE,
		"SOFTWARE\\TENCENT\\PLATFORM_TYPE_LIST\\1",
		"TypePath"
		);
	
	string time=GetTime();
	for(int i=0;i<m_ListCtrl.GetItemCount();i++)
	{
		if(m_ListCtrl.GetCheck(i))
		{
			ShellExecute(NULL, "open",strPath.c_str(),(char *) dqLine[i].c_str(), NULL, SW_SHOWNORMAL);
			m_ListCtrl.SetItemText(i,2,time.c_str());
		}
		
		Sleep(1000);
	}
	
	string strClose=regedit.ReadValue
		(
		HKEY_LOCAL_MACHINE,
		"SOFTWARE\\TENCENT\\PLATFORM_TYPE_LIST\\1",
		"close"
		);
	if(strClose=="Y")
		PostMessage(WM_QUIT,0,0);
	//    
	//	CDialog::OnOK();
	
}


void CQQLoginDlg::OnButtonAdd() 
{
	// TODO: Add your control notification handler code here
	CAddNum addNum;
	addNum.DoModal();
}

bool CQQLoginDlg::InitList()
{
	//取QQ信息文件全路径
	dqLine.clear();
	
	char AppName[255]={0};
	::GetModuleFileName(NULL,AppName,255);
	string strQQInfoFile=AppName;
	strQQInfoFile=strQQInfoFile.substr(0,strQQInfoFile.find_last_of("\\")+1);
	strQQInfoFile+="QQInfo.dat";
	
	//文件是否存在
	if((_access(strQQInfoFile.c_str(),0)) == -1 )
		return false;
	
	
	int BufSize=1024*1024; // 1M
	char* FileBuf=new char[BufSize];
	memset(FileBuf,0,BufSize);
	FILE* pFile=fopen(strQQInfoFile.c_str(),"rb");
	if(pFile==NULL) return false;
	fread(FileBuf,1,BufSize,pFile);
	string strFileBuf=FileBuf;
	fclose(pFile);
	delete[] FileBuf;
	
	
	string strLink="";
	for(int i=0;i<strFileBuf.length();i++)
	{
		strLink+=strFileBuf[i];
		int Pos=strLink.find("\r\n");
		if(Pos!=-1)
		{
			string strTmp=strLink.substr(0,Pos);
			if(!strTmp.empty())
				dqLine.push_back(strTmp);
			strLink="";
		}
	}
	
	m_ListCtrl.DeleteAllItems();
	for(i=0;i<dqLine.size();i++)
	{
		
		string QQNum=dqLine[i].substr(13,dqLine[i].find_first_of("PW")-15);
		m_ListCtrl.InsertItem(i,QQNum.c_str());
		
		string QQIsHide=dqLine[i].substr(dqLine[i].size()-2,dqLine[i].size());
		if(QQIsHide=="41")
			m_ListCtrl.SetItemText(i,1,"正常");
		else
			m_ListCtrl.SetItemText(i,1,"隐身");
		
	}

	Lregedit reg;
	string str,value;
	for(i=0;i<m_ListCtrl.GetItemCount();i++)
	{
		str=m_ListCtrl.GetItemText( i, 0);

		value=reg.ReadValue(HKEY_LOCAL_MACHINE,"SOFTWARE\\TENCENT\\PLATFORM_TYPE_LIST\\1",str.c_str());
		if(value[0]=='Y')
		{
			m_ListCtrl.SetCheck(i);
			value=value.substr(1,value.length()+1);
			m_ListCtrl.SetItemText(i,2,value.c_str());
		}
		m_ListCtrl.SetItemText(i,2,value.c_str());
		
	}
	
	Lregedit regedit;
	string strAutoLogin=regedit.ReadValue
		(
		HKEY_LOCAL_MACHINE,
		"SOFTWARE\\TENCENT\\PLATFORM_TYPE_LIST\\1",
		"autoLogin"
		);
	if(strAutoLogin=="Y")
	{
		OnOK();
	}
	
	


	return true;
}

LRESULT CQQLoginDlg::OnAddNum(LPARAM lParam, WPARAM wParam)
{
	InitList();
	return 0;
}

void CQQLoginDlg::OnButtonDel() 
{
	// TODO: Add your control notification handler code here
	char AppName[255]={0};
	::GetModuleFileName(NULL,AppName,255);
	string strQQInfoFile=AppName;
	strQQInfoFile=strQQInfoFile.substr(0,strQQInfoFile.find_last_of("\\")+1);
	strQQInfoFile+="QQInfo.dat";
	
	FILE* pFile=fopen(strQQInfoFile.c_str(),"wb");
	
	for(int i=0;i<m_ListCtrl.GetItemCount();i++)
	{
		if(!m_ListCtrl.GetCheck(i))
			
			fwrite(dqLine[i].c_str(),1,dqLine[i].length(),pFile);
		fclose(pFile);
		
	}
	
	InitList();
}

void CQQLoginDlg::OnButtonSet() 
{
	// TODO: Add your control notification handler code here
	CSet setDlg;
	setDlg.DoModal();
}



void CQQLoginDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	Lregedit reg;
	
	
	for(int i=0;i<m_ListCtrl.GetItemCount();i++)
	{
		string str,date;
		
		str=m_ListCtrl.GetItemText( i, 0);
		
		date=m_ListCtrl.GetItemText(i,2);
		
		if(m_ListCtrl.GetCheck(i))
		{
			date='Y'+date;
			reg.SetValue(HKEY_LOCAL_MACHINE,"SOFTWARE\\TENCENT\\PLATFORM_TYPE_LIST\\1",str.c_str(),date.c_str());
		}
		else
		{
			
			reg.SetValue(HKEY_LOCAL_MACHINE,"SOFTWARE\\TENCENT\\PLATFORM_TYPE_LIST\\1",str.c_str(),date.c_str());
			
		}
	}
	// TODO: Add your message handler code here
	
}

string CQQLoginDlg::GetTime()
{
	CTime time=CTime::GetCurrentTime();
	
	CString GetTime;
	GetTime.Format("%d年%d月%d日",time.GetYear(),time.GetMonth(),time.GetDay());
	
	return GetTime;
	
}