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

📄 readersfdlg.cpp

📁 TXT阅读器,自定义字体,字体颜色,背景颜色及字体大小.支持书签保存及关闭自己动保存
💻 CPP
字号:
// ReaderSFDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ReaderSF.h"
#include "info.h"
#include "ReaderSFDlg.h"
#include "resource.h"

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


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReaderSFDlg dialog

CReaderSFDlg::CReaderSFDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CReaderSFDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CReaderSFDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	bHide=FALSE;
	
}

void CReaderSFDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CReaderSFDlg)
	DDX_Control(pDX, IDC_EDIT2, m_nouse);
	DDX_Control(pDX, IDC_EDIT1, m_edit);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CReaderSFDlg, CDialog)
//	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(CReaderSFDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_OPENFILE, OnOpenfile)
	ON_COMMAND(ID_SAVE, OnSave)
	ON_COMMAND(ID_SETCOLOR, OnSetcolor)
	ON_COMMAND(ID_SETFONT, OnSetfont)
	ON_COMMAND(ID_EXIT, OnExit)
	ON_COMMAND(ID_GETSAVE, OnGetsave)
	ON_WM_DESTROY()
	ON_COMMAND(ID_LOADDEF, OnLoaddef)
	ON_COMMAND(ID_ABOUT, OnAbout)
	ON_COMMAND(ID_FAST, OnFast)
	ON_WM_SIZE()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReaderSFDlg message handlers

BOOL CReaderSFDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	m_edit.SetReadOnly ();
	m_edit.OpenDefault ();
	//RegisterHotKey(NULL,11,MOD_WIN,37);
	RegisterHotKey(NULL,12,NULL,VK_F3);
	RegisterHotKey(this->m_hWnd ,13,NULL,VK_F2);
	

	GetWindowRect(&mret);
	int sx=GetSystemMetrics(SM_CXSCREEN);
	int sy=GetSystemMetrics(SM_CYSCREEN);
	::SetWindowPos(this->m_hWnd,HWND_TOPMOST  ,0 ,0 ,sx ,sy ,SWP_NOZORDER|SWP_NOREDRAW);
	m_nouse.SetFocus ();


	SetTimer(1,100,NULL);
	//ShowCursor(FALSE);
	//m_edit.HideCaret ();
	//this->RedrawWindow ();
//	this->SetFocus ();



	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CReaderSFDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CReaderSFDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CReaderSFDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



void CReaderSFDlg::OnOpenfile() 
{
 m_edit.OpenFile();	
}

void CReaderSFDlg::OnSave() 
{
	// TODO: Add your command handler code here
	
	m_edit.SaveMark ();
	
}

void CReaderSFDlg::OnSetcolor() 
{
	// TODO: Add your command handler code here
	m_edit.SetBackColor ();
}

void CReaderSFDlg::OnSetfont() 
{
	// TODO: Add your command handler code here
	m_edit.SetTextFont ();
	
}

void CReaderSFDlg::OnExit() 
{
	// TODO: Add your command handler code here
	OnOK();
	
}


void CReaderSFDlg::OnGetsave() 
{
	m_edit.LoadMark ();

//	FullScreen();
		
}



void CReaderSFDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	//m_edit.SaveDefault ();
	
	// TODO: Add your message handler code here
	
}


int CReaderSFDlg::DoModal() 
{
	
	//MessageBox("sdf");
	
//
	return CDialog::DoModal();
}

void CReaderSFDlg::OnLoaddef() 
{

	m_edit.OpenDefault ();
	//FullScreen();
}

BOOL CReaderSFDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class

	switch(pMsg->message )
	{
	case WM_HOTKEY:
		
		int k=pMsg->lParam /0x10000;
		switch(k )
		{
		case VK_F3:

			this->ShowHide();
			return TRUE;
		case VK_F2:
			this->OnFast ();
			return TRUE;
		}
		break;
	}
	return CDialog::PreTranslateMessage(pMsg);
}



void CReaderSFDlg::OnAbout() 
{
//	m_edit.sfMark.CurPos  =m_edit.GetScrollPos (SB_VERT);
//MessageBox("I won't tell you any thing about me","No About Me");
//m_edit.SetCur(m_edit.sfMark.CurPos );
	
}

void CReaderSFDlg::OnFast() 
{


	m_edit.sfMark .CurPos =m_edit.GetScrollPos(SB_VERT);
	m_edit.SaveDefault ();
}

void CReaderSFDlg::ShowHide()
{

	if(bHide)
	{
		ShowWindow(SW_SHOW);
		bHide=FALSE;
	}
	else 
	{
		ShowWindow(SW_HIDE);
		bHide=TRUE;
	}

}

void CReaderSFDlg::FullScreen()
{



}

void CReaderSFDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	if(nType==SIZE_RESTORED ||SIZE_MAXIMIZED )
	{
		m_edit.ReSize (cx,cy);
	//	this->GetWindowRect (&m_edit.sfMark .sfRECT );
	}
	// TODO: Add your message handler code here
	
}



void CReaderSFDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(!m_edit.bOpen )
	{
		SetWindowText("从来不信我和人类是孤独的");
		return;
	}
	int cLine=m_edit.GetLineCount ();
	int nLine=m_edit.sfMark .CurPos;
	char txt[MAX_PATH];
	GetWindowText(txt,MAX_PATH);
	char *p=strstr(txt," -  -[");
	if(p)p[0]='\0';
	sprintf(txt,"%s -  -[%d/%d]-  %d%%",txt,nLine,cLine,(int)(((float)nLine/(float)cLine)*100 ));
	SetWindowText(txt );

	
}

⌨️ 快捷键说明

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