📄 bookmark.cpp
字号:
// Bookmark.cpp : implementation file
//
#include "stdafx.h"
#include "ebook.h"
#include "Bookmark.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static CString liststr1;
DWORD ebookmark;
int kk;
/////////////////////////////////////////////////////////////////////////////
// Bookmark dialog
Bookmark::Bookmark(CWnd* pParent /*=NULL*/)
: CDialog(Bookmark::IDD, pParent)
{
//{{AFX_DATA_INIT(Bookmark)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void Bookmark::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Bookmark)
DDX_Control(pDX, IDC_LIST1, m_listbox);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Bookmark, CDialog)
//{{AFX_MSG_MAP(Bookmark)
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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Bookmark message handlers
BOOL Bookmark::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowPos(NULL,0,0,450,320,SWP_SHOWWINDOW );
ebookmark = RegisterWindowMessage(liststr1);//注册一个消息
CString flstr;
flstr.Format(L"%d",kk);
file=fopen("NandFlash\\11.txt","a+");//打开文件
DWORD aa;
fseek(file,0,SEEK_END );//把文件指针移到最后;
aa=ftell(file);//统计文件字节数
fseek(file,0,SEEK_SET );//把文件指针移到最前
int count=aa/20;//计算存储书签个数
for (int jj=0;jj<count;jj++)//读取文件数据是数据在listbox插入
{
char*p1;
p1=new char[20];
memset(p1,0,20);
fread(p1,sizeof(char),20,file);
CString liststr;
liststr=p1;
m_listbox.AddString(liststr);
}
fclose(file);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//********画背景*******//
void Bookmark::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC memory;
mycbitmap=new CBitmap;
mycbitmap->LoadBitmap(IDB_BITMAP2);
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);
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
//************设置按钮区域*********//
BOOL Bookmark::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 Bookmark::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (InRect(375,42,403,66,point.x,point.y))
{
OnButton1();
}
if (InRect(376,103,407,131,point.x,point.y))
{
OnButton2();
}
if (InRect(376,186,403,212,point.x,point.y))
{
OnButton3();
}
if (InRect(375,262,406,288,point.x,point.y))
{
OnButton4();
}
CDialog::OnLButtonUp(nFlags, point);
}
void Bookmark::GetPage(int a)
{
kk=a;
}
//******添加书签*********//
void Bookmark::OnButton1()
{
// TODO: Add your control notification handler code here
CString flstr;
flstr.Format(L"%d",kk);
file=fopen("NandFlash\\11.txt","a+");//创建文件,把书签信息保存
char*pp;
pp=new char[20];
_itoa(kk,pp,10);//把整形转换为字符型
fwrite(pp,sizeof(char),20,file);//写文件
fseek(file,-20,SEEK_END );//把指针移到最后向上偏移20个字节
char*p1;
p1=new char[20];
memset(p1,0,20);
fread(p1,sizeof(char),20,file);//对添加的数据进行阅读
CString liststr;
liststr=p1;
m_listbox.AddString(liststr);//把字符串添加到listbox
fclose(file);
}
//******删除书签*********//
void Bookmark::OnButton2()
{
// TODO: Add your control notification handler code here
int b=m_listbox.GetCurSel();
m_listbox.DeleteString(b);//在listbox列表上删除
int c=b+1;
file=fopen("NandFlash\\11.txt","a+");//打开文件
DWORD aa;
fseek(file,0,SEEK_END );
aa=ftell(file);
int count1=aa/20;
if (c==1)
{
char*p4;
p4=new char[(count1-1)*20+1];
memset(p4,0,(count1-1)*20+1);
fseek(file,20,SEEK_SET );
fread(p4,sizeof(char),(count1-1)*20,file);//把需要的文件内容保存在p4
fclose(file);
file=fopen("NandFlash\\11.txt","w");//对文件清空,创建新的空文件覆盖
fclose(file);
file=fopen("NandFlash\\11.txt","a+");
fwrite(p4,sizeof(char),(count1-1)*20,file);//对文件进行重写
fclose(file);
}
if (c>1&&c<count1)
{
char*p5;
p5=new char[(c-1)*20+1];
memset(p5,0,(c-1)*20+1);
char*p6;
p6=new char[(count1-c)*20+1];
memset(p6,0,(count1-c)*20+1);
fseek(file,0,SEEK_SET );
fread(p5,sizeof(char),(c-1)*20,file);//把需要的文件内容保存在p5
fseek(file,20*c,SEEK_SET );
fread(p6,sizeof(char),(count1-c)*20,file);//把需要的文件内容保存在p6
fclose(file);
file=fopen("NandFlash\\11.txt","w");//对文件清空,创建新的空文件覆盖
fclose(file);
file=fopen("NandFlash\\11.txt","a+");
fwrite(p5,sizeof(char),(c-1)*20,file);//对文件进行重写
fwrite(p6,sizeof(char),(count1-c)*20,file);//在后面对文件进行重写
fclose(file);
}
if (c==count1)
{
char*p8;
p8=new char[(c-1)*20+1];
memset(p8,0,(c-1)*20+1);
fseek(file,0,SEEK_SET );
fread(p8,sizeof(char),(c-1)*20,file);
fclose(file);
file=fopen("NandFlash\\11.txt","w");
fclose(file);
file=fopen("NandFlash\\11.txt","a+");
fwrite(p8,sizeof(char),(c-1)*20,file);
fclose(file);
}
}
//********书签跳转***********//
void Bookmark::OnButton3()
{
// TODO: Add your control notification handler code here
HWND hWnd;
int b=m_listbox.GetCurSel() ;
int n = m_listbox.GetTextLen( b );
m_listbox.GetText(b,liststr1);
char *p2;
p2=new char[n+1];
wcstombs(p2,liststr1,n);
hWnd=::FindWindow(0,L"电子书");
::PostMessage(hWnd,ebookmark,0,(LPARAM)p2);
DestroyWindow();
}
//*******关闭窗口*******//
void Bookmark::OnButton4()
{
// TODO: Add your control notification handler code here
DestroyWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -