MainFrm.cpp
上传用户:csjhqyl
上传日期:2013-08-06
资源大小:22k
文件大小:4k
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "CHtmlView_Search.h"
- #include "MainFrm.h"
- #include "CHtmlView_SearchDoc.h"
- #include "CHtmlView_SearchView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_BN_CLICKED(IDC_HALL, OnHall)
- //}}AFX_MSG_MAP
- ON_COMMAND(IDC_SEARCHCOMBO, OnSearch)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
-
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- if (!m_wndDlgBar.Create(this, IDR_MAINFRAME,
- CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
- {
- TRACE0("Failed to create dialogbarn");
- return -1; // fail to create
- }
- CRect rect(50,3,250,200);
- m_wndSearchCombo.Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWN|CBS_AUTOHSCROLL|WS_VSCROLL,rect,&m_wndDlgBar,IDC_SEARCHCOMBO);
- m_wndSearchCombo.SetFont(m_wndDlgBar.GetFont());
-
- if (!m_wndReBar.Create(this) ||
- !m_wndReBar.AddBar(&m_wndToolBar) ||
- !m_wndReBar.AddBar(&m_wndDlgBar))
- {
- TRACE0("Failed to create rebarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Remove this if you don't want tool tips
- m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY);
- m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->SetWindowText("darkblue");
- m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->EnableWindow(FALSE);
- m_wndDlgBar.GetDlgItem(IDC_HCOL)->EnableWindow(FALSE);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CMDIFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CMDIFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CMDIFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnSearch()
- {
- CString txt;
- m_wndSearchCombo.GetWindowText(txt);
- if(txt=="") return;
- int nFlags = ((CButton*)m_wndDlgBar.GetDlgItem(IDC_WORD))->GetCheck() ? 2 : 0;
- BOOL bHAll = ((CButton*)m_wndDlgBar.GetDlgItem(IDC_HALL))->GetCheck();
- CString sHlColor;
- m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->GetWindowText(sHlColor);
- CView *pView = GetActiveFrame()->GetActiveView();
- if(pView!=NULL)
- {
- CString sClassName(pView->GetRuntimeClass()->m_lpszClassName);
- if(sClassName=="CCHtmlView_SearchView")
- {
- if(bHAll)
- ((CCHtmlView_SearchView*)pView)->FindText2(txt,nFlags,"color: white; background-color: "+sHlColor);
- else
- ((CCHtmlView_SearchView*)pView)->FindText(txt,nFlags);
- }
- // TODO: Add more if statements to extend search to other view classes
- return;
- }
- AfxMessageBox("Cannot find the string '" + txt + "'.");
- }
- void CMainFrame::OnHall()
- {
- if(((CButton*)m_wndDlgBar.GetDlgItem(IDC_HALL))->GetCheck())
- {
- m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->EnableWindow();
- m_wndDlgBar.GetDlgItem(IDC_HCOL)->EnableWindow();
- } else
- {
- m_wndDlgBar.GetDlgItem(IDC_HCOLOR)->EnableWindow(FALSE);
- m_wndDlgBar.GetDlgItem(IDC_HCOL)->EnableWindow(FALSE);
- }
- }