showcontentdlg.cpp

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

CPP
190
字号
// ShowContentDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ShowContentDlg.h"


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

/////////////////////////////////////////////////////////////////////////////
// CShowContentDlg dialog


CShowContentDlg::CShowContentDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShowContentDlg::IDD, pParent)
{
	m_bKeepVisible = false ;
	//{{AFX_DATA_INIT(CShowContentDlg)
	m_nCharCountAPage = 30000;
	m_nEleMaxCharCount = 28000 ;
	//}}AFX_DATA_INIT
}


void CShowContentDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShowContentDlg)
	DDX_Control(pDX, IDC_PAGE_NUM, m_editCombox);
	DDX_Control(pDX, IDC_CONTENT, m_editContent);
	DDX_Text(pDX, IDC_CHARCOUNT_PAGE, m_nCharCountAPage);
	DDX_Text(pDX, IDC_ELE_MAX_CHARCOUNT, m_nEleMaxCharCount);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CShowContentDlg, CDialog)
	//{{AFX_MSG_MAP(CShowContentDlg)
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_COPY_ALL, OnCopyAll)
	ON_WM_ACTIVATE()
	ON_EN_KILLFOCUS(IDC_CHARCOUNT_PAGE, OnKillfocusCharcountPage)
	ON_EN_KILLFOCUS(IDC_ELE_MAX_CHARCOUNT, OnKillfocusEleMaxCharcount)
	ON_CBN_SELCHANGE(IDC_PAGE_NUM, OnSelchangePageNum)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowContentDlg message handlers

void CShowContentDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	/* 发言改变此对话框大小没多大意义,删除此代码
	if(NULL != m_editContent.GetSafeHwnd())
	{
		CRect r ;
		GetClientRect(&r);
		r.left += 10 ;
		r.top  += 10 ;
		r.right-= 10 ;
		r.bottom -= 40 ;
		m_editContent.MoveWindow(&r);
	}
	*/
}

void CShowContentDlg::OnCopyAll() 
{
	//选中全部,复制到剪切板
	m_editContent.SetSel(0,-1);
	m_editContent.Copy();
}

void CShowContentDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
{
	CDialog::OnActivate(nState, pWndOther, bMinimized);

	//非激状态最小化
	if(WA_INACTIVE == nState && !bMinimized)	
	{
		if(!m_bKeepVisible)
			ShowWindow(SW_MINIMIZE) ;			
	}
}

BOOL CShowContentDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


void CShowContentDlg::ShowContent()
{
	if(NULL == GetSafeHwnd())
	{
		ASSERT(false);
		return ;
	}

	//生成新值
	m_ArtEles.MakeTextWithCurBBSFormat(m_nEleMaxCharCount,m_nCharCountAPage,m_arTexts);	
	//修改combox的值,并选中第一个值
	m_editCombox.ResetContent() ;
	for(int i = 0 ; i < m_arTexts.GetSize() ; i++ )
	{
		CString strTmp ;
		strTmp.Format("%d",i+1);
		m_editCombox.AddString(strTmp);
	}
	m_editCombox.SetCurSel(0);

	//显示当前页的内容
	GoCurPage() ;
}

bool CShowContentDlg::GoCurPage()
{
	int nPage = m_editCombox.GetCurSel();

	if( nPage < 0 || nPage >= m_arTexts.GetSize())
	{
		ASSERT(false);
		m_editContent.SetWindowText("");
		return false ;
	}
	
	m_editContent.SetWindowText(m_arTexts[nPage]);

	OnCopyAll();//将内容copy到剪贴板
}


void CShowContentDlg::OnKillfocusCharcountPage() 
{
	UpdateData();
	ShowContent();
}

void CShowContentDlg::OnKillfocusEleMaxCharcount() 
{
	UpdateData();
	ShowContent();
}


void CShowContentDlg::OnSelchangePageNum() 
{
	GoCurPage() ;
}

BOOL CShowContentDlg::PreTranslateMessage(MSG* pMsg) 
{
	//焦点在两个编辑框中,回车表示输入完毕,不关闭对话框
	//Esc表示取消输入,也不表示关闭对话框
	if(WM_KEYDOWN == pMsg->message )
	{	
		 CWnd * pWnd = GetFocus();
		if(NULL != pWnd && 
			(pWnd->GetDlgCtrlID() == IDC_ELE_MAX_CHARCOUNT || pWnd->GetDlgCtrlID() == IDC_CHARCOUNT_PAGE))
		{
			int nVirtKey = (int) pMsg->wParam;    
			if(VK_RETURN == nVirtKey )//回车
			{
				UpdateData();
				ShowContent();
				return TRUE;
			}
			else if(VK_ESCAPE == nVirtKey )//取消
			{
				UpdateData(false);
				return TRUE ;
			}
		}		
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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