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

📄 main.pas

📁 电子小说阅读器v2.68可用于阅读pdf.html等各种形式的文档
💻 PAS
📖 第 1 页 / 共 5 页
字号:

		77 :  //背景音乐  "M"
			ItemMP3.Click;

		86 :  //查看剪贴板  "V"
			ItemReadClip.Click;

		83 :  //设置  "S"
			ItemSetup.Click;

		78 :  //显示 / 隐藏书本  "N"
			ItemShow.Click;

		73 :  //最大化显示  "I"
			ItemMax.Click;

		90 :  //自动翻页测试  "Z"
			ItemRecordTime.Click;

		88 :  //退出  "X"
			ItemQuit.Click;

		67 :  //清除最新文件  "C"
			ItemClearNewItem.Click;

		192 :  //单、双页显示切换  "~"
		begin
			g_boolSinglePage := not g_boolSinglePage;
			Init_Window;
			Init_BackImage;  //初始化背景图片
			Init_Page;
			ChangeYe(g_nYeCurrent);
		end;

		48..57, 96..105 :  //打开最新文件  "1..9"
		begin
			if TimeKeyDelay.Enabled then
			begin  //转换键码的第二位
				if (Key >= 48) and (Key <= 57) then
					FnKeyOpenFile := FnKeyOpenFile * 10 + Key - 48
				else
					FnKeyOpenFile := FnKeyOpenFile * 10 + Key - 96;

				//关闭键盘延时
				TimeKeyDelay.Enabled := False;
			end
			else
			begin  //转换键码的第一位
				if (Key >= 48) and (Key <= 57) then
					FnKeyOpenFile := Key - 48
				else
					FnKeyOpenFile := Key - 96;

				//打开键盘延时
				TimeKeyDelay.Enabled := True;
				Exit;
			end;

			//打开最新文件
			if (FnKeyOpenFile >= 1) and (FnKeyOpenFile <= FstrNewFileList.Count) then
			begin
				OnItemNewFileClick(ItemNew.Items[FnKeyOpenFile - 1]);
			end;
		end;
	end;
end;

//---窗口隐藏事件---
procedure TFormMain.FormHide(Sender: TObject);
begin
	FboolIsMP3Show := FormMP3Play.Visible;
	FormMP3Play.Close;
end;

//---窗口关闭事件---
procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction);
var i : integer;
begin
	//保存设置
	//保存书本设置
	g_nBookLeft := FormMain.Left;      //窗口左位置
	g_nBookTop := FormMain.Top;        //窗口上位置
	g_nBookWidth := FormMain.Width;    //窗口宽度
	g_nBookHeight := FormMain.Height;  //窗口高度

	if FormMain.WindowState = wsMaximized then
	begin  //最大化显示,记录最大化以前备份的位置
		RegWriteInt(c_strRegPath, c_strRegBookLeft, FnBookLeftBeMax);
		RegWriteInt(c_strRegPath, c_strRegBookTop, FnBookTopBeMax);
		RegWriteInt(c_strRegPath, c_strRegBookWidth, FnBookWidthBeMax);
		RegWriteInt(c_strRegPath, c_strRegBookHeight, FnBookHeightBeMax);
	end
	else
	begin  //正常显示,记录正常的位置
		RegWriteInt(c_strRegPath, c_strRegBookLeft, g_nBookLeft);
		RegWriteInt(c_strRegPath, c_strRegBookTop, g_nBookTop);
		RegWriteInt(c_strRegPath, c_strRegBookWidth, g_nBookWidth);
		RegWriteInt(c_strRegPath, c_strRegBookHeight, g_nBookHeight);
	end;

	//保存页面设置
	RegWriteBool(c_strRegPath, c_strRegBookMoveFlag, g_boolMove);              //移动窗口标志
	RegWriteBool(c_strRegPath, c_strRegBookResizeFlag, g_boolResize);          //改变窗口大小标志
	RegWriteBool(c_strRegPath, c_strRegPageMoveFlag, g_boolPageMove);          //拖曳页面移动标志
	RegWriteBool(c_strRegPath, c_strRegPageYeFlag, g_boolPageYe);              //点击页面翻页标志
	RegWriteBool(c_strRegPath, c_strRegMaxFlag, g_boolMax);                    //最大化显示标志
	RegWriteBool(c_strRegPath, c_strRegSinglePage, g_boolSinglePage);          //单页显示标志
	RegWriteBool(c_strRegPath, c_strRegAutoPageMoveFlag, g_boolAutoPageMove);  //自动翻页标志
	RegWriteInt(c_strRegPath, c_strRegAutoVal, g_nAutoVal);                    //自动翻页时间

	RegWriteBool(c_strRegPath, c_strRegUnMimeCodeFlag, g_boolUnMimeCode);      //处理UnMimeCode标志
	RegWriteBool(c_strRegPath, c_strRegUnQPCodeFlag, g_boolUnQPCode);          //处理UnQPCode标志
	RegWriteBool(c_strRegPath, c_strRegUnHZCodeFlag, g_boolUnHZCode);          //处理UnHZCode标志
	RegWriteBool(c_strRegPath, c_strRegBIG5Flag, g_boolBIG5);                  //处理BIG5码标志
	RegWriteBool(c_strRegPath, c_strRegGBFlag, g_boolGB);                      //处理GB码标志
	RegWriteBool(c_strRegPath, c_strRegHtmlFlag, g_boolHtml);                  //处理html标志
	RegWriteBool(c_strRegPath, c_strRegChapFlag, g_boolChap);                  //智能分段标志
	RegWriteBool(c_strRegPath, c_strRegHangDFlag, g_boolHangD);                //行距加倍标志
	RegWriteBool(c_strRegPath, c_strRegUnderLineFlag, g_boolUnderLine);        //下划线标志
	RegWriteInt(c_strRegPath, c_strRegUnderLineColor, g_nUnderLineColor);      //下划线颜色
	RegWriteInt(c_strRegPath, c_strRegUnderLineOffset, g_nUnderLineOffset);    //下划线的距离
	RegWriteInt(c_strRegPath, c_strRegUnderLineThick, g_nUnderLineThick);      //下划线的宽度

	//保存页码设置
	RegWriteStr(c_strRegPath, c_strRegYe1Be, g_strYe1Be);          //页码1的前缀
	RegWriteStr(c_strRegPath, c_strRegYe1Af, g_strYe1Af);          //页码1的后缀
	RegWriteStr(c_strRegPath, c_strRegYe1Loc, g_strYe1Loc);        //页码1的位置
	RegWriteBool(c_strRegPath, c_strRegYe1Count, g_boolYe1Count);  //显示页码1的总页码标志

	RegWriteStr(c_strRegPath, c_strRegYe2Be, g_strYe1Be);          //页码2的前缀
	RegWriteStr(c_strRegPath, c_strRegYe2Af, g_strYe1Af);          //页码2的后缀
	RegWriteStr(c_strRegPath, c_strRegYe2Loc, g_strYe2Loc);        //页码2的位置
	RegWriteBool(c_strRegPath, c_strRegYe2Count, g_boolYe2Count);  //显示页码2的总页码标志

	//保存界面设置
	RegWriteBool(c_strRegPath, c_strRegBackBmpFlag, g_boolBackImage);                //背景图片标志
	RegWriteStr(c_strRegPath, c_strRegBackBmpFilename, g_strBackImageFilename);      //背景图片文件
	RegWriteBool(c_strRegPath, c_strRegLabelImageFlag, g_boolLabelImage);            //书签图片标志
	RegWriteStr(c_strRegPath, c_strRegLabelImageFilename, g_strLabelImageFilename);  //书签图片文件
	RegWriteBool(c_strRegPath, c_strRegShowTime, g_boolShowTime);                    //显示时间标志

	for i := 1 to c_nAlarmMax do
	begin
		RegWriteBool(c_strRegAlarmPath, c_strRegAlarmFlag + IntToStr(i), g_boolAlarm[i]);            //定时提醒标志
		RegWriteStr(c_strRegAlarmPath, c_strRegAlarmTime + IntToStr(i), TimeToStr(g_AlarmTime[i]));  //定时提醒时间
		RegWriteStr(c_strRegAlarmPath, c_strRegAlarmMsg + IntToStr(i), g_strAlarmMsg[i]);            //定时提醒内容
	end;

	RegWriteBool(c_strRegPath, c_strRegBtnFlat, g_boolFlat);                //浮动式按钮标志
	RegWriteBool(c_strRegPath, c_strRegViewCtrl, g_boolViewCtrl);           //显示界面控制按钮标志

	//保存系统设置
	RegWriteBool(c_strRegPath, c_strRegItemChangeFlag, g_boolChangeItem);   //最新文件菜单改变顺序标志
	RegWriteBool(c_strRegPath, c_strRegOpenFileFlag, g_boolOpenCloseFile);  //打开上次关闭时候的文件标志

	if (g_strFilename <> '') and (g_strFilename <> '说明文件') and (g_strFilename <> '剪贴板') then
	begin  //有打开的文件,则将该文件写入注册表
		RegWriteStr(c_strRegFilePath, c_strRegCloseFilename, g_strFilename);
		RegWriteInt(c_strRegFilePath, c_strRegCloseFilenameIndex, FnOpenNewIndex);
		RegWriteInt(c_strRegFilePath, c_strRegCloseFilenameYe, g_nYeCurrent + FnYeOffset);
	end
	else
	begin  //没有打开的文件,则将空记录写入注册表
		RegWriteStr(c_strRegFilePath, c_strRegCloseFilename, '');
		RegWriteInt(c_strRegFilePath, c_strRegCloseFilenameIndex, -1);
		RegWriteInt(c_strRegFilePath, c_strRegCloseFilenameYe, 0);
	end;

	RegWriteBool(c_strRegPath, c_strRegClearLabFlag, g_boolClearLabel);    //清除书签信息标志
	RegWriteBool(c_strRegPath, c_strRegClearNewFlag, g_boolClearNewItem);  //清除最新文件信息标志
	RegWriteBool(c_strRegPath, c_strRegSimpleItem, g_boolSimpleItem);       //简化最新文件菜单

	RegWriteBool(c_strRegPath, c_strRegAutoGB, g_boolAutoGB);              //自动转换为GB/BIG5码
	RegWriteBool(c_strRegPath, c_strRegYeViewFlag, g_boolYeView);          //页码显示标志

	//保存页码字体设置
	RegWriteStr(c_strRegFontPath, c_strRegYeFontName, g_YeFont.Name);        //字体名称
	RegWriteInt(c_strRegFontPath, c_strRegYeFontSize, g_YeFont.Size);        //字体大小
	RegWriteInt(c_strRegFontPath, c_strRegYeFontColor, g_YeFont.Color);      //字体颜色
	RegWriteInt(c_strRegFontPath, c_strRegYeFontCharset, g_YeFont.Charset);  //字体语言

	RegWriteBool(c_strRegFontPath, c_strRegYeFontStyle1, fsBold in g_YeFont.Style);       //粗体
	RegWriteBool(c_strRegFontPath, c_strRegYeFontStyle2, fsItalic in g_YeFont.Style);     //斜体
	RegWriteBool(c_strRegFontPath, c_strRegYeFontStyle3, fsStrikeOut in g_YeFont.Style);  //删除线
	RegWriteBool(c_strRegFontPath, c_strRegYeFontStyle4, fsUnderline in g_YeFont.Style);  //下划线

	//保存页面字体设置
	RegWriteStr(c_strRegFontPath, c_strRegPageFontName, g_PageFont.Name);        //字体名称
	RegWriteInt(c_strRegFontPath, c_strRegPageFontSize, g_PageFont.Size);        //字体大小
	RegWriteInt(c_strRegFontPath, c_strRegPageFontColor, g_PageFont.Color);      //字体颜色
	RegWriteInt(c_strRegFontPath, c_strRegPageFontCharset, g_PageFont.Charset);  //字体语言

	RegWriteBool(c_strRegFontPath, c_strRegPageFontStyle1, fsBold in g_PageFont.Style);       //粗体
	RegWriteBool(c_strRegFontPath, c_strRegPageFontStyle2, fsItalic in g_PageFont.Style);     //斜体
	RegWriteBool(c_strRegFontPath, c_strRegPageFontStyle3, fsStrikeOut in g_PageFont.Style);  //删除线
	RegWriteBool(c_strRegFontPath, c_strRegPageFontStyle4, fsUnderline in g_PageFont.Style);  //下划线

	RegWriteInt(c_strRegPath, c_strRegMaxFileRead, g_nMaxFileRead);  //最大容纳的文件容量

	//恢复窗口状态
	FboolBookResizeFlag := True;
	FormMain.Hide;
	FormMain.WindowState := wsNormal;

	//返回当前目录
	ChDir(g_strAppCurrentDir);

	//删除临时ZIP目录
	DeleteDirectory(g_strZipPassDir);
end;


//--------------------------------菜单事件--------------------------------------
//---右键主菜单弹出事件---
procedure TFormMain.MenuMainPopup(Sender: TObject);
var i : integer;
begin
	//调整最新文件菜单
	ItemNew.Enabled := (FstrNewFileList.Count > 0);

	//调整默认最新文件
	if (FstrNewFileList.Count > 0) then
	begin
		if (FnOpenNewIndex >= 0) and (FnOpenNewIndex <= FstrNewFileList.Count - 1) then
		begin
			ItemNew.Items[FnOpenNewIndex].Default := True;
		end
		else
		begin
			ItemNew.Items[0].Default := True;
			ItemNew.Items[0].Default := False;
		end;
	end;

	//调整文件处理菜单
	ItemBIG5.Checked := g_boolBIG5;
	ItemGB.Checked := g_boolGB;
	ItemHtml.Checked := g_boolHtml;
	ItemChap.Checked := g_boolChap;
	ItemHangD.Checked := g_boolHangD;
	ItemUnderLine.Checked := g_boolUnderLine;

	//调整编码处理菜单
	ItemUnMimeCode.Checked := g_boolUnMimeCode;
	ItemUnQPCode.Checked := g_boolUnQPCode;
	ItemUnHZCode.Checked := g_boolUnHZCode;

	//调整书签菜单
	ItemLabel.Enabled := (g_strFilename <> '') and (g_strFilename <> '剪贴板');
	ItemAddLabel.Enabled := not FboolCurrentLabel;
	ItemEditLabel.Enabled := FboolCurrentLabel;
	ItemDeleteLabel.Enabled := FboolCurrentLabel;
	ItemLabelInput.Enabled := ItemLabel.Enabled and (ItemLabelInput.Count > 0);

	//调整默认书签
	if ItemLabelInput.Enabled then
	begin
		for i := 0 to ItemLabelInput.Count - 1 do
		begin
			if g_boolSinglePage then
				ItemLabelInput.Items[i].Default := (g_nYeCurrent + FnYeOffset = FnLabelIndex[i])
			else
				ItemLabelInput.Items[i].Default := (g_nYeCurrent = FnLabelIndex[i]) or (g_nYeCurrent + 1 = FnLabelIndex[i]);
		end;
	end;

	//调整指定页菜单
	ItemInputYe.Enabled := (g_nYeCount > 2);

    //调整自动翻页菜单
	ItemAutoPageMove.Checked := g_boolAutoPageMove;
	ItemAutoPageMove.Caption := '自动翻页(' + IntToStr(g_nAutoVal) + '秒)';

    //调整背景音乐菜单
	ItemMP3.Enabled := g_boolExistMP3;

	//调整显示菜单
	if FormMain.Visible then
		ItemShow.Caption := '隐藏书本'
	else
		ItemShow.Caption := '显示书本';

	//调整最大化显示菜单
	g_boolMax := (FormMain.WindowState = wsMaximized);
	if g_boolMax then
		ItemMax.Caption := '恢复显示'
	else
		ItemMax.Caption := '最大化显示';

    //调整测试自动翻页菜单
	if FboolTestAutoPage then
		ItemRecordTime.Caption := '结束自动翻页测试...'
	else
		ItemRecordTime.Caption := '开始自动翻页测试';

    //调整清除最新文件菜单
	ItemClearNewItem.Enabled := (FstrNewFileList.Count > 0);
end;

//---打开文件菜单---
procedure TFormMain.ItemOpenClick(Sender: TObject);
var nOpenFileIndex : integer;     //打开文件索引
	nOpenFileCount : integer;     //打开文件总数
begin
    //显示主窗口
	ShowMainForm;

	//打开对话框,错误则退出
	with FDlgOpenTextFile do
	begin
		if isZipSubFile(g_strFilename) then
			InitialDir := ExtractFilePath(Copy(g_strFilename, 1, pos(c_strZipSpilt, g_strFilename) - 1))
		else
			InitialDir := ExtractFilePath(g_strFilename);

		if not Execute then
			Exit;
	end;

	//刷新主窗口
	UpdateMainForm;

    //设置参数
	FboolOpenFileFlag := False;  //写标志:没有正确打开文件
	FboolOpenLibFile := False;   //写标志:没有打开书库文件
	FnOpenFileCount := 0;        //文件计数写0

	//获得总文件数
	nOpenFileCount := FDlgOpenTextFile.Files.Count;
	if nOpenFileCount > c_nRegFilenameCount then
		nOpenFileCount := c_nRegFilenameCount;

	for nOpenFileIndex := nOpenFileCount - 1 downto 0 do
		OpenItemFile(FDlgOpenTextFile.Files.Strings[nOpenFileIndex]);  //打开菜单文件(仅把文件写入菜单)

	//判断是否打开了书库文件,并且删除原最新菜单
	if FboolOpenFileFlag and FboolOpenLibFile and g_boolClearNewItem then
	begin
        //删除最新文件菜单
		for nOpenFileIndex := FnOpenFileCount to FstrNewFileList.Count - 1 do
			DeleteNewItem(FnOpenFileCount);

		//改变最新文件索引
		if FnOpenNewIndex >= FnOpenFileCount then
			FnOpenNewIndex := -1;
	end;

	//正确打开文件,则打开参数文件中第一个文件
	if FboolOpenFileFlag then
	begin
		OnItemNewFileClick(ItemNew.Items[0]);
	end;
end;

//---保存文件菜单---
procedure TFormMain.ItemSaveClick(Sender: TObject);
var i, j : integer;
	s : string;
begin
    //显示主窗口
	ShowMainForm;

	//打开对话框,错误则退出
	with FDlgSaveTextFile do
	begin
		if isZipSubFile(g_strFilename) then
			InitialDir := ExtractFilePath(Copy(g_strFilename, 1, pos(c_strZipSpilt, g_strFilename) - 1))
		else
			InitialDir := ExtractFilePath(g_strFilename);

		if not Execute then
			Exit;
	end;

	//获得文件名
	s := FDlgSaveTextFile.Filename;

	//保存文件
	try
		AssignFile(FpFile, s);
		FileMode := 1;
		Rewrite(FpFile, 1);

		//初始化显示信息
		InitShowMess(0, FnCountTextRead, '保存文件');

		for i := 1 to FnCountTextRead do
		begin
			//显示完成度信息
			ShowMessPos(i);

			//写文件
			for j := 1 to Length(FstrTextReadReady[i]) do
				FstrDataBuf[j] := FstrTextReadReady[i][j];

			BlockWrite(FpFile, FstrDataBuf, Length(FstrTextReadReady[i]), FnReadnum);
		end;
	except
		Alert('保存文件 ' + s + ' 失败!' + c_strReturn + '请检查磁盘是否错误。');
	end;

	//关闭文件
	CloseFile(FpFile);

	//关闭显示信息
	CloseShowMess;
end;

//---打开最新文件---
procedure TFormMain.OnItemNewFileClick(Sender: TObject);
var
	strFilename : string;  //打开的文件名
	strZipFileList : TStringList;  //用于传送解压文件的文件列表
	strZipFilename, strZipSubFilename : string;  //ZIP文件名、子文件名
	i : integer;

	procedure InitOpenFile;
	var
		nCurrentLabel, nCountLabel : integer;
	begin  //初始化打开的文件
		//初始化打开文件的索引的文件名
		FnOpenNewIndex := TMenuItem(Sender).MenuIndex;
		g_strFilename := strFilename;

		//初始化处理设置
		if (LowerCase(ExtractFileExt(strFilename)) = '.htm') or

⌨️ 快捷键说明

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