// ViewerView.cpp : implementation of the CViewerView class // #include "stdafx.h" #include "Viewer.h" #include "ViewerDoc.h" #include "ViewerView.h" #include "MainFrm.h" #include "fileInfo.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CViewerView IMPLEMENT_DYNCREATE(CViewerView, CHtmlView) BEGIN_MESSAGE_MAP(CViewerView, CHtmlView) // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CHtmlView::OnFilePrint) ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1) ON_WM_TIMER() END_MESSAGE_MAP() // CViewerView construction/destruction CViewerView::CViewerView() { // TODO: add construction code here } CViewerView::~CViewerView() { } BOOL CViewerView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CHtmlView::PreCreateWindow(cs); } void CViewerView::OnInitialUpdate() { CHtmlView::OnInitialUpdate(); pDoc2 = 0; // find all *.h and *.cpp files in current directory char path[255]; GetCurrentDirectory(255,path); _path = path; _path += "\\"; fileInfo fi(path); MaxCount = 0; if(fi.firstFile("*.cpp")) { files[MaxCount++] = fi.name().c_str(); // AfxMessageBox(files[num-1],0,0); while(MaxCount < 254 && fi.nextFile()) { files[MaxCount++] = fi.name().c_str(); } } fi.closeFile(); if(fi.firstFile("*.h")) { files[MaxCount++] = fi.name().c_str(); // AfxMessageBox(files[num-1],0,0); while(MaxCount < 254 && fi.nextFile()) { files[MaxCount++] = fi.name().c_str(); } } Count = 0; // create timer and set to tick once per second SetTimer(1,1000,NULL); // load first file in browser control Navigate2(_T(_path + files[Count]),NULL,NULL); GetHTMLDocPointer(); } //----< navigate to next name in files array >----------------------- afx_msg void CViewerView::OnTimer(UINT nTimerID) { CMainFrame* pMF = (CMainFrame*)AfxGetMainWnd(); CDialogBar& bar = pMF->GetDialogBarRef(); CButton *pChkBox = (CButton*)bar.GetDlgItem(IDC_CHECK1); if(pChkBox->GetCheck()) { Count = Count++; if(Count >= MaxCount) Count = 0; Navigate2(_T(_path + files[Count]),NULL,NULL); bar.SetDlgItemText(IDC_EDIT1,_path + files[Count]); } } // CViewerView printing // CViewerView diagnostics #ifdef _DEBUG void CViewerView::AssertValid() const { CHtmlView::AssertValid(); } void CViewerView::Dump(CDumpContext& dc) const { CHtmlView::Dump(dc); } CViewerDoc* CViewerView::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CViewerDoc))); return (CViewerDoc*)m_pDocument; } #endif //_DEBUG // CViewerView message handlers //----< navigate to url in textbox when button is clicked >---------- void CViewerView::OnBnClickedButton1() { CMainFrame* pMF = (CMainFrame*)AfxGetMainWnd(); CDialogBar& bar = pMF->GetDialogBarRef(); CString str; bar.GetDlgItemText(IDC_EDIT1,str); Navigate2(str,NULL,NULL); } //----< retrieve pointer to COM document interface >----------------- bool CViewerView::GetHTMLDocPointer() { // get dispatch interface pDoc = GetHtmlDocument(); // use that to get document interface if(pDoc) { // sets member pDoc to the document interface HRESULT hr = pDoc->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&pDoc2); pDoc->Release(); if(SUCCEEDED(hr)) return true; return false; } } //----< release the COM document interface >------------------------- void CViewerView::ReleaseHTMLDocument() { if(pDoc2) { pDoc2->Release(); pDoc2 = 0; } } //----< insert HTML heading into current document >------------------ // // When navigation to new document is complete this handler // Gets COM document interface and uses it to load a heading // element // void CViewerView::OnNavigateComplete2(LPCTSTR strURL) { CHtmlView::OnNavigateComplete2(strURL); GetHTMLDocPointer(); IHTMLElement* pBody = 0; pDoc2->get_body(&pBody); // CComBSTR name(L"onclick"); // CComVariant value(L"alert('hi')"); // pBody->setAttribute(name,value); CComBSTR file(files[Count]); CComBSTR temp = L"

"; temp += file; temp += L"

"; pBody->insertAdjacentHTML(L"afterBegin",temp); BSTR temp2; pBody->get_outerHTML(&temp2); // AfxMessageBox((LPCSTR)temp2); ReleaseHTMLDocument(); } //----< event handler when navigation starts - not used here >------- void CViewerView::OnBeforeNavigate2( LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel ) { CHtmlView::OnBeforeNavigate2(lpszURL, nFlags, lpszTargetFrameName, baPostedData, lpszHeaders, pbCancel); }