MainFrm.cpp
上传用户:csjhqyl
上传日期:2013-08-06
资源大小:22k
文件大小:4k
源码类别:

PlugIns编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "CHtmlView_Search.h"
  5. #include "MainFrm.h"
  6. #include "CHtmlView_SearchDoc.h"
  7. #include "CHtmlView_SearchView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMainFrame
  15. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  16. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  17. //{{AFX_MSG_MAP(CMainFrame)
  18. ON_WM_CREATE()
  19. ON_BN_CLICKED(IDC_HALL, OnHall)
  20. //}}AFX_MSG_MAP
  21. ON_COMMAND(IDC_SEARCHCOMBO, OnSearch)
  22. END_MESSAGE_MAP()
  23. static UINT indicators[] =
  24. {
  25. ID_SEPARATOR,           // status line indicator
  26. ID_INDICATOR_CAPS,
  27. ID_INDICATOR_NUM,
  28. ID_INDICATOR_SCRL,
  29. };
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMainFrame construction/destruction
  32. CMainFrame::CMainFrame()
  33. {
  34. // TODO: add member initialization code here
  35. }
  36. CMainFrame::~CMainFrame()
  37. {
  38. }
  39. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  40. {
  41. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  42. return -1;
  43. if (!m_wndToolBar.CreateEx(this) ||
  44. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  45. {
  46. TRACE0("Failed to create toolbarn");
  47. return -1;      // fail to create
  48. }
  49. if (!m_wndDlgBar.Create(this, IDR_MAINFRAME, 
  50. CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
  51. {
  52. TRACE0("Failed to create dialogbarn");
  53. return -1; // fail to create
  54. }
  55. CRect rect(50,3,250,200);
  56. m_wndSearchCombo.Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWN|CBS_AUTOHSCROLL|WS_VSCROLL,rect,&m_wndDlgBar,IDC_SEARCHCOMBO);
  57. m_wndSearchCombo.SetFont(m_wndDlgBar.GetFont());
  58. if (!m_wndReBar.Create(this) ||
  59. !m_wndReBar.AddBar(&m_wndToolBar) ||
  60. !m_wndReBar.AddBar(&m_wndDlgBar))
  61. {
  62. TRACE0("Failed to create rebarn");
  63. return -1;      // fail to create
  64. }
  65. if (!m_wndStatusBar.Create(this) ||
  66. !m_wndStatusBar.SetIndicators(indicators,
  67.   sizeof(indicators)/sizeof(UINT)))
  68. {
  69. TRACE0("Failed to create status barn");
  70. return -1;      // fail to create
  71. }
  72. // TODO: Remove this if you don't want tool tips
  73. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  74. CBRS_TOOLTIPS | CBRS_FLYBY);
  75. m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->SetWindowText("darkblue");
  76. m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->EnableWindow(FALSE);
  77. m_wndDlgBar.GetDlgItem(IDC_HCOL)->EnableWindow(FALSE);
  78. return 0;
  79. }
  80. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  81. {
  82. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  83. return FALSE;
  84. // TODO: Modify the Window class or styles here by modifying
  85. //  the CREATESTRUCT cs
  86. return TRUE;
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CMainFrame diagnostics
  90. #ifdef _DEBUG
  91. void CMainFrame::AssertValid() const
  92. {
  93. CMDIFrameWnd::AssertValid();
  94. }
  95. void CMainFrame::Dump(CDumpContext& dc) const
  96. {
  97. CMDIFrameWnd::Dump(dc);
  98. }
  99. #endif //_DEBUG
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CMainFrame message handlers
  102. void CMainFrame::OnSearch()
  103. {
  104. CString txt;
  105. m_wndSearchCombo.GetWindowText(txt);
  106. if(txt=="") return;
  107. int nFlags = ((CButton*)m_wndDlgBar.GetDlgItem(IDC_WORD))->GetCheck() ? 2 : 0;
  108. BOOL bHAll = ((CButton*)m_wndDlgBar.GetDlgItem(IDC_HALL))->GetCheck();
  109. CString sHlColor;
  110. m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->GetWindowText(sHlColor);
  111. CView *pView = GetActiveFrame()->GetActiveView();
  112. if(pView!=NULL)
  113. {
  114. CString sClassName(pView->GetRuntimeClass()->m_lpszClassName);
  115. if(sClassName=="CCHtmlView_SearchView")
  116. {
  117. if(bHAll)
  118. ((CCHtmlView_SearchView*)pView)->FindText2(txt,nFlags,"color: white; background-color: "+sHlColor);
  119. else
  120. ((CCHtmlView_SearchView*)pView)->FindText(txt,nFlags);
  121. }
  122. // TODO: Add more if statements to extend search to other view classes
  123. return;
  124. }
  125. AfxMessageBox("Cannot find the string '" + txt + "'.");
  126. }
  127. void CMainFrame::OnHall() 
  128. {
  129. if(((CButton*)m_wndDlgBar.GetDlgItem(IDC_HALL))->GetCheck())
  130. {
  131. m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->EnableWindow();
  132. m_wndDlgBar.GetDlgItem(IDC_HCOL)->EnableWindow();
  133. } else
  134. {
  135. m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->EnableWindow(FALSE);
  136. m_wndDlgBar.GetDlgItem(IDC_HCOL)->EnableWindow(FALSE);
  137. }
  138. }