findmailDlg.cpp
资源名称:FindMail.zip [点击查看]
上传用户:feituo2008
上传日期:2013-02-02
资源大小:493k
文件大小:7k
源码类别:
Email客户端
开发平台:
Visual C++
- // findmailDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "findmail.h"
- #include "findmailDlg.h"
- #include "tcp.h"
- #include "findmailthread.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CfindmailDlg 对话框
- CfindmailDlg::CfindmailDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CfindmailDlg::IDD, pParent)
- , m_stat(_T(""))
- , m_domain(_T(""))
- , m_max_thread_count(100)
- , m_max_thread_num(99)
- , m_min_thread_num(0)
- , m_stat_file(_T(""))
- , m_dict_file(_T(""))
- , m_dial_name(_T(""))
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CfindmailDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Text(pDX, IDE_STAT, m_stat);
- DDX_CBString(pDX, IDC_DOMAIN, m_domain);
- DDX_Text(pDX, IDE_THREAD_COUNT, m_max_thread_count);
- DDV_MinMaxInt(pDX, m_max_thread_count, 1, 1024000);
- DDX_Text(pDX, IDE_MAX_THREAD_NUM, m_max_thread_num);
- DDX_Text(pDX, IDE_MIN_THREAD_NUM, m_min_thread_num);
- DDX_Text(pDX, IDE_STAT_FILE, m_stat_file);
- DDX_Text(pDX, IDE_DICT_FILE, m_dict_file);
- DDX_Text(pDX, IDE_DIAL_NAME, m_dial_name);
- }
- BEGIN_MESSAGE_MAP(CfindmailDlg, CDialog)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(ID_START, OnBnClickedStart)
- ON_WM_CLOSE()
- ON_BN_CLICKED(ID_BROWSE_STAT_FILE, OnBnClickedBrowseStatFile)
- ON_BN_CLICKED(ID_BROWSE_DICT_FILE, OnBnClickedBrowseDictFile)
- ON_BN_CLICKED(IDC_NO_STAT, OnBnClickedNoStat)
- ON_BN_CLICKED(IDC_NOT_SHOW_NONEXIST, OnBnClickedNotShowNonexist)
- ON_EN_CHANGE(IDE_DIAL_NAME, OnEnChangeDialName)
- END_MESSAGE_MAP()
- // CfindmailDlg 消息处理程序
- extern HWND g_hWndNotify;
- BOOL CfindmailDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- g_hWndNotify =m_hWnd; // TODO:在此添加额外的初始化代码
- SetDlgItemText(IDC_DNS, m_dns_client.m_dns_ip);
- for(int i =0; i<m_dns_client.m_dns_count; i++)
- SendDlgItemMessage(IDC_DNS, CB_ADDSTRING, 0, (LPARAM)m_dns_client.m_dns_servers[i]);
- SetDlgItemText(IDE_STAT, "rn只需要输入域名按开始按钮就可以搜索了,选择不显示可以加快搜索速度.rnrn可以调用上次搜索保存的状态文件继续上次的搜索,rnrn可以选择重拨号的拨号名称,在每次连接被拒绝后重新拨号更换IP地址。rnrn欢迎光临编程沙龙www.ProgramSalon.com");
- GetDialName();
- return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void CfindmailDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作矩形中居中
- 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;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标显示。
- HCURSOR CfindmailDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CfindmailDlg::OnBnClickedStart()
- {
- CString str;
- GetDlgItemText(ID_START, str);
- time_t t;
- struct tm *ptm;
- time(&t);
- ptm =localtime(&t);
- char ttm[30];
- wsprintf(ttm, "%04d/%02d/%02d %02d:%02d:%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour,
- ptm->tm_min, ptm->tm_sec);
- if(str =="启动")
- {
- UpdateData();
- SetDlgItemText(IDC_START_TIME, ttm);
- m_dns_client.GetMxServers((char *)(LPCTSTR)m_domain);
- SendDlgItemMessage(IDC_MX_SERVER, CB_RESETCONTENT, 0, 0L);
- for(int i =0; i<m_dns_client.m_mx_server_count; i++)
- SendDlgItemMessage(IDC_MX_SERVER, CB_ADDSTRING, 0, (LPARAM)m_dns_client.m_mx_servers[i]);
- SendDlgItemMessage(IDC_MX_SERVER, CB_SETCURSEL, 0, 0L);
- if(m_dns_client.m_mx_servers ==NULL)
- {
- MessageBox("no mx server");
- return;
- }
- m_thread_manager.Init((char *)(LPCTSTR)m_domain,m_dns_client.m_mx_servers[0], (char *)(LPCTSTR)m_dial_name,
- m_max_thread_count, m_max_thread_num-m_min_thread_num+1, m_min_thread_num,
- (char *)(LPCTSTR)m_stat_file, (char *)(LPCTSTR)m_dict_file);
- SetDlgItemText(IDE_STAT_FILE, m_thread_manager.m_stat_file);
- m_thread_manager.Start((m_stat_file=="")?false:true);
- SetDlgItemText(ID_START, "停止");
- }
- else
- {
- SetDlgItemText(IDC_END_TIME, ttm);
- m_thread_manager.Stop();
- SetDlgItemText(ID_START, "启动");
- }
- }
- void CfindmailDlg::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- if(MessageBox("您是否确定要退出?", "FindMail", MB_YESNO|MB_DEFBUTTON2) ==IDNO)
- return;
- m_thread_manager.Stop();
- CDialog::OnClose();
- }
- void CfindmailDlg::OnBnClickedBrowseStatFile()
- {
- CFileDialog fd(true, "stat", "*.stat");
- if(fd.DoModal() ==IDOK)
- SetDlgItemText(IDE_STAT_FILE, (LPCTSTR)fd.GetPathName());
- else return;
- char temp[100];
- GetPrivateProfileString("CONFIG", "DOMAIN_NAME", "", temp, sizeof(temp), (LPCTSTR)fd.GetPathName());
- SetDlgItemText(IDC_DOMAIN, temp);
- GetPrivateProfileString("CONFIG", "DICT_FILE", "", temp, sizeof(temp), (LPCTSTR)fd.GetPathName());
- SetDlgItemText(IDE_DICT_FILE, temp);
- m_max_thread_count =GetPrivateProfileInt("THREADS", "MAX_COUNT", 0, (LPCTSTR)fd.GetPathName());
- SetDlgItemInt(IDE_THREAD_COUNT, m_max_thread_count);
- m_min_thread_num =GetPrivateProfileInt("THREADS", "MIN_NUM", 0, (LPCTSTR)fd.GetPathName());
- SetDlgItemInt(IDE_MIN_THREAD_NUM, m_min_thread_num);
- m_max_thread_num =GetPrivateProfileInt("THREADS", "COUNT", 0, (LPCTSTR)fd.GetPathName())+m_min_thread_num-1;
- SetDlgItemInt(IDE_MAX_THREAD_NUM, m_max_thread_num);
- //UpdateData();
- }
- void CfindmailDlg::OnBnClickedBrowseDictFile()
- {
- CFileDialog fd(true);
- if(fd.DoModal() ==IDOK)
- SetDlgItemText(IDE_DICT_FILE, (LPCTSTR)fd.GetPathName());
- }
- extern int g_show_stat, g_show_nonexist;
- void CfindmailDlg::OnBnClickedNoStat()
- {
- g_show_stat =!g_show_stat;
- }
- void CfindmailDlg::OnBnClickedNotShowNonexist()
- {
- g_show_nonexist =!g_show_nonexist;
- }
- void CfindmailDlg::OnEnChangeDialName()
- {
- // TODO: If this is a RICHEDIT control, the control will not
- // send this notification unless you override the CDialog::OnInitDialog()
- // function and call CRichEditCtrl().SetEventMask()
- // with the ENM_CHANGE flag ORed into the mask.
- // TODO: Add your control notification handler code here
- }
- int CfindmailDlg::GetDialName(void)
- {
- RASCONN * lpRasConn;
- DWORD lpcb;
- DWORD lpcConnections;
- lpRasConn = (LPRASCONN) GlobalAlloc(GPTR, sizeof(RASCONN));
- lpRasConn->dwSize = sizeof(RASCONN);
- lpcb = sizeof(RASCONN);
- int nRet = RasEnumConnections(lpRasConn, &lpcb, &lpcConnections);
- if (nRet != 0)
- return -1;
- else
- {
- for (int i = 0; i < (int)lpcConnections; i++)
- {
- SendDlgItemMessage(IDE_DIAL_NAME, CB_ADDSTRING, 0, (LPARAM)lpRasConn->szEntryName);
- lpRasConn++;
- }
- }
- GlobalFree(lpRasConn);
- return 0;
- }