?? main.pas
字號:
//打開鍵盤延時
TimeKeyDelay.Enabled := True;
Exit;
end;
//打開最新文件
if (FnKeyOpenFile > 0) and (FnKeyOpenFile <= ItemNew.Count - 2) then
begin
OnItemNewFileClick(ItemNew.Items[FnKeyOpenFile - 1]);
end;
end;
end;
end;
//---窗口隱藏事件---
procedure TFormMain.FormHide(Sender: TObject);
begin
FboolIsMP3Show := FormMP3Play.Visible;
FormMP3Play.Close;
end;
//---窗口關(guān)閉事件---
procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction);
var i : integer;
begin
//保存設(shè)置
//保存書本設(shè)置
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;
//保存頁面設(shè)置
RegWriteBool(c_strRegPath, c_strRegBookMoveFlag, g_boolMove); //移動窗口標(biāo)志
RegWriteBool(c_strRegPath, c_strRegBookResizeFlag, g_boolResize); //改變窗口大小標(biāo)志
RegWriteBool(c_strRegPath, c_strRegPageMoveFlag, g_boolPageMove); //拖曳頁面移動標(biāo)志
RegWriteBool(c_strRegPath, c_strRegPageYeFlag, g_boolPageYe); //點擊頁面翻頁標(biāo)志
RegWriteBool(c_strRegPath, c_strRegMaxFlag, g_boolMax); //最大化顯示標(biāo)志
RegWriteBool(c_strRegPath, c_strRegAutoPageMoveFlag, g_boolAutoPageMove); //自動翻頁標(biāo)志
RegWriteInt(c_strRegPath, c_strRegAutoVal, g_nAutoVal); //自動翻頁時間
RegWriteBool(c_strRegPath, c_strRegBIG5Flag, g_boolBIG5); //處理BIG5碼標(biāo)志
RegWriteBool(c_strRegPath, c_strRegGBFlag, g_boolGB); //處理GB碼標(biāo)志
RegWriteBool(c_strRegPath, c_strRegHtmlFlag, g_boolHtml); //處理html標(biāo)志
RegWriteBool(c_strRegPath, c_strRegChapFlag, g_boolChap); //智能分段標(biāo)志
RegWriteBool(c_strRegPath, c_strRegHangDFlag, g_boolHangD); //行距加倍標(biāo)志
RegWriteBool(c_strRegPath, c_strRegUnderLineFlag, g_boolUnderLine); //下劃線標(biāo)志
RegWriteInt(c_strRegPath, c_strRegUnderLineColor, g_nUnderLineColor); //下劃線顏色
RegWriteInt(c_strRegPath, c_strRegUnderLineOffset, g_nUnderLineOffset); //下劃線的距離
RegWriteInt(c_strRegPath, c_strRegUnderLineThick, g_nUnderLineThick); //下劃線的寬度
//保存頁碼設(shè)置
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的總頁碼標(biāo)志
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的總頁碼標(biāo)志
//保存系統(tǒng)設(shè)置
RegWriteBool(c_strRegPath, c_strRegBackBmpFlag, g_boolBackImage); //背景圖片標(biāo)志
RegWriteStr(c_strRegPath, c_strRegBackBmpFilename, g_strBackImageFilename); //背景圖片文件
RegWriteBool(c_strRegPath, c_strRegLabelImageFlag, g_boolLabelImage); //書簽圖片標(biāo)志
RegWriteStr(c_strRegPath, c_strRegLabelImageFilename, g_strLabelImageFilename); //書簽圖片文件
RegWriteBool(c_strRegPath, c_strRegShowTime, g_boolShowTime); //顯示時間標(biāo)志
for i := 1 to c_nAlarmMax do
begin
RegWriteBool(c_strRegAlarmPath, c_strRegAlarmFlag + IntToStr(i), g_boolAlarm[i]); //定時提醒標(biāo)志
RegWriteStr(c_strRegAlarmPath, c_strRegAlarmTime + IntToStr(i), TimeToStr(g_AlarmTime[i])); //定時提醒時間
RegWriteStr(c_strRegAlarmPath, c_strRegAlarmMsg + IntToStr(i), g_strAlarmMsg[i]); //定時提醒內(nèi)容
end;
RegWriteBool(c_strRegPath, c_strRegBtnFlat, g_boolFlat); //浮動式按鈕標(biāo)志
RegWriteBool(c_strRegPath, c_strRegViewCtrl, g_boolViewCtrl); //顯示界面控制按鈕標(biāo)志
RegWriteBool(c_strRegPath, c_strRegItemChangeFlag, g_boolChangeItem); //最新文件菜單改變順序標(biāo)志
RegWriteBool(c_strRegPath, c_strRegOpenFileFlag, g_boolOpenCloseFile); //打開上次關(guān)閉時候的文件標(biāo)志
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);
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); //清除書簽信息標(biāo)志
RegWriteBool(c_strRegPath, c_strRegClearNewFlag, g_boolClearNewItem); //清除最新文件信息標(biāo)志
RegWriteBool(c_strRegPath, c_strRegAutoGB, g_boolAutoGB); //自動轉(zhuǎn)換為GB/BIG5碼
RegWriteBool(c_strRegPath, c_strRegYeViewFlag, g_boolYeView); //頁碼顯示標(biāo)志
//保存頁碼字體設(shè)置
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); //下劃線
//保存頁面字體設(shè)置
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); //下劃線
//恢復(fù)窗口狀態(tài)
FboolBookResizeFlag := True;
FormMain.Hide;
FormMain.WindowState := wsNormal;
//返回當(dāng)前目錄
ChDir(g_strAppCurrentDir);
//刪除臨時Zip目錄
DeleteDirectory(g_strZipPassDir);
end;
//--------------------------------菜單事件--------------------------------------
//---右鍵主菜單彈出事件---
procedure TFormMain.MenuMainPopup(Sender: TObject);
var i : integer;
begin
//調(diào)整最新文件菜單
ItemNew.Enabled := (ItemNew.Count > 2);
//調(diào)整默認(rèn)最新文件
if ItemNew.Enabled then
begin
if (FnOpenNewIndex >= 0) and (FnOpenNewIndex < ItemNew.Count -2) then
begin
ItemNew.Items[FnOpenNewIndex].Default := True;
end
else
begin
ItemNew.Items[0].Default := True;
ItemNew.Items[0].Default := False;
end;
end;
//調(diào)整文件處理菜單
ItemBIG5.Checked := g_boolBIG5;
ItemGB.Checked := g_boolGB;
ItemHtml.Checked := g_boolHtml;
ItemChap.Checked := g_boolChap;
ItemHangD.Checked := g_boolHangD;
ItemUnderLine.Checked := g_boolUnderLine;
//調(diào)整書簽菜單
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);
//調(diào)整默認(rèn)書簽
if ItemLabelInput.Enabled then
for i := 0 to ItemLabelInput.Count - 1 do
ItemLabelInput.Items[i].Default := (g_nYeCurrent = FnLabelIndex[i]) or (g_nYeCurrent + 1 = FnLabelIndex[i]);
//調(diào)整指定頁菜單
ItemInputYe.Enabled := (g_nYeCount > 2);
//調(diào)整自動翻頁菜單
ItemAutoPageMove.Checked := g_boolAutoPageMove;
ItemAutoPageMove.Caption := '自動翻頁(' + IntToStr(g_nAutoVal) + '秒)';
//調(diào)整背景音樂菜單
ItemMP3.Enabled := g_boolExistMP3;
//調(diào)整顯示菜單
if FormMain.Visible then
ItemShow.Caption := '隱藏書本'
else
ItemShow.Caption := '顯示書本';
//調(diào)整最大化顯示菜單
g_boolMax := (FormMain.WindowState = wsMaximized);
if g_boolMax then
ItemMax.Caption := '恢復(fù)顯示'
else
ItemMax.Caption := '最大化顯示';
//調(diào)整測試自動翻頁菜單
if FboolTestAutoPage then
ItemRecordTime.Caption := '結(jié)束自動翻頁測試...'
else
ItemRecordTime.Caption := '開始自動翻頁測試';
//調(diào)整清除最新文件菜單
ItemClearNewItem.Enabled := ItemNew.Enabled;
end;
//---打開文件菜單---
procedure TFormMain.ItemOpenClick(Sender: TObject);
var nOpenFileIndex : integer; //打開文件索引
nOpenFileCount : integer; //打開文件總數(shù)
begin
//顯示主窗口
ShowMainForm;
//打開對話框,錯誤則退出
with FDlgOpenTextFile do
begin
if pos('|', g_strFilename) > 0 then
InitialDir := ExtractFilePath(Copy(g_strFilename, 1, pos('|', g_strFilename) - 1))
else
InitialDir := ExtractFilePath(g_strFilename);
if not Execute then
Exit;
end;
//刷新主窗口
UpdateMainForm;
//設(shè)置參數(shù)
FboolOpenFileFlag := False; //寫標(biāo)志:沒有正確打開文件
FboolOpenLibFile := False; //寫標(biāo)志:沒有打開書庫文件
FnOpenFileCount := 0; //文件計數(shù)寫0
//獲得總文件數(shù)
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 ItemNew.Count - 3 do
DeleteNewItem(FnOpenFileCount);
//改變最新文件索引
if FnOpenNewIndex >= FnOpenFileCount then
FnOpenNewIndex := -1;
end;
//正確打開文件,則打開參數(shù)文件中第一個文件
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 pos('|', g_strFilename) > 0 then
InitialDir := ExtractFilePath(Copy(g_strFilename, 1, pos('|', 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;
//關(guān)閉文件
CloseFile(FpFile);
//關(guān)閉顯示信息
CloseShowMess;
end;
//---打開最新文件---
procedure TFormMain.OnItemNewFileClick(Sender: TObject);
var strFilename : string; //打開的文件名
strZipFileList : TStringList; //用于傳送解壓文件的文件列表
strZipFilename, strZipSubFilename : string; //zip文件
i : integer;
s : string;
procedure InitOpenFile;
var
nCurrentLabel, nCountLabel : integer;
begin //初始化打開的文件
//初始化打開文件的索引的文件名
FnOpenNewIndex := TMenuItem(Sender).MenuIndex;
g_strFilename := strFilename;
//初始化處理設(shè)置
if (LowerCase(ExtractFileExt(strFilename)) = '.htm') or
(LowerCase(ExtractFileExt(strFilename)) = '.html') then
g_boolHtml := True;
//初始化書簽變量
ItemLabelInput.Clear;
nCurrentLabel := RegReadInt(c_strRegFilePath,
c_strRegFilenameSort + IntToStr(FnOpenNewIndex),
-1);
if (nCurrentLabel >= 0) then
begin
for nCountLabel := 0 to c_nRegLabelCount - 1 do
begin
//讀入書簽設(shè)置
FnLabelIndex[nCountLabel] := RegReadInt(c_strRegLabelPath,
IntToStr(nCurrentLabel) + c_strRegLabel + IntToStr(nCountLabel),
0);
FstrLabelString[nCountLabel] := RegReadStr(c_strRegLabelPath,
IntToStr(nCurrentLabel) + c_strRegLabelString + IntToStr(nCountLabel),
'');
if FnLabelIndex[nCountLabel] <= 0 then
Break;
//增加指定書簽菜單
FItemAddLabel := TMenuItem.Create(Self);
FItemAddLabel.Caption := FstrLabelString[nCountLabel];
FItemAddLabel.OnClick := OnLabelInputClick;
ItemLabelInput.Add(FItemAddLabel);
end;
end;
//寫標(biāo)志:正確打開文件
FboolOpenFileFlag := True;
//處理
Init_Text;
Init_Page_Do;
Init_Page;
//翻到第1頁
ChangeYe(1);
//刷新主窗口
UpdateMainForm;
end;
begin
//沒有最新文件則退出
if ItemNew.Count <= 2 then Exit;
//得到文件名
strFilename := GetIndexFilename(TMenuItem(Sender).MenuIndex);
//---打開文件---
//判斷是否是ZIP文件中的文件
if pos('|', strFilename) > 0 then
begin //解壓ZIP文件
//得到解壓文件名
strZipFilename := Copy(strFilename,
1,
pos('|', strFilename) - 1);
strZipSubFilename := Copy(strFilename,
pos('|', strFilename) + 1,
Length(strFilename) - Length(strZipFilename) - 1);
s := strZipSubFilename;
i := pos('\', strZipSubFilename);
while i > 0 do
begin
strZipSubFilename[i] := '/';
i := pos('\', strZipSubFilename);
end;
//解壓文件
UnZipFile(strZipFilename, strZipSubFilename, g_strZipPassDir);
strZipSubFilename := g_strZipPassDir + '\' + s;
//判斷文件是否存在
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -