UrlDlg.cpp
上传用户:st5609838
上传日期:2013-03-29
资源大小:66k
文件大小:4k
源码类别:

搜索引擎

开发平台:

Visual C++

  1. // UrlDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Spider.h"
  5. #include "UrlDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CUrlDlg dialog
  13. IMPLEMENT_SERIAL (CUrlDlg, CDialog, 1)
  14. CUrlDlg::CUrlDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CUrlDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CUrlDlg)
  18. m_root = FALSE;
  19. //}}AFX_DATA_INIT
  20. m_select=0;
  21. }
  22. void CUrlDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CUrlDlg)
  26. DDX_Control(pDX, IDC_URLCOMBO, m_comboBox);
  27. DDX_Check(pDX, IDC_CHECKROOT, m_root);
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CUrlDlg, CDialog)
  31. //{{AFX_MSG_MAP(CUrlDlg)
  32. ON_CBN_SELCHANGE(IDC_URLCOMBO, OnSelchangeUrlcombo)
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CUrlDlg message handlers
  37. void CUrlDlg::Serialize(CArchive& ar) 
  38. {
  39.     CDialog::Serialize (ar);
  40. if (ar.IsStoring())
  41. { // storing code
  42. ar << m_count << m_select << m_root;
  43. }
  44. else
  45. { // loading code
  46. ar >> m_count >> m_select >> m_root;
  47. }
  48. m_list.Serialize(ar);
  49. }
  50. BOOL CUrlDlg::LoadFile (LPCSTR lpszFileName)
  51. {
  52.     CFile file;
  53.     BOOL bResult = TRUE;
  54.     if (file.Open (lpszFileName, CFile::modeRead)) {
  55.         CWaitCursor wait;
  56.         CArchive ar (&file, CArchive::load);
  57. m_list.RemoveAll();
  58. Serialize (ar);
  59.         //Invalidate ();
  60.     }
  61.     else {
  62.         bResult = FALSE;
  63.     }
  64.     return bResult;
  65. }
  66. BOOL CUrlDlg::SaveFile (LPCSTR lpszFileName)
  67. {
  68.     CFile file;
  69.     BOOL bResult = TRUE;
  70.     if (file.Open (lpszFileName, CFile::modeCreate | CFile::modeWrite)) {
  71.         CWaitCursor wait;
  72.         CArchive ar (&file, CArchive::store);
  73.         Serialize (ar);
  74.     }
  75.     else {
  76.         CString string;
  77.         string.Format ("Unable to Save URL Settings in file  %s", lpszFileName);
  78.         MessageBox (string, "Error", MB_ICONEXCLAMATION | MB_OK);
  79.         bResult = FALSE;
  80.     }
  81.     return bResult;
  82. }
  83. void CUrlDlg::OnOK()
  84. {
  85. m_comboBox.GetWindowText(m_WebFileName);
  86. int nListCount =m_comboBox.GetCount();
  87. m_list.RemoveAll();
  88. // update the combo box so the most recently used URL is at the top
  89. CString strTemp;
  90. while (nListCount > 0)
  91. {
  92. m_comboBox.GetLBText(--nListCount, strTemp);
  93. if (m_WebFileName.Compare(strTemp) == 0)
  94. {
  95. m_comboBox.DeleteString(nListCount);
  96. nListCount = 0;
  97. }
  98. }
  99. m_comboBox.InsertString(0,(LPCTSTR) m_WebFileName );
  100.  nListCount =m_comboBox.GetCount();
  101. for(int i=0; i<nListCount; i++)
  102. {
  103. m_comboBox.GetLBText(i, strTemp);
  104. m_list.AddTail((LPCSTR) strTemp);
  105. }
  106. m_select = m_comboBox.GetCurSel();
  107. CDialog::OnOK();
  108. }
  109. BOOL CUrlDlg::OnInitDialog() 
  110. {
  111. CDialog::OnInitDialog();
  112. CString rString;
  113. POSITION pos=NULL;
  114. int count= m_list.GetCount();
  115. if(count>0)
  116. {
  117. m_comboBox.ResetContent();
  118. for(int i=0; i<count; i++)
  119. {
  120. if( ( pos = m_list.FindIndex( i)) != NULL )
  121. {
  122. rString = m_list.GetAt( pos );
  123. m_comboBox.InsertString(i,(LPCTSTR) rString );
  124. }
  125. }
  126. }
  127. m_comboBox.SetCurSel(m_select);
  128. return TRUE;  // return TRUE unless you set the focus to a control
  129.               // EXCEPTION: OCX Property Pages should return FALSE
  130. }
  131. void CUrlDlg::OnSelchangeUrlcombo() 
  132. {
  133. m_select = m_comboBox.GetCurSel();
  134. if(m_select==CB_ERR) return;
  135. m_comboBox.SetCurSel(m_select);
  136. m_comboBox.GetLBText(m_select,m_WebFileName);
  137. }