unicodeDlg.cpp
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:13k
源码类别:
游戏
开发平台:
Visual C++
- // unicodeDlg.cpp : implementation file
- //
- #include "stdAfx.h"
- #include "unicode.h"
- #include "unicodeDlg.h"
- #include "ClientSockThread.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //extern UINT ClientSocketThreadProc(LPVOID);
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- CHyperLink m_sUrl;
- // 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)
- virtual BOOL OnInitDialog();
- //}}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)
- // DDX_Control(pDX, IDC_STATIC1, m_sUrl);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CUnicodeDlg dialog
- //extern HWND hwnd;
- CUnicodeDlg::CUnicodeDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CUnicodeDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CUnicodeDlg)
- m_startip = _T("127.0.0.1");
- m_endip = _T("127.0.0.1");
- m_pDaodb=new CDaoDatabase;
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CUnicodeDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CUnicodeDlg)
- // DDX_Control(pDX, IDC_RESULT, m_result);
- DDX_Control(pDX, IDC_ANIMATE1, m_ani1);
- DDX_Text(pDX, IDC_EDIT1, m_startip);
- DDX_Text(pDX, IDC_EDIT2, m_endip);
- DDX_Control(pDX, IDC_STATIC1, m_stcURL);
- DDX_Control(pDX, IDC_STATIC2, m_stcURL1);
- DDX_Control(pDX, IDC_EDIT1, m_Edit1);
- DDX_Control(pDX, IDC_EDIT2, m_Edit2);
- DDX_Control(pDX, IDOK, btn1);
- DDX_Control(pDX, IDOK2, btn2);
- DDX_Control(pDX, IDCANCEL, btn3);
- DDX_Control(pDX, IDCLEAR, btn4);
- DDX_Control(pDX, IDC_RESULT, m_result);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CUnicodeDlg, CDialog)
- //{{AFX_MSG_MAP(CUnicodeDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
- ON_BN_CLICKED(IDOK2, OnStop)
- ON_BN_CLICKED(IDCLEAR, OnClear)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CUnicodeDlg message handlers
- BOOL CUnicodeDlg::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
- WSADATA wsd;
- WORD wWinSockVer;
- wWinSockVer=MAKEWORD(2,0);
- int err=WSAStartup(wWinSockVer, &wsd);
- if(err!=0)
- {
- AfxMessageBox("WINSOCK 版本无效!");
- return FALSE;
- }
- BYTE btLowVer=LOBYTE(wsd.wVersion);
- //如果SOCK的版本大于2.0
- if(LOBYTE(wsd.wVersion)<2)
- {
- AfxMessageBox("WINSOCK 版本无效!");
- WSACleanup();
- return FALSE;
- }
- m_stcURL.SetWindowText("http://www.wantsoft.com");
- m_stcURL.SetAutoSize(FALSE);
- m_stcURL.SetURL("http://www.wantsoft.com");
- m_stcURL.SetColours(RGB(0,0,255), RGB(0,0,0) ,RGB(255,0,0));
- m_stcURL1.SetWindowText("mailto:wantsoft@163.com");
- m_stcURL1.SetAutoSize(FALSE);
- m_stcURL1.SetURL("mailto:wantsoft@163.com");
- m_stcURL1.SetColours(RGB(0,0,255), RGB(0,0,0) ,RGB(255,0,0));
- btn1.SetButtonText("开始扫描");
- btn2.SetButtonText("停止扫描");
- btn3.SetButtonText("退出程序");
- btn4.SetButtonText("清空列表");
- m_result.AddString(" 欢迎使用思想软件安全扫描工具");
- m_result.AddString("台湾自古以来是中国的领土");
- m_result.AddString("版权所有,翻版必究!Copyright (c) by suyu 2001");
- m_result.AddString("HTTP://WWW.WANTSOFT.COM");
- m_result.AddString("QQ:5778368");
- TCHAR szBuffer[256];
- DWORD dwSize=256;
- GetCurrentDirectory(dwSize,szBuffer);
- hwnd=GetSafeHwnd();
- CString strTemp;
- strTemp=szBuffer;
- m_ani1.Open(IDR_AVI);
- m_ani1.Stop();
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CUnicodeDlg::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 CUnicodeDlg::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 CUnicodeDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- BOOL CUnicodeDlg::ValidAddress(CString sAddress,
- UINT& n1,
- UINT& n2,
- UINT& n3,
- UINT& n4)
- {
- int nPos;
- CString sTemp=sAddress;
- n1=atoi(sTemp);
- nPos=sTemp.Find(".");
- if(nPos==-1) return false;
- sTemp=sTemp.Mid(nPos+1);
- n2=atoi(sTemp);
- nPos=sTemp.Find(".");
- if(nPos==-1) return false;
- sTemp=sTemp.Mid(nPos+1);
- n3=atoi(sTemp);
- nPos=sTemp.Find(".");
- if(nPos==-1) return false;
- sTemp=sTemp.Mid(nPos+1);
- n4=atoi(sTemp);
- if(n1<0 ||n1>255) return false;
- if(n2<0 ||n2>255) return false;
- if(n3<0 ||n3>255) return false;
- if(n4<0 ||n4>255) return false;
- return true;
- }
- void CUnicodeDlg::OnOK()
- {
- UINT nStartAddr1,nStartAddr2,nStartAddr3,nStartAddr4;
- UINT nEndAddr1,nEndAddr2,nEndAddr3,nEndAddr4;
- UpdateData(true);
- if (!ValidAddress(m_startip,
- nStartAddr1,
- nStartAddr2,
- nStartAddr3,
- nStartAddr4))
- {
- CString sInvalidAddr=m_startip + "rnIP地址格式不正确。";
- sInvalidAddr+="请输入n.n.n.n格式地址。";
- MessageBox(sInvalidAddr,"无效地址",MB_ICONEXCLAMATION);
- GetDlgItem(IDC_EDIT1)->SetFocus();
- return;
- }
- if (!ValidAddress(m_endip,
- nEndAddr1,
- nEndAddr2,
- nEndAddr3,
- nEndAddr4))
- {
- CString sInvalidAddr=m_endip+"rnIP地址格式不正确。";
- sInvalidAddr+="请输入n.n.n.n格式地址。";
- MessageBox(sInvalidAddr,"无效地址",MB_ICONEXCLAMATION);
- GetDlgItem(IDC_EDIT2)->SetFocus();
- return;
- }
- unsigned long nStartVal=(nStartAddr1<<24)+
- (nStartAddr2<<16)+
- (nStartAddr3<<8)+
- (nStartAddr4);
- unsigned long nEndVal=(nEndAddr1<<24)+
- (nEndAddr2<<16)+
- (nEndAddr3<<8)+
- (nEndAddr4);
- if (nEndVal<nStartVal)
- {
- CString sInvalidAddr="IP地址范围不正确。";
- sInvalidAddr+="请输入n.n.n.n格式地址。";
- MessageBox(sInvalidAddr,"无效地址",MB_ICONEXCLAMATION);
- GetDlgItem(IDC_EDIT2)->SetFocus();
- return;
- }
- if (nEndVal-nStartVal>5000)
- {
- CString sInvalidAddr="IP地址范围不能超过5000。";
- //sInvalidAddr+="请输入n.n.n.n格式地址。";
- MessageBox(sInvalidAddr,"无效地址",MB_ICONEXCLAMATION);
- GetDlgItem(IDC_EDIT2)->SetFocus();
- return;
- }
- count=nEndVal-nStartVal+1;
- m_ani1.Play(0,-1,-1);
- // _tagHost* pHost=new _tagHost[count];
- UINT n1,n2,n3,n4;
- n1=nStartAddr1;
- n2=nStartAddr2;
- n3=nStartAddr3;
- n4=nStartAddr4;
- BOOL bContinue=true;
- for (int i=0;i<count;i++)
- {
- host[i].strIP.Format("%d.%d.%d.%d",n1,n2,n3,n4);
- host[i].bFinished=false;
- host[i].bProxy =false;
- host[i].strName="" ;
- host[i].strProxyName="";
- host[i].uPort=80;
- host[i].uProxyPort=0;
- if((n1==nEndAddr1)&&
- (n2==nEndAddr2)&&
- (n3==nEndAddr3)&&
- (n4==nEndAddr4)) break;
- else
- {
- n4++;
- if(n4>255)
- {
- n4=0;
- n3++;
- if(n3>255)
- {
- n3=0;
- n2++;
- if(n2>255)
- {
- n2=0;
- n1++;
- }//end n2
- }//end n3
- }//end n4
- }
- }
- CString strTemp="开始地址" + host[0].strIP;
- TRACE0(strTemp);
- strTemp="结束地址" + host[count-1].strIP;
- TRACE0(strTemp);
- CString strThread;
- ////////////////////////////////////
- for ( i=0;i< nTotalNum;i++)
- {
- if (i==count) break;
- session.Lock();
- thread[i].nThreadFlag =3;
- thread[i].nThreadNum =i+1;
- thread[i].pHost =&host[i];
- thread[i].strMsg ="";
- nThreadCount++;
- nCurrent++;
- session.Unlock();
- strThread.Format("%d/100",nThreadCount);
- SetDlgItemText(IDC_STATICOUNT,strThread);
- blnRunning=true;
- AfxBeginThread(ClientSocketThreadProc,(LPVOID)&thread[i],0,0,0,NULL);
- strTemp.Format("线程%d开始连接%s...",i+1,thread[i].pHost->strIP);
- m_result.AddString(strTemp);
- UpdateData(false);
- }
- // GetDlgItem(IDOK)->EnableWindow(false);
- btn1.EnableWindow(false);
- }
- void CUnicodeDlg::OnChangeEdit1()
- {
- // TODO: If this is a RICHEDIT control, the control will not
- // TODO: Add your control notification handler code here
- UpdateData(true);
- m_endip=m_startip;
- CString strTemp,strTemp1;
- strTemp=m_startip;
- strTemp.TrimLeft();
- int nPos;
- nPos=strTemp.Find(".");
- if (nPos==-1)
- {
- UpdateData(false);
- return;
- }
- strTemp1=strTemp.Left(nPos);
- strTemp1=strTemp1+".";
- strTemp=strTemp.Mid(nPos+1);
- nPos=strTemp.Find(".");
- if (nPos==-1)
- {
- UpdateData(false);
- return;
- }
- strTemp1=strTemp1+strTemp.Left(nPos);
- strTemp1=strTemp1+".";
- strTemp=strTemp.Mid(nPos+1);
- nPos=strTemp.Find(".");
- if (nPos==-1)
- {
- UpdateData(false);
- return;
- }
- strTemp1=strTemp1+strTemp.Left(nPos);
- strTemp1=strTemp1+".";
- strTemp=strTemp.Mid(nPos+1);
- if (atoi(strTemp)==1)
- {
- strTemp1=strTemp1+"255";
- m_endip=strTemp1;
- }
- UpdateData(false);
- }
- void CUnicodeDlg::OnStop()
- {
- blnRunning=false;
- // m_ani1.Stop();
- //GetDlgItem(IDOK)->EnableWindow(true);
- btn1.EnableWindow(true);
- }
- unsigned long CUnicodeDlg::SplitIp(CString strIp)
- {
- int ip1, ip2,ip3,ip4;
- int nPos;
- unsigned long result;
- ip1=atoi(LPCSTR(strIp));
- nPos=strIp.Find(".");
- strIp=strIp.Mid (nPos+1);
- ip2=atoi(LPCSTR(strIp));
- nPos=strIp.Find(".");
- strIp=strIp.Mid (nPos+1);
- ip3=atoi(LPCSTR(strIp));
- nPos=strIp.Find(".");
- strIp=strIp.Mid (nPos+1);
- ip4=atoi(LPCSTR(strIp));
- // result=ip1*2500000000+ip2*1000000+ip3*1000+ip4; //合成一个
- int sip1,sip2,sip3,sip4;
- sip1=ip1;
- sip2=ip2;
- sip3=ip3;
- sip4=ip4;
- result=(sip1<<24)+(sip2<<16)+(sip3<<8)+ip4; //合成一个
- return result;
- }
- BOOL CAboutDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- HCURSOR hCur;
- hCur=AfxGetApp()->LoadCursor(IDC_HAND);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- LRESULT CUnicodeDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- CString strTemp;
- CString strThread;
- _tagThread * pThread;
- switch(message)
- {
- case WM_SCAN:
- strTemp=LPCSTR(lParam);
- m_result.AddString(strTemp);
- break;
- case WM_SCANOVER:
- pThread=(_tagThread*)wParam;
- strTemp.Format("线程%d结束---->%s",pThread->nThreadNum,pThread->strMsg);
- // MessageBox(strTemp);
- m_result.AddString(strTemp);
- strThread.Format("%d/100",nThreadCount);
- SetDlgItemText(IDC_STATICOUNT,strThread);
- //总数达到
- if (nThreadCount==0)
- {
- btn1.EnableWindow(true);
- m_ani1.Stop();
- break;
- }
- //结束
- if (!blnRunning)
- {
- btn1.EnableWindow(true);
- m_ani1.Stop();
- break;
- }
- if (nCurrent>count-1) break;
- session.Lock();
- pThread->nThreadFlag =3;
- pThread->pHost =&host[nCurrent];
- pThread->strMsg ="";
- nThreadCount++;
- nCurrent++;
- session.Unlock();
- blnRunning=true;
- AfxBeginThread(ClientSocketThreadProc,(LPVOID)pThread,0,0,0,NULL);
- strTemp.Format("线程%d开始连接%s...",pThread->nThreadNum,pThread->pHost->strIP);
- m_result.AddString(strTemp);
- UpdateData(false);
- break;
- case WM_SCANSTART:
- break;
- default:
- ;
- }
- return CDialog::WindowProc(message, wParam, lParam);
- }
- void CUnicodeDlg::OnClear()
- {
- m_result.ResetContent();
- m_result.AddString(" 欢迎使用思想软件安全扫描工具");
- m_result.AddString("台湾自古以来是中国的领土");
- m_result.AddString("版权所有,翻版必究!Copyright (c) by suyu 2001");
- m_result.AddString("HTTP://WWW.WANTSOFT.COM");
- m_result.AddString("QQ:5778368");
- }