exportview.cpp

来自「深入浅出Visual C++入门进阶与应用实例 随书光盘 作者 何志丹」· C++ 代码 · 共 346 行

CPP
346
字号
// ExportView.cpp : implementation file
//

#include "stdafx.h"
#include "ExportView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CExportView

IMPLEMENT_DYNCREATE(CExportView, CFormView)

CExportView::CExportView()
	: CFormView(CExportView::IDD)
{
	//{{AFX_DATA_INIT(CExportView)
	m_strCurArticleTopic = _T("");
	m_bUseQMDExportArticle = TRUE;
	m_bUserQMDExportClass = FALSE;
	m_bUserLink = TRUE ;
	m_ExportType = 1;
	m_bExportSome = TRUE;
	//}}AFX_DATA_INIT

	m_pShowContentDlg = NULL ;
}

CExportView::~CExportView()
{
	if(NULL != m_pShowContentDlg)
		delete m_pShowContentDlg ;

	for(int i = m_arWebInfos.GetSize() - 1 ; i >= 0 ; i-- )
	{
		CWebInfo * pWebInfo = m_arWebInfos[i] ;
		if(NULL == pWebInfo )
			continue ;
		delete pWebInfo ;
	}
}

void CExportView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CExportView)
	DDX_Control(pDX, IDC_LIST_WEBNAME, m_listWebName);
	DDX_Text(pDX, IDC_CURARTICLE_TOPIC, m_strCurArticleTopic);
	DDX_Check(pDX, IDC_USEQMD_EXPORTARTICLE, m_bUseQMDExportArticle);
	DDX_Check(pDX, IDC_USEQMD_EXPORTCLASS, m_bUserQMDExportClass);
	DDX_Check(pDX, IDC_USER_LINK, m_bUserLink);
	DDX_Radio(pDX, IDC_EXPORTBBS_CURARTICLE, m_ExportType);
	DDX_Check(pDX, IDC_EXPORT_SOME, m_bExportSome);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CExportView, CFormView)
	//{{AFX_MSG_MAP(CExportView)
	ON_BN_CLICKED(IDC_EXPORT, OnExport)
	ON_LBN_SELCHANGE(IDC_LIST_WEBNAME, OnSelchangeListWebname)
	ON_BN_CLICKED(IDC_SETTING, OnSetting)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_ADVANCE, OnAdvance)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExportView diagnostics

#ifdef _DEBUG
void CExportView::AssertValid() const
{
	CFormView::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CExportView message handlers

void CExportView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	CArticleDoc * pDoc = (CArticleDoc*) m_pDocument ;
	if(NULL == pDoc)
	{
		ASSERT(false);
		return ;
	}

	CMainData * pData = &pDoc->m_mainData ;
	

	CArticleData * pArticleData = pData->GetCurArticleData() ;
	if(NULL == pArticleData)
		m_strCurArticleTopic = "";
	else
		m_strCurArticleTopic = pArticleData->m_topic ;

//	m_strTemFileName = GetExePath() + "tem.htm" ;

//	CClassTreeNodeData* pTreeNode = pData->GetCurTreeNode() ;
//	m_strDestPath = GetExePath() + pTreeNode->m_strDirName + "\\";
		
	UpdateData(false);
}

bool CExportView::ExportCurArticle()
{
	CArticleDoc * pDoc = (CArticleDoc*) m_pDocument ;
	if(NULL == pDoc)
	{
		ASSERT(false);
		return false;
	}
	CArticleData * pData = pDoc->m_mainData.GetCurArticleData() ;
	if(NULL == pData )
	{
		ASSERT(false);
		return false ;
	}
	
	if(NULL == m_pShowContentDlg)
		m_pShowContentDlg = new CShowContentDlg ;
	if(NULL == m_pShowContentDlg)
	{
		ASSERT(false);
		return false;
	}
	
	{
		CString strDirUrl = pDoc->m_mainData.GetDirOfCurTreeNode() ;

		m_pShowContentDlg->m_ArtEles = pData->m_content ;	
		m_pShowContentDlg->m_ArtEles +="\r\n\r\n\r\n";
		
		CString strText = "全文(静态页面,访问速度N快)" ;
		CString strUrl = strDirUrl + pData->m_FileName ;
		m_pShowContentDlg->m_ArtEles.AddLink(strText,strUrl);
		m_pShowContentDlg->m_ArtEles +="\r\n\r\n";
		
		strText = "类似内容"	 ;
		strUrl = strDirUrl ;
		m_pShowContentDlg->m_ArtEles.AddLink(strText,strUrl);
		m_pShowContentDlg->m_ArtEles +="\r\n\r\n";
		
		if(m_bUseQMDExportArticle)
		{
			CString strQMD = ::GetQMD();
			m_pShowContentDlg->m_ArtEles += strQMD ;
		}
	}
	
	if(NULL == m_pShowContentDlg->GetSafeHwnd())
		m_pShowContentDlg->Create(CShowContentDlg::IDD,NULL);
	m_pShowContentDlg->ShowWindow(SW_NORMAL);
	m_pShowContentDlg->ShowContent();
	
	return true;
}

bool CExportView::ExportCurClass()
{
	CArticleDoc * pDoc = (CArticleDoc*) m_pDocument ;
	if(NULL == pDoc)
	{
		ASSERT(false);
		return false;
	}

	CString strText ;
	if(m_bExportSome)
		strText = CSelectExportArticles::GetArticleTexts();
	else
		strText = pDoc->m_mainData.ExportCurClassIndex(m_bUserLink);
	
	if(m_bUserQMDExportClass)
	{
		strText += "\r\n\r\n\r\n";
		strText += GetQMD();
	}
	
	if(NULL == m_pShowContentDlg)
		m_pShowContentDlg = new CShowContentDlg ;
	if(NULL == m_pShowContentDlg)
	{
		ASSERT(false);
		return false;
	}
	if(NULL == m_pShowContentDlg->GetSafeHwnd())
		m_pShowContentDlg->Create(CShowContentDlg::IDD,this);
	m_pShowContentDlg->ShowWindow(SW_RESTORE);
	m_pShowContentDlg->m_editContent.SetWindowText(strText);
	m_pShowContentDlg->m_editContent.SetSel(0,-1);
	m_pShowContentDlg->m_editContent.Copy();

	return true;
}


void CExportView::OnExport() 
{
	UpdateData();
	
	switch(m_ExportType)
	{
	case 0 : 		
		ExportCurArticle();
		break;
	case 1 :
		ExportCurClass();
		break;
	default:
		ASSERT(false);
		break;
	}
	
}



void CExportView::InitWebNameList()
{
	CWebInfoSet rs ;
	rs.Open();
	while(!rs.IsEOF())
	{
		CWebInfo * pWebInfo = new CWebInfo(rs) ;
		if(NULL != pWebInfo)
		{
			m_arWebInfos.Add(pWebInfo) ;
			m_listWebName.AddString(pWebInfo->m_strWebName);
		}
		rs.MoveNext();
	}
	rs.Close();
}

void CExportView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	InitWebNameList();	

	CSetting::SetChildFrameStateInfo(CHILDFRAME_TYPE_EXPORT,true);
}

void CExportView::OnSelchangeListWebname() 
{
	int nSel = m_listWebName.GetCurSel() ;
	if(-1 == nSel )
		return ;
	
	CWebInfo * pWebInfo = m_arWebInfos[nSel] ;
	if(NULL != pWebInfo )
		CSetting::SetBBSLinkFormat(pWebInfo->m_strLinkFormat);
}

BOOL CExportView::PreTranslateMessage(MSG* pMsg) 
{
	if(WM_LBUTTONDBLCLK	== pMsg->message)
	{
		if(pMsg->hwnd == GetDlgItem(IDC_EXPORTBBS_CURARTICLE)->GetSafeHwnd())
		{
			OnExport();
			OnUserEvent();
		}
		else if(pMsg->hwnd == GetDlgItem(IDC_EXPORTBBS_CURCLASS)->GetSafeHwnd())
		{
			OnExport();
			OnUserEvent();
		}
		else if(pMsg->hwnd == GetDlgItem(IDC_LIST_WEBNAME)->GetSafeHwnd())
		{
			OnExport();
			OnUserEvent();
		}		
	}
	return CFormView::PreTranslateMessage(pMsg);
}

void CExportView::OnUserEvent()
{
	UpdateData();
	
	CString strUrl;
	int nSel = m_listWebName.GetCurSel();
	if(-1 == nSel)
		return ;

	switch(m_ExportType)
	{
	case 0 : 		
		strUrl = m_arWebInfos[nSel]->m_strLink1 ;
		break;
	case 1 :
		strUrl = m_arWebInfos[nSel]->m_strLink2 ;
		break;
	default:
		break;
	}

	if(!strUrl.IsEmpty())
	ShellExecute(NULL,_T("open"),//SK modified for Unicode
		_T(strUrl),NULL,NULL,//SK modified for Unicode
		SW_MAXIMIZE);
}

void CExportView::OnSetting() 
{
	CArticleDoc * pDoc = (CArticleDoc*) m_pDocument ;
	if(NULL == pDoc)
	{
		ASSERT(false);
		return ;
	}

	CSelectExportArticles::GetArticleTexts(true,&pDoc->m_mainData);
}


void CExportView::OnDestroy() 
{
	CFormView::OnDestroy();
	
	CSetting::SetChildFrameStateInfo(CHILDFRAME_TYPE_EXPORT,false);
}

void CExportView::OnAdvance() 
{
	CSelectLinkFormatDlg dlg; 
	if(IDOK == dlg.DoModal())
	{
		if(!dlg.m_strLinkFormat.IsEmpty())
			CSetting::SetBBSLinkFormat(dlg.m_strLinkFormat);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?