⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tipreaderview.cpp

📁 一个集成的文本阅读工具
💻 CPP
字号:
// TipReaderView.cpp : implementation of the CTipReaderView class
//

#include "stdafx.h"
#include "TipReader.h"
#include "ChildFrm.h"
#include "TipReaderDoc.h"
#include "TipReaderView.h"
#include "MainFrm.h"
#include "CtrlFullScreenBar.h"

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

#define WM_MYSCROLL WM_USER+1
/////////////////////////////////////////////////////////////////////////////
// CTipReaderView

IMPLEMENT_DYNCREATE(CTipReaderView, CEditView)

BEGIN_MESSAGE_MAP(CTipReaderView, CEditView)
	//{{AFX_MSG_MAP(CTipReaderView)
	ON_WM_CREATE()
	ON_COMMAND(ID_FONT, OnFont)
	ON_CONTROL_REFLECT(EN_VSCROLL, OnVscroll)
	ON_COMMAND(ID_NOTEPAD, OnNotepad)
	ON_WM_CHAR()
	ON_COMMAND(ID_BACKGROUND_COLOR, OnBackgroundColor)
	ON_COMMAND(ID_FONT_COLOR, OnFontColor)
	ON_WM_CTLCOLOR_REFLECT()
	ON_WM_TIMER()
	ON_WM_SIZE()
	ON_WM_VSCROLL()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTipReaderView construction/destruction

CTipReaderView::CTipReaderView()
{
	// TODO: add construction code here
	((CTipReaderApp *)(::AfxGetApp()))->m_pEditView=this;
	m_pbrBkgnd=new CBrush();
	m_clrText = RGB( 220, 220, 220 );
	m_clrBkgnd = RGB( 0, 0, 0 );
	m_pbrBkgnd->CreateSolidBrush( m_clrBkgnd );
	m_IsScroll=FALSE;
}

CTipReaderView::~CTipReaderView()
{
}

BOOL CTipReaderView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
	cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);	// Enable word-wrapping

	return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CTipReaderView drawing

void CTipReaderView::OnDraw(CDC* pDC)
{
	CTipReaderDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

}

/////////////////////////////////////////////////////////////////////////////
// CTipReaderView printing

BOOL CTipReaderView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default CEditView preparation
	return CEditView::OnPreparePrinting(pInfo);
}

void CTipReaderView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView begin printing.
	CEditView::OnBeginPrinting(pDC, pInfo);
}

void CTipReaderView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView end printing
	CEditView::OnEndPrinting(pDC, pInfo);
}

/////////////////////////////////////////////////////////////////////////////
// CTipReaderView diagnostics

#ifdef _DEBUG
void CTipReaderView::AssertValid() const
{
	CEditView::AssertValid();
}

void CTipReaderView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

CTipReaderDoc* CTipReaderView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTipReaderDoc)));
	return (CTipReaderDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTipReaderView message handlers

int CTipReaderView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CEditView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	this->GetDocument()->m_pEditView=this;
	return 0;
}

void CTipReaderView::OnFont() 
{
	// TODO: Add your command handler code here
	LOGFONT m_logfont;
	((CTipReaderApp *)::AfxGetApp())->m_config.m_font.GetLogFont(&m_logfont);
	CFontDialog m_fontdlg(&m_logfont,CF_EFFECTS | CF_SCREENFONTS,NULL,this);
	m_fontdlg.m_cf.hwndOwner=this->m_hWnd;
	if(m_fontdlg.DoModal()==IDOK)
	{
		m_fontdlg.GetCurrentFont(&m_logfont);
		((CTipReaderApp *)::AfxGetApp())->m_config.m_font.DeleteObject();
		((CTipReaderApp *)::AfxGetApp())->m_config.m_font.CreateFontIndirect(&m_logfont);
		(this->GetEditCtrl()).SetFont(&(((CTipReaderApp *)::AfxGetApp())->m_config.m_font),TRUE);
		(this->GetEditCtrl()).UpdateWindow();
	}
}



void CTipReaderView::OnVscroll() 
{
	// TODO: Add your control notification handler code here
	((CTipReaderApp *)::AfxGetApp())->m_config.m_poision=this->GetEditCtrl().GetScrollPos(SB_VERT);
}

void CTipReaderView::OnNotepad() 
{
	// TODO: Add your command handler code here
	HINSTANCE m_instance;
	if(((int)(m_instance=::ShellExecute(this->m_hWnd, "open","notepad.exe", NULL, NULL, SW_SHOWNORMAL)))<=32)
	{
		::AfxMessageBox("有错误发生!");
	}
}


void CTipReaderView::OnInitialUpdate() 
{
	CEditView::OnInitialUpdate();
	// TODO: Add your specialized code here and/or call the base class
	((CSplitterWnd *)this->GetParent())->SetColumnInfo(0,170,10);
	((CSplitterWnd *)this->GetParent())->RecalcLayout();
}


void CTipReaderView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	if(nChar==VK_ESCAPE) //如果按的键为Esc键  
	{
		//获取主框架窗口的指针  
		CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;  
		//调用主窗口类的自定义函数 EndFullScreen ,便可退出全屏显示状态  
		pFrame->EndFullScreen();
	}
	else
		CEditView::OnChar(nChar, nRepCnt, nFlags);
}



void CTipReaderView::OnBackgroundColor() 
{
	// TODO: Add your command handler code here

	CColorDialog dlg;
	if(dlg.DoModal()==IDOK)
	{
		m_clrBkgnd=dlg.GetColor();
		delete m_pbrBkgnd;
		m_pbrBkgnd=new CBrush();
		m_pbrBkgnd->CreateSolidBrush( m_clrBkgnd );
		::AfxGetApp()->m_pMainWnd->ShowWindow(SW_HIDE);
		::AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
		((CTipReaderApp *)::AfxGetApp())->m_config.m_bkgcolor=m_clrBkgnd;
	}

}

void CTipReaderView::OnFontColor() 
{

	// TODO: Add your command handler code here
	CColorDialog dlg;
	if(dlg.DoModal()==IDOK)
	{

		m_clrText=dlg.GetColor();
		::AfxGetApp()->m_pMainWnd->ShowWindow(SW_HIDE);
		::AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
		((CTipReaderApp *)::AfxGetApp())->m_config.m_txtcolor=m_clrText;
	}	

}


HBRUSH CTipReaderView::CtlColor(CDC* pDC, UINT nCtlColor) 
{
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a non-NULL brush if the parent's handler should not be called
	//return NULL;
	pDC->SetTextColor( m_clrText );    // text
	pDC->SetBkColor( m_clrBkgnd );    // text bkgnd
	return *(m_pbrBkgnd);                // ctl bkgnd
}



LRESULT CTipReaderView::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(message==WM_MYSCROLL)
	{
		if(FALSE==m_IsScroll)
		{
			CString str;
			((CMainFrame *)::AfxGetApp()->m_pMainWnd)->m_wndCFSBar.m_Edt.GetWindowText(str);
			this->SetTimer(322,atoi(str),NULL);
			((CMainFrame *)::AfxGetApp()->m_pMainWnd)->m_wndCFSBar.m_Btn2.SetWindowText("停止滚屏");
			m_IsScroll=TRUE;
		}
		else
		{
			this->KillTimer(322);
			((CMainFrame *)::AfxGetApp()->m_pMainWnd)->m_wndCFSBar.m_Btn2.SetWindowText("自动滚屏");
			m_IsScroll=FALSE;
		}
	}
	return CEditView::DefWindowProc(message, wParam, lParam);
}

void CTipReaderView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	//int line_index;
	//line_index=this->GetEditCtrl().GetFirstVisibleLine();
	//this->GetEditCtrl().LineScroll(line_index+1,0);
	::SendMessage(this->m_hWnd,
				WM_KEYDOWN,
				0x28,
				1
				);


	CEditView::OnTimer(nIDEvent);
}

void CTipReaderView::OnSize(UINT nType, int cx, int cy) 
{
	CEditView::OnSize(nType, cx, cy);
	if(this->m_IsScroll==TRUE)
		((CMainFrame *)::AfxGetApp()->m_pMainWnd)->m_wndCFSBar.StopScroll();
	// TODO: Add your message handler code here
	
}

void CTipReaderView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	
	CEditView::OnVScroll(nSBCode, nPos, pScrollBar);
}

⌨️ 快捷键说明

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