本帖最后由 VisualEleven 于 2011-05-09 15:20:46 编辑

解决方案 »

  1.   


    /////////////////////////////////////////////////////////////////////////////
    // CSynScanPortDlg message handlersBOOL CSynScanPortDlg::OnInitDialog()//对话被创建(Create)后立即被执行的函数,因此在这里可以添加对话框的初始化所需要的自定义代码。
    {
    CDialog::OnInitDialog();//调用父类初始化函数
        m_progress = &m_progressScan;
    // 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 m_wndLink1.SubclassDlgItem(IDC_URL1, this); m_btnok.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4);
    m_btnok.SetFontColor(RGB(100,50,280));
    m_btn_ping.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4);
    m_btn_ping.SetFontColor(RGB(100,50,280));
    m_btn_out.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4);
    m_btn_out.SetFontColor(RGB(100,50,280));
    m_btn_clean.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4);
    m_btn_clean.SetFontColor(RGB(100,50,280)); // TODO: Add extra initialization here m_IP2.SetAddress(172,18,94,18); char FAR              hostname[128] = ""; 
        struct hostent        *phe; 
    WSADATA               WSAData;
    WSAStartup(MAKEWORD(2,1) ,&WSAData);
        gethostname(hostname,128);
        phe = gethostbyname(94);
    if(phe == NULL) 
    exit(0);
        strcpy(srcIP, inet_ntoa(*((struct in_addr *)phe->h_addr_list[0])));
    SetDlgItemText(IDC_EDIT_IP,srcIP);
    StartPort = 0;
    EndPort = 0;
    dlg = this;
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)recv_packet,NULL,0,NULL); 
    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CSynScanPortDlg::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 CSynScanPortDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }void CSynScanPortDlg::OnOK() 
    {
    UpdateData(TRUE); BYTE f1,f2,f3,f4;
    char temp[10]; /****获取IP地址****/
    if(m_IP2.IsBlank())
    {
    MessageBox("请输入IP地址",_T("错误"),MB_ICONWARNING|MB_OK);
    return;
    } if(m_IP2.GetAddress(f1,f2,f3,f4)<4)
    {
    MessageBox("请输入完整的IP地址",_T("错误"),MB_ICONWARNING|MB_OK);
    return;
    }
        m_ip.Format("%d.%d.%d.%d",f1,f2,f3,f4);
    UpdateData(false);
    StartPort = m_startport;
    EndPort = m_endport;
    AfxBeginThread((AFX_THREADPROC)send_packet,(void *)m_ip.GetBuffer(0));//开启扫描线程
    }
    void CSynScanPortDlg::OnButtonOut() 
    {
    CFileDialog fileDialog(TRUE,"*.txt",NULL,NULL,"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||");
    if (fileDialog.DoModal() == IDOK) 
    {
    CString m_file = fileDialog.GetPathName();
    CFile file;
    file.Open(m_file,CFile::modeCreate|CFile::modeWrite);
    file.Write(m_show.GetBuffer(0),m_show.GetLength());
    file.Close();
    MessageBox("导出成功","导出列表");
    }
    }void CSynScanPortDlg::OnButtonClean() 
    {
    m_show="显示结果...\n";
    UpdateData(FALSE);
    }void CSynScanPortDlg::OnButtonPing() 
    {
    UpdateData(TRUE);
    CPing ping;
    ping.SetConfigure(m_ip.GetBuffer(0),32,4);//设置ping参数
    ping.Ping(1000);
    CString str;
    str.Format("%s",ping.msg);
    m_show+=str;
    UpdateData(FALSE);
    }void CSynScanPortDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    ::SendMessage(this->GetSafeHwnd(),WM_SYSCOMMAND,SC_MOVE+HTCAPTION,0);
    CDialog::OnLButtonDown(nFlags, point);
    }