?? ebookdlg.cpp
字號:
// ebookDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ebook.h"
#include "ebookDlg.h"
#include "Bookmark.h"
#include "Goto.h"
#include <vector>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int t=0;
DWORD ii;
extern DWORD ebookmark;
Bookmark *mymark;
Goto mygoto;
CString pagecount;
/////////////////////////////////////////////////////////////////////////////
// CEbookDlg dialog
CEbookDlg::CEbookDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEbookDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEbookDlg)
m_editstr = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CEbookDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEbookDlg)
DDX_Control(pDX, IDC_EDIT2, m_edit2);
DDX_Control(pDX, IDC_STATIC1, m_static);
DDX_Control(pDX, IDC_EDIT1, m_edit);
DDX_Text(pDX, IDC_EDIT1, m_editstr);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEbookDlg, CDialog)
//{{AFX_MSG_MAP(CEbookDlg)
ON_WM_PAINT()
ON_WM_LBUTTONUP()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
//}}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
SetWindowPos(NULL,0,0,800,480,SWP_SHOWWINDOW );
m_edit.SetWindowPos(NULL,28,20,622,355,SWP_SHOWWINDOW );
m_edit2.SetWindowPos(NULL,697,90,80,30,SWP_SHOWWINDOW );
m_static.SetWindowPos(NULL,697,50,80,30,SWP_SHOWWINDOW );
SetWindowText(L"電子書");
SetWindowPos(NULL,0,0,800,480,SWP_SHOWWINDOW );
m_edit.SetWindowPos(NULL,28,20,622,355,SWP_SHOWWINDOW );
m_edit2.SetWindowPos(NULL,697,90,80,30,SWP_SHOWWINDOW );
m_static.SetWindowPos(NULL,697,50,80,30,SWP_SHOWWINDOW );
CString state=L"succeed";
HWND MyhWnd;
COPYDATASTRUCT MyCopyStr;
MyCopyStr.dwData = (DWORD)m_hWnd;//用戶定義數(shù)據(jù)
MyCopyStr.lpData = state.GetBuffer(state.GetLength());//指向數(shù)據(jù)的指針
MyCopyStr.cbData = state.GetLength()*2;//數(shù)據(jù)大小
MyhWnd = ::FindWindow(NULL,L"電子書界面");
if(MyhWnd!=NULL)
{
::SendMessage(MyhWnd,WM_COPYDATA,0,(LPARAM)&MyCopyStr);
}
return TRUE; // return TRUE unless you set the focus to a control
}
LRESULT CEbookDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if(message == WM_COPYDATA)//接收消息得到雙擊的路徑名
{
txtstr = (LPCTSTR)((PCOPYDATASTRUCT)lParam)->lpData;
ReadFile(txtstr);
}
if(message==ebookmark)//接受書簽的數(shù)據(jù)進行轉跳
{
char*p3;
p3=new char[20];
p3=(char*)lParam;
t=atoi(p3)-1;
fp=new CFile;
fp->Open(mystring,fp->modeRead,NULL);
char *p ;
p=new char[ii-t*992+1];
memset(p,0,ii-t*992+1);
fp->Seek(t*992,CFile::begin);
fp->Read(p,ii-t*992);
m_editstr=p;
SetDlgItemText(IDC_EDIT1,m_editstr);
fp->Close( );
CString page;
page.Format(L"第%d頁",t+1);
m_edit2.SetWindowText(page);
mymark->GetPage(t+1);
}
return CDialog::WindowProc(message, wParam, lParam);
}
void CEbookDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CDC memory;
mycbitmap=new CBitmap;
mycbitmap->LoadBitmap(IDB_BITMAP1);
memory.CreateCompatibleDC(&dc);
memory.SelectObject(mycbitmap);
RECT myrect;
GetWindowRect(&myrect);
dc.BitBlt(0,0,myrect.right-myrect.left,myrect.bottom-myrect.top,&memory,0,0,SRCCOPY);
// Do not call CDialog::OnPaint() for painting messages
}
BOOL CEbookDlg::InRect(int left, int top, int right, int bottom, int px, int py)
{
if((left < 0) || (left > 800))
return FALSE;
if((right < 0) || (right > 800))
return FALSE;
if((top < 0) || (top > 480))
return FALSE;
if((bottom < 0) || (bottom > 480))
return FALSE;
if((px < 0) || (px > 800))
return FALSE;
if((py < 0) || (py > 480))
return FALSE;
if((px>=left)&&(px<=right) && (py>=top)&&(py<=bottom))
return TRUE;
return FALSE;
}
void CEbookDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (InRect(712,140,746,170,point.x,point.y))
{
OnButton1();
}
if (InRect(709,221,750,244,point.x,point.y))
{
OnButton2();
}
if (InRect(710,300,746,323,point.x,point.y))
{
OnButton3();
}
if (InRect(710,375,751,400,point.x,point.y))
{
OnButton4();
}
if (InRect(158,401,193,428,point.x,point.y))
{
OnButton5();
}
if (InRect(258,401,297,426,point.x,point.y))
{
OnButton6();
}
if (InRect(371,395,412,426,point.x,point.y))
{
OnButton7();
}
if (InRect(480,401,518,422,point.x,point.y))
{
OnButton8();
}
if (InRect(66,401,103,427,point.x,point.y))
{
OnButton9();
}
CDialog::OnLButtonUp(nFlags, point);
}
//********讀文件*********//
void CEbookDlg::ReadFile(CString a)
{
CString pagecount;
CString page;
mystring=a;
fp=new CFile;//讀文件可以用CFile,寫文件不行
fp->Open(mystring,fp->modeRead,NULL);//打開文件
char *p ;
ii=fp->SeekToEnd( ); //把指針移到最后返回問文件的字節(jié)數(shù)
p=new char[ii+1];
memset(p,0,ii+1);
fp->SeekToBegin();//把指針移到最前
fp->Read(p,ii);
m_editstr=p;
SetDlgItemText(IDC_EDIT1,m_editstr);//在編輯框進行顯示
fp->Close( );
pagecount.Format(L"共%d頁",ii/992+1);//把每頁定義為992字節(jié),計算文件有多少頁
m_static.SetWindowText(pagecount);//把共有多少頁顯示出來
page.Format(L"第%d頁",t+1);
m_edit2.SetWindowText(page);//顯示當前文件為第幾頁
mymark=new Bookmark();
mymark->GetPage(t+1);//把頁數(shù)傳到書簽
}
//*******上行********//
void CEbookDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_edit.SendMessage(EM_SCROLL,SB_LINEUP,0);//進行上翻一行直接發(fā)消息
}
//*******下行********//
void CEbookDlg::OnButton2()
{
// TODO: Add your control notification handler code here
m_edit.SendMessage(EM_SCROLL,SB_LINEDOWN,0);//進行下翻一行直接發(fā)消息
}
//*******上頁********//
void CEbookDlg::OnButton3()
{
// TODO: Add your control notification handler code here
if(t>=1)
{
t--;
fp=new CFile;
fp->Open(mystring,fp->modeRead,NULL);
char *p ;
p=new char[ii-t*992+1];
memset(p,0,ii-t*992+1);
fp->Seek(t*992,CFile::begin);
fp->Read(p,ii-t*992);
m_editstr=p;
SetDlgItemText(IDC_EDIT1,m_editstr);
fp->Close( );
CString page;
page.Format(L"第%d頁",t+1);
m_edit2.SetWindowText(page);
mymark->GetPage(t+1);
}
}
//*******下頁********//
void CEbookDlg::OnButton4()
{
// TODO: Add your control notification handler code here
if(t<ii/992)
{
t++;
fp=new CFile;
fp->Open(mystring,fp->modeRead,NULL);
char *p ;
p=new char[ii-t*992+1];
memset(p,0,ii-t*992+1);
fp->Seek(t*992,CFile::begin);
fp->Read(p,ii-t*992);
m_editstr=p;
SetDlgItemText(IDC_EDIT1,m_editstr);
fp->Close( );
CString page;
page.Format(L"第%d頁",t+1);
m_edit2.SetWindowText(page);
mymark->GetPage(t+1);
}
}
//********轉跳*******//
void CEbookDlg::OnButton5()
{
// TODO: Add your control notification handler code here
if(mygoto.DoModal()==IDOK)
{
CString mygo;
int b;
char *a;
a=new char[10];
mygo=mygoto.m_goedit;
mygoto.m_goedit.Empty();
wcstombs(a,mygo,10);//把String轉換為字符型
b=atoi(a);//字符型變?yōu)檎? t=b-1;
fp=new CFile;
fp->Open(mystring,fp->modeRead,NULL);
char *p ;
p=new char[ii-t*992+1];
memset(p,0,ii-t*992+1);
fp->Seek(t*992,CFile::begin);//按照跳轉偏移量讀文件
fp->Read(p,ii-t*992);
m_editstr=p;
SetDlgItemText(IDC_EDIT1,m_editstr);
fp->Close( );
m_edit2.SetWindowText(L"第"+mygo+L"頁");
mymark->GetPage(b);//跳轉頁數(shù)給書簽
}
}
//********全屏**********//
void CEbookDlg::OnButton6()
{
// TODO: Add your control notification handler code here
m_edit.SetWindowPos(NULL,0,0,800,480,SWP_SHOWWINDOW );
}
//********書簽**********//
void CEbookDlg::OnButton7()
{
// TODO: Add your control notification handler code here
mymark=new Bookmark();
mymark->Create(IDD_DIALOG1);
mymark->SetWindowText(L"書簽");
mymark->ShowWindow(TRUE);
}
//********退出**********//
void CEbookDlg::OnButton8()
{
// TODO: Add your control notification handler code here
DestroyWindow();
}
//********返回**********//
void CEbookDlg::OnButton9()
{
// TODO: Add your control notification handler code here
HWND MyhWnd;
MyhWnd = ::FindWindow(NULL,L"電子書界面");
::SetForegroundWindow(MyhWnd);
}
//*********為封裝新的EDIT消息,建立的函數(shù)實現(xiàn)下翻*********//
void CEbookDlg::Down()
{
if(t<ii/992)
{
t++;
fp=new CFile;
fp->Open(mystring,fp->modeRead,NULL);
char *p ;
p=new char[ii-t*992+1];
memset(p,0,ii-t*992+1);
fp->Seek(t*992,CFile::begin);
fp->Read(p,ii-t*992);
m_editstr=p;
SetDlgItemText(IDC_EDIT1,m_editstr);
fp->Close( );
CString page;
page.Format(L"第%d頁",t+1);
m_edit2.SetWindowText(page);
mymark->GetPage(t+1);
}
}
void CEbookDlg::Up()
{
if(t>=1)
{
t--;
fp=new CFile;
fp->Open(mystring,fp->modeRead,NULL);
char *p ;
p=new char[ii-t*992+1];
memset(p,0,ii-t*992+1);
fp->Seek(t*992,CFile::begin);
fp->Read(p,ii-t*992);
m_editstr=p;
SetDlgItemText(IDC_EDIT1,m_editstr);
fp->Close( );
CString page;
page.Format(L"第%d頁",t+1);
m_edit2.SetWindowText(page);
mymark->GetPage(t+1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -