gusucode.com > 基于VC编程界面编程高级应用技术源码程序 > VC界面编程高级应用技术/code/2/TaxExpert/ContainerView.cpp

    // ContainerView.cpp : implementation file
//

#include "stdafx.h"
#include "TaxExpert.h"
#include "ContainerView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CContainerView

IMPLEMENT_DYNCREATE(CContainerView, CHtmlView)

CContainerView::CContainerView()
{
	can=1;
}

CContainerView::~CContainerView()
{
}


BEGIN_MESSAGE_MAP(CContainerView, CHtmlView)
	//{{AFX_MSG_MAP(CContainerView)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CContainerView drawing



/////////////////////////////////////////////////////////////////////////////
// CContainerView diagnostics

#ifdef _DEBUG
void CContainerView::AssertValid() const
{
	CHtmlView::AssertValid();
}

void CContainerView::Dump(CDumpContext& dc) const
{
	CHtmlView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CContainerView message handlers


void CContainerView::OnInitialUpdate() 
{
	//TODO: This code navigates to a popular spot on the web.
	//Change the code to go where you'd like.
///this->getd
	LoadFromResource( IDR_WHATS_NEW );
	

	
}
void CContainerView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel) 
{
CHtmlView::OnBeforeNavigate2(lpszURL, nFlags,	lpszTargetFrameName, baPostedData, lpszHeaders, pbCancel);
}

#include "TaxExpertDoc.h"
void CContainerView::OnStatusTextChange(LPCTSTR lpszText) 
{
	
	CString k(lpszText);
	CString g;
	this->u=k;
	CHtmlView::OnStatusTextChange(lpszText);
	
}



BOOL CContainerView::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	if(!can)
		return 1;
	
	//if(pMsg->message==WM_RBUTTONDOWN)
	//	return 1;
	if(pMsg->message==WM_LBUTTONDOWN)
	{
		if(u.Find("temp.htm?no")!=-1)
		{
			can=0;
			CString filename;
			filename=this->GenarateHtml(u.Mid(u.Find("=")+1));
			can=1;
			this->Navigate2(filename);
		//::SendMessage(AfxGetMainWnd()->m_hWnd,ID_FROM_HTML,0,0);	
		return 0;
		}
	////this->Navigate2("c:\\");
	
	}

		
	return CHtmlView::PreTranslateMessage(pMsg);
}


CString CContainerView::GenarateHtml(CString num)

{
	BeginWaitCursor();
	CString filename;
	
	CString content;
	TCHAR s[MAX_PATH];
	GetModuleFileName(NULL,s,MAX_PATH);
	
	TCHAR szDir[MAX_PATH];
	TCHAR szDrv[MAX_PATH];
	_splitpath(s,szDrv,szDir,NULL,NULL);
	
	CString htmlpath=(CString)szDrv+(CString)szDir;
	htmlpath+="kingdom/";
	
	filename=htmlpath+num;
	if(IsFileExist(filename))
		return filename;
	
	
	
	CString Header,tail,body,aftertile;
	//格式化的HTTML文件头及文件尾
	Header.LoadString(IDS_BANNER);
	tail="<hr color=\"#FF0000\">";
	tail+="<p align=\"center\"><span style=\"font-size: 9pt\">税务师欢迎你</span></p>";
	
	
	
	
	CFile tempFile;
	filename=htmlpath+num+".html";
	CTaxExpertDoc * pDOC=(CTaxExpertDoc *)this->GetDocument();	
	CString filter="[num]="+num;
	pDOC->m_pSet->m_strFilter=filter;
	
	pDOC->m_pSet->Requery();
	content=pDOC->m_pSet->m_content;
	if(content.IsEmpty())
		content="无法查看该文件";
	Header+=pDOC->m_pSet->m_fileName;
	aftertile.LoadString(IDS_BANNERAFTERTILE);
	//构造红头文件:标题+换行+文号
	Header+="<br>";
	Header+=pDOC->m_pSet->m_file_num;
	Header+=aftertile;
	tempFile.Open(filename,CFile::modeCreate|CFile::modeReadWrite);
	CString k("\r\n");
	content.Replace(k,"<br>" );
	body=Header+content+tail;
	tempFile.Write(body,body.GetLength() ); 
	
	tempFile.Close();
	EndWaitCursor();
	return filename;
}

BOOL CContainerView::IsFileExist(CString strFileName)
{
	CFileStatus sta; 
	CFile tempFile;
	BOOL IsExist=tempFile.GetStatus(strFileName,sta);
	return IsExist;
}