282 lines
6.9 KiB
C++
Executable File
282 lines
6.9 KiB
C++
Executable File
// EBookDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "EBook.h"
|
|
#include "EBookDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CEBookDlg dialog
|
|
|
|
CEBookDlg::CEBookDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CEBookDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CEBookDlg)
|
|
//}}AFX_DATA_INIT
|
|
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
|
|
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
|
|
|
// 加载资源文件
|
|
theApp.LoadLanguageRes(theApp.GetLanguage());
|
|
|
|
m_txtFont.CreateFont(18,0,0,0,FW_BOLD,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,
|
|
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,_T("Arial"));
|
|
m_BookFont.CreateFont(16,0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,
|
|
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,_T("Arial"));
|
|
|
|
//WCHAR strRes[MAX_PATH];
|
|
//CString(LoadString(theApp.GetResourceLib(),IDS_MUSICPLAYER_TITLE,strRes,MAX_PATH));
|
|
|
|
m_TitleText = L"";
|
|
|
|
// 初始化背景画刷
|
|
CBitmap tmpBmp;
|
|
// 从资源中加载背景图片
|
|
tmpBmp.LoadBitmap(IDB_EBOOK_WND);
|
|
|
|
m_BgDC.CreateCompatibleDC(NULL);
|
|
m_BgDC.SelectObject(&tmpBmp);
|
|
|
|
tmpBmp.DeleteObject();
|
|
// 组合框背景
|
|
tmpBmp.LoadBitmap(IDB_EBOOK_BOOK);
|
|
m_BookBrush.CreatePatternBrush(&tmpBmp);
|
|
// 清理资源
|
|
tmpBmp.DeleteObject();
|
|
|
|
m_BookTxtColor = RGB(255,255,255);
|
|
|
|
}
|
|
|
|
CEBookDlg::~CEBookDlg()
|
|
{
|
|
m_BgDC.DeleteDC();
|
|
m_MemDC.DeleteDC();
|
|
|
|
m_txtFont.DeleteObject();
|
|
m_BookFont.DeleteObject();
|
|
|
|
}
|
|
|
|
void CEBookDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CEBookDlg)
|
|
DDX_Control(pDX, IDC_EDIT_BOOK, m_txtBook);
|
|
DDX_Control(pDX, IDC_BUTTON_UP, m_butUp);
|
|
DDX_Control(pDX, IDC_BUTTON_OPEN, m_butOpen);
|
|
DDX_Control(pDX, IDC_BUTTON_EXIT, m_butExit);
|
|
DDX_Control(pDX, IDC_BUTTON_DOWN, m_butDown);
|
|
DDX_Control(pDX, IDC_BUTTON_BACK, m_butBack);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CEBookDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CEBookDlg)
|
|
ON_WM_PAINT()
|
|
ON_WM_ERASEBKGND()
|
|
ON_WM_CTLCOLOR()
|
|
ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
|
|
ON_BN_CLICKED(IDC_BUTTON_BACK, OnButtonBack)
|
|
ON_BN_CLICKED(IDC_BUTTON_DOWN, OnButtonDown)
|
|
ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
|
|
ON_BN_CLICKED(IDC_BUTTON_UP, OnButtonUp)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CEBookDlg message handlers
|
|
|
|
BOOL CEBookDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
// 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
|
|
|
|
CenterWindow(GetDesktopWindow()); // center to the hpc screen
|
|
|
|
// TODO: Add extra initialization here
|
|
MoveWindow(0,0,320,240);
|
|
m_butExit.MoveWindow(283,7,25,25);
|
|
m_butExit.LoadBitmaps(IDB_EBOOK_CLOSE,IDB_EBOOK_CLOSED);
|
|
|
|
m_butUp.MoveWindow(271,37,46,46);
|
|
m_butUp.LoadBitmaps(IDB_EBOOK_UP,IDB_EBOOK_UPD,IDB_EBOOK_UPDIS);
|
|
|
|
m_butDown.MoveWindow(271,87,46,46);
|
|
m_butDown.LoadBitmaps(IDB_EBOOK_DOWN,IDB_EBOOK_DOWND,IDB_EBOOK_DOWNDIS);
|
|
|
|
m_butOpen.MoveWindow(271,137,46,46);
|
|
m_butOpen.LoadBitmaps(IDB_EBOOK_OPEN,IDB_EBOOK_OPEND);
|
|
|
|
m_butBack.MoveWindow(271,187,46,46);
|
|
m_butBack.LoadBitmaps(IDB_EBOOK_BACK,IDB_EBOOK_BACKD,IDB_EBOOK_BACKDIS);
|
|
|
|
m_txtBook.MoveWindow(11,22,249,183);
|
|
m_txtBook.SetFont(&m_BookFont);
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
}
|
|
|
|
|
|
|
|
void CEBookDlg::OnPaint()
|
|
{
|
|
CPaintDC dc(this); // device context for painting
|
|
|
|
// TODO: Add your message handler code here
|
|
|
|
dc.BitBlt(0,0,320,240,&m_BgDC,0,0,SRCCOPY);
|
|
if (!m_TitleText.IsEmpty())
|
|
{
|
|
dc.SetBkMode(TRANSPARENT);
|
|
dc.SetTextColor(RGB(0,0,255));
|
|
dc.SelectObject(m_txtFont);
|
|
dc.DrawText(m_TitleText,CRect(10,208,258,230),DT_VCENTER|DT_CENTER);
|
|
}
|
|
|
|
// Do not call CDialog::OnPaint() for painting messages
|
|
}
|
|
|
|
BOOL CEBookDlg::OnEraseBkgnd(CDC* pDC)
|
|
{
|
|
// TODO: Add your message handler code here and/or call default
|
|
return TRUE;
|
|
//return CDialog::OnEraseBkgnd(pDC);
|
|
}
|
|
|
|
HBRUSH CEBookDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
|
{
|
|
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
|
|
// TODO: Change any attributes of the DC here
|
|
if (nCtlColor == CTLCOLOR_STATIC)
|
|
{
|
|
pDC->SetBkMode(TRANSPARENT);
|
|
pDC->SetTextColor(m_BookTxtColor);
|
|
return m_BookBrush;
|
|
}
|
|
// TODO: Return a different brush if the default is not desired
|
|
return hbr;
|
|
}
|
|
|
|
void CEBookDlg::OnButtonOpen()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
COpenBookFileDlg fileDlg;
|
|
|
|
if (fileDlg.DoModal() == IDOK)
|
|
{
|
|
m_SourceFile = fileDlg.GetFilePath();
|
|
m_txtBook.SetWindowText(ReadFile(m_SourceFile));
|
|
m_TitleText = GetFileName(m_SourceFile);
|
|
|
|
m_butDown.EnableWindow(TRUE);
|
|
m_butUp.EnableWindow(TRUE);
|
|
m_butBack.EnableWindow(TRUE);
|
|
|
|
InvalidateRect(CRect(10,208,258,230));
|
|
}
|
|
}
|
|
|
|
void CEBookDlg::OnButtonBack()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
m_txtBook.LineScroll(-(m_txtBook.GetFirstVisibleLine() + 1));
|
|
}
|
|
|
|
void CEBookDlg::OnButtonDown()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
int line = GetLineHeight(&m_BookFont);
|
|
|
|
m_txtBook.LineScroll(line);
|
|
|
|
}
|
|
|
|
void CEBookDlg::OnButtonExit()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
EndDialog(IDOK);
|
|
}
|
|
|
|
void CEBookDlg::OnButtonUp()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
int line = GetLineHeight(&m_BookFont);
|
|
|
|
m_txtBook.LineScroll(-line);
|
|
}
|
|
|
|
CString CEBookDlg::ReadFile(CString sFileName)
|
|
{
|
|
char* lpData = NULL;
|
|
int len = 0;
|
|
CString FileTxt;
|
|
CFile file;
|
|
|
|
FileTxt.Empty();
|
|
|
|
if(!file.Open(sFileName,CFile::modeRead))
|
|
{
|
|
MessageBox(L"读取文件错误!");
|
|
}
|
|
else
|
|
{
|
|
// 读取文件内容
|
|
len = file.GetLength();
|
|
lpData = new char[len + 1];
|
|
memset(lpData,0,len+1);
|
|
file.Read(lpData,len);
|
|
file.Close();
|
|
FileTxt = lpData;
|
|
delete lpData;
|
|
}
|
|
// 返回文件字符串
|
|
return FileTxt;
|
|
}
|
|
|
|
int CEBookDlg::GetLineHeight(CFont* pFont)
|
|
{
|
|
int Height = 0;
|
|
CDC* pDC = m_txtBook.GetDC();
|
|
CRect txtRect;
|
|
pDC->SelectObject(pFont);
|
|
pDC->DrawText(L"我们",&txtRect,DT_CALCRECT);
|
|
|
|
Height = txtRect.Height();
|
|
CRect wndRect;
|
|
m_txtBook.GetClientRect(wndRect);
|
|
|
|
return wndRect.Height() / Height;
|
|
}
|
|
|
|
CString CEBookDlg::GetFileName(CString strFileName)
|
|
{
|
|
CString FileExt;
|
|
FileExt.Empty();
|
|
// 文件名长度
|
|
int strLen = strFileName.GetLength() - 1;
|
|
|
|
for(int i = strLen; i >= 0; i--)
|
|
{
|
|
// 查找文件名中最好一个'.'
|
|
if(strFileName.GetAt(i) == '\\')
|
|
{
|
|
// 提取文件扩展名
|
|
FileExt = strFileName.Right(strLen - i);
|
|
break;
|
|
}
|
|
}
|
|
return FileExt;
|
|
}
|