📄 tdctradedlg.cpp
字号:
// tdctradeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "tdctrade.h"
#include "tdctradeDlg.h"
#include "ODBCINST.H"
//包含odbc注册数据缘的头文件
#include "afxinet.h" //包含网络的类
#include <afxmt.h> //包含多线程的类
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HINSTANCE gLibSample=NULL;
//第二个变量ShowMe是指向DLL 库中ShowMe()函数的指针
typedef void(* SHOWME)(CString message1);
SHOWME ShowMe;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CTdctradeDlg dialog
CTdctradeDlg::CTdctradeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTdctradeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTdctradeDlg)
// 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 CTdctradeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTdctradeDlg)
DDX_Control(pDX, IDC_EDIT_message, m_edit_message);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTdctradeDlg, CDialog)
//{{AFX_MSG_MAP(CTdctradeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_category2, OnBUTTONcategory2)
ON_BN_CLICKED(IDC_BUTTON_run, OnBUTTONrun)
ON_BN_CLICKED(IDC_BUTTON_clear, OnBUTTONclear)
ON_BN_CLICKED(IDC_BUTTON_run_message, OnBUTTONrunmessage)
ON_BN_CLICKED(IDC_BUTTON_get_friend, OnBUTTONgetfriend)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTdctradeDlg message handlers
BOOL CTdctradeDlg::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
/************************************************/
if(!reg_access_odbc())
MessageBox("reg odbc error!");
/************************************************/
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CTdctradeDlg::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 CTdctradeDlg::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 CTdctradeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int CTdctradeDlg::reg_access_odbc()
{
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);//得到程序的路径
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind('\\');
sPath=sPath.Left(nPos);
CString lpszFile=sPath+"\\xiaonei.mdb"; //得到程序目录下的数据库的完整路径
char* szDesc;
int mlen;
szDesc=new char[256];
sprintf(szDesc,"DSN=%s? DESCRIPTION=TOC support source? DBQ=%s? FIL=MicrosoftAccess? DEFAULTDIR=%s??","xiaonei",lpszFile,sPath);
//形成一个SQLConfigDataSource函数参数串结构
mlen = strlen(szDesc);
for (int i=0; i<mlen;i++)
if(szDesc[i]=='?')
szDesc[i] = '\0'; //替换上面串的?为\0,形成一个完整的串
if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))//注册数据库
return 0;
try
{
m_database.Open("xiaonei");
//数据库连接对象连接到mysql数据库
m_recordset.m_pDatabase=&m_database;
//数据集操作对象关联到数据库连接对象
}
catch(...)
{
return 0;
}
//数据库连接对象
return 1;
}
//DEL BOOL CTdctradeDlg::GetWebPage(const CString strUrl, CString &strPageSource)
//DEL {
//DEL
//DEL CString strSentence;
//DEL CInternetSession sess;
//DEL CHttpFile* fileGet;
//DEL strPageSource=_T("");
//DEL try
//DEL {
//DEL fileGet=(CHttpFile*)sess.OpenURL(strUrl);
//DEL }
//DEL catch(...)
//DEL {
//DEL fileGet = 0;
//DEL sess.Close();
//DEL return FALSE;
//DEL }
//DEL
//DEL if(fileGet != NULL)
//DEL {
//DEL DWORD dwStatus;
//DEL DWORD dwBuffLen = sizeof(dwStatus);
//DEL BOOL bSuccess = fileGet->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwBuffLen);
//DEL
//DEL if(bSuccess && dwStatus>= 200&& dwStatus<300)
//DEL {
//DEL while(fileGet->ReadString(strSentence))
//DEL {
//DEL strPageSource += strSentence;
//DEL }
//DEL }
//DEL else
//DEL {
//DEL strSentence.Format("打开网页文件出错,错误码:%d", dwStatus);
//DEL AfxMessageBox(strSentence);
//DEL fileGet->Close();
//DEL sess.Close();
//DEL delete fileGet;
//DEL return FALSE;
//DEL }
//DEL fileGet->Close();
//DEL delete fileGet;
//DEL }
//DEL else
//DEL {
//DEL sess.Close();
//DEL return FALSE;
//DEL }
//DEL
//DEL sess.Close();
//DEL return TRUE;
//DEL
//DEL
//DEL }
//DEL void CTdctradeDlg::OnBUTTONcategory1()
//DEL {
//DEL CString url, strPageSource;
//DEL CString category_name1, category_url1;
//DEL url="http://sourcing.tdctrade.com/cgi-bin/hkei.dll/Jsp/hkei/Template_TopStandardCatalog.cmd?CategoryOID=0&vertical=ALL&isRegionHome=1";
//DEL
//DEL CString url_left,url_right;
//DEL
//DEL url_left="http://sourcing.tdctrade.com/cgi-bin/hkei.dll/Jsp/hkei/Template_StandardCatalog.cmd?CategoryOID=";
//DEL url_right="&vertical=ALL";
//DEL
//DEL
//DEL if(GetWebPage(url, strPageSource))
//DEL {
//DEL
//DEL int k1,k2,k3,k4,k5;
//DEL CString category_name1, category_url1;
//DEL k1=k2=k3=k4=k5=0;
//DEL k1=strPageSource.Find("Template_StandardCatalog",k5+1);
//DEL k2=strPageSource.Find("3D",k1+1);
//DEL k3=strPageSource.Find("%",k2+1);
//DEL k4=strPageSource.Find(">",k3+1);
//DEL k5=strPageSource.Find("<",k4+1);
//DEL while(k1!=-1&&k2!=-1&&k3!=-1&&k4!=-1&&k5!=-1)
//DEL {
//DEL
//DEL category_url1=strPageSource.Mid(k2+2,k3-k2-2);
//DEL category_name1=strPageSource.Mid(k4+1,k5-k4-1);
//DEL category_name1.TrimLeft();
//DEL category_name1.TrimRight();
//DEL category_url1=url_left+category_url1+url_right;
//DEL try
//DEL {
//DEL CString strSQL;
//DEL strSQL.Format("insert into category_1(category_name1,category_url1) values('%s', '%s')",category_name1,category_url1);
//DEL m_database.ExecuteSQL(strSQL);
//DEL }
//DEL catch(...)
//DEL {
//DEL MessageBox("error!");
//DEL return ;
//DEL }
//DEL
//DEL k1=strPageSource.Find("Template_StandardCatalog",k5+1);
//DEL k2=strPageSource.Find("3D",k1+1);
//DEL k3=strPageSource.Find("%",k2+1);
//DEL k4=strPageSource.Find(">",k3+1);
//DEL k5=strPageSource.Find("<",k4+1);
//DEL
//DEL
//DEL
//DEL }
//DEL
//DEL
//DEL }
//DEL
//DEL
//DEL }
void CTdctradeDlg::OnBUTTONcategory2()
{
//要添加的代码如下
if(gLibSample!=NULL)
{
MessageBox("The Sample.DLL has already been load.");
return;
}
//装载Sample.dll,未加路径,将在三个默认路径中寻找
gLibSample=LoadLibrary("sample.dll");
//返回DLL中ShowMe()函数的地址
ShowMe=(SHOWME)GetProcAddress(gLibSample,"ShowMe");
//代码添加完毕
CString strPageSource;
CString url_1,url;
begin:
try
{
if(m_recordset.IsOpen())
m_recordset.Close();
//如果原来打开了,就先关闭,这样就可以打开多次
CString strsql;
strsql.Format("SELECT * FROM student where over='0'");
m_recordset.Open(CRecordset::forwardOnly,strsql);
CString strPageSource;
if(!m_recordset.IsEOF())
//循环读取
{
m_recordset.GetFieldValue("url",url_1);
ShellExecute(0, _T("open"), url_1, NULL, NULL, SW_SHOWMAXIMIZED);
Sleep(5000);
ShowMe(strPageSource);
int k1,k2,k3;
k1=k2=k3=0;
k1=strPageSource.Find("personName",k3+1);
k2=strPageSource.Find("=",k1+1);
k3=strPageSource.Find(">",k2+1);
while(k1!=-1&&k2!=-1&&k3!=-1)
{
url=strPageSource.Mid(k2+2,k3-k2-3);
try
{
CString strSQL;
strSQL.Format("insert into student(url,over) values('%s', '0')",url);
m_database.ExecuteSQL(strSQL);
}
catch(...)
{
;
}
k1=strPageSource.Find("personName",k3+1);
k2=strPageSource.Find("=",k1+1);
k3=strPageSource.Find(">",k2+1);
}
try
{
CString strSQL;
strSQL.Format("update student set over='1' where url='%s' ",url_1);
m_database.ExecuteSQL(strSQL);
}
catch(...)
{
;
}
}
}
catch(...)
{
return ;
}
goto begin;
MessageBox("over!");
}
void CTdctradeDlg::OnBUTTONrun()
{
CString url;
try
{
if(m_recordset.IsOpen())
m_recordset.Close();
//如果原来打开了,就先关闭,这样就可以打开多次
CString strsql;
strsql.Format("SELECT * FROM student where over='0'");
m_recordset.Open(CRecordset::forwardOnly,strsql);
CString strPageSource;
while(!m_recordset.IsEOF())
//循环读取
{
m_recordset.GetFieldValue("url",url);
ShellExecute(0, _T("open"), url, NULL, NULL, SW_SHOWMAXIMIZED);
Sleep(1000);
try
{
CString strSQL;
strSQL.Format("update student set over='1' where url='%s' ",url);
m_database.ExecuteSQL(strSQL);
}
catch(...)
{
;
}
m_recordset.MoveNext();
}
}
catch(...)
{
return ;
}
MessageBox("over!");
}
void CTdctradeDlg::OnBUTTONclear()
{
try
{
CString strSQL;
strSQL.Format("update student set over='0' ");
m_database.ExecuteSQL(strSQL);
}
catch(...)
{
;
}
}
void CTdctradeDlg::OnBUTTONrunmessage()
{
CString message;
m_edit_message.GetWindowText(message);
//要添加的代码如下
if(gLibSample!=NULL)
{
MessageBox("The Sample.DLL has already been load.");
return;
}
//装载Sample.dll,未加路径,将在三个默认路径中寻找
gLibSample=LoadLibrary("sample.dll");
//返回DLL中ShowMe()函数的地址
ShowMe=(SHOWME)GetProcAddress(gLibSample,"ShowMe");
//代码添加完毕
CString url;
try
{
if(m_recordset.IsOpen())
m_recordset.Close();
//如果原来打开了,就先关闭,这样就可以打开多次
CString strsql;
strsql.Format("SELECT * FROM student where over='0'");
m_recordset.Open(CRecordset::forwardOnly,strsql);
CString strPageSource;
while(!m_recordset.IsEOF())
//循环读取
{
m_recordset.GetFieldValue("url",url);
ShellExecute(0, _T("open"), url, NULL, NULL, SW_SHOWMAXIMIZED);
Sleep(6000);
ShowMe(message);
Sleep(6000);
try
{
CString strSQL;
strSQL.Format("update student set over='1' where url='%s' ",url);
m_database.ExecuteSQL(strSQL);
}
catch(...)
{
;
}
m_recordset.MoveNext();
}
}
catch(...)
{
return ;
}
MessageBox("over!");
}
void CTdctradeDlg::OnBUTTONgetfriend()
{
CString url;
try
{
if(m_recordset.IsOpen())
m_recordset.Close();
//如果原来打开了,就先关闭,这样就可以打开多次
CString strsql;
strsql.Format("SELECT * FROM student where over='0'");
m_recordset.Open(CRecordset::forwardOnly,strsql);
CString strPageSource;
while(!m_recordset.IsEOF())
//循环读取
{
m_recordset.GetFieldValue("url",url);
url.Replace("getuser","RequestFriend");
ShellExecute(0, _T("open"), url, NULL, NULL, SW_SHOWMAXIMIZED);
Sleep(1000);
try
{
CString strSQL;
strSQL.Format("update student set over='1' where url='%s' ",url);
m_database.ExecuteSQL(strSQL);
}
catch(...)
{
;
}
m_recordset.MoveNext();
}
}
catch(...)
{
return ;
}
MessageBox("over!");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -