ВКР (1197993), страница 11
Текст из файла (страница 11)
if (group>0) and (group<=groups) then
if (index>0) and (index<=db[group].solutions) then result:=db[group].solution[index] else result:=''
end;
{======================================}
{Методы для добавления программы в трей}
{======================================}
procedure TForm1.IconMouse(var Msg:TMessage);
var
p:tpoint;
begin
GetCursorPos(p); // Запоминаем координаты курсора мыши
case Msg.LParam of // проверяем какая кнопка была нажата
WM_LBUTTONUP,WM_LBUTTONDBLCLK: {действия, выполняемые по оди-нарному или двойному щелчку левой кнопки мышки на значке. В нашем случае это просто активация приложения }
begin
Ic(2,Application.Icon); // Удаление из трея
ShowWindow(Application.Handle,SW_SHOW); // Восстанавливаем кнопку про-граммы
ShowWindow(Handle,SW_SHOW); // Восстанавливаем окно программы
Update
end;
WM_RBUTTONUP: {действия, выполняемые по одинарному щелчку правой кнопки мыши}
begin
SetForegroundWindow(Handle); // восстанавливаем программу в качестве пе-реднего окна
pmTreyMenu.Popup(p.X,p.Y); // Заставляем всплыть PopMenu
PostMessage(Handle,WM_NULL,0,0)
end
end
end;
procedure TForm1.OnMinimizeProc(Sender:TObject);
begin
PostMessage(Handle,WM_SYSCOMMAND,SC_MINIMIZE,0)
end;
procedure TForm1.ControlWindow(var Msg:TMessage);
begin
if Msg.WParam=SC_MINIMIZE then
begin
Ic(1,Application.Icon); // добавляем значок в трей
ShowWindow(Handle,SW_HIDE); // Скрываем программу
ShowWindow(Application.Handle,SW_HIDE) // Скрываем кнопку с TaskBar'à
end
else inherited
end;
procedure TForm1.Ic(n:Integer;Icon:TIcon);
var
Nim:TNotifyIconData;
begin
with Nim do
begin
cbSize:=SizeOf(Nim);
Wnd:=Self.Handle;
uID:=1;
uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
hicon:=Icon.Handle;
uCallbackMessage:=wm_user+1;
szTip:='Helper 1.0'
end;
case n of
1: Shell_NotifyIcon(Nim_Add,@Nim);
2: Shell_NotifyIcon(Nim_Delete,@Nim);
3: Shell_NotifyIcon(Nim_Modify,@Nim)
end
end;
procedure TForm1.N1Click(Sender: TObject);
begin
Ic(2,Application.Icon);
Close
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=vk_escape then
begin
Ic(1,Application.Icon);
ShowWindow(Handle,SW_HIDE);
ShowWindow(Application.Handle,SW_HIDE)
end
end;
function LoadConfig:tcfg;
var
f:textfile;
line:string;
begin
assignfile(f,'Helper.ini');
{$I-}
reset(f);
{$I+}
if IOResult=0 then
begin
readln(f,line); result.db_path:=line;
readln(f,line); result.autostart:=line='1';
readln(f,line); result.group:=line;
end
else
begin
result.db_path:='\\*\Документы\helper\database.txt';
result.autostart:=true;
result.group:='';
rewrite(f);
writeln(f,result.db_path);
writeln(f,ord(result.autostart));
writeln(f,result.group)
end;
closefile(f)
end;
procedure SaveConfig(cfg:tcfg);
var
f:textfile;
line:string;
begin
assignfile(f,'Helper.ini');
rewrite(f);
writeln(f,cfg.db_path);
writeln(f,ord(cfg.autostart));
writeln(f,cfg.group);
closefile(f)
end;
procedure LoadDB(cfg:tcfg);
var
f:textfile;
line:string;
group,title,solution:string;
attr:integer;
SR:TSearchRec;
begin
group:=''; title:=''; solution:='';
assignfile(f,cfg.db_path);
reset(f);
while not eof(f) do
begin
readln(f,line);
line:=trim(line);
if line<>'' then
if line[1]<>'#' then
if line[1]='[' then begin topics.addtopic(group,title,solution); group:=copy(line,2,pos(']',line)-2); title:=copy(line,pos(':',line)+1,length(line)); solution:='' end
else solution:=solution+line+' ';
end;
topics.addtopic(group,title,solution);
// FindFirst(cfg.db_path,attr,SR);
// topics.date:=FileDateToDateTime(SR.FindData.ftCreationTime.dwLowDateTime);
topics.date:=FileDateToDateTime(FileAge(cfg.db_path));
closefile(f)
end;
procedure LoadGroups;
var
j:integer;
begin
for j:=1 to topics.groups do Form1.ListBox2.Items.Add(topics.getgroup(j));
Form1.RichEdit1.Clear
end;
procedure LoadTitles(group:string);
var
j:integer;
begin
id_group:=0;
for j:=1 to topics.groups do
if topics.db[j].group=group then id_group:=j;
Form1.ListBox1.Clear;
for j:=1 to topics.db[id_group].titles do Form1.ListBox1.Items.Add(topics.db[id_group].title[j]);
Form1.RichEdit1.Clear
end;
procedure LoadSolution(title:string);
var
j:integer;
id_title:integer;
begin
id_title:=0;
for j:=1 to topics.db[id_group].titles do
if topics.db[id_group].title[j]=title then id_title:=j;
Form1.RichEdit1.Clear;
Form1.RichEdit1.Text:=topics.db[id_group].solution[id_title]
end;
procedure TForm1.FormCreate(Sender: TObject);
var
j,n:integer;
begin
topics.init;
cfg:=LoadConfig;
LoadDB(cfg);
LoadGroups;
if cfg.group<>'' then
begin
LoadTitles(cfg.group);
ListBox2.ItemIndex:=0
end
else
begin
LoadTitles(ListBox2.Items.Strings[0]);
ListBox2.ItemIndex:=0
end;
StatusBar1.Panels[0].Text:='Версия БД: '+datetimetostr(topics.date);
n:=0;
for j:=1 to topics.groups do n:=n+topics.db[j].titles;
StatusBar1.Panels[1].Text:='Групп: '+inttostr(topics.groups)+' Вопросов: '+inttostr(n);
end;
procedure TForm1.ListBox2Click(Sender: TObject);
begin
LoadTitles(ListBox2.Items.Strings[ListBox2.ItemIndex]);
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
LoadSolution(ListBox1.Items.Strings[ListBox1.ItemIndex]);
end;
procedure TForm1.FormActivate(Sender: TObject);
var
j,x,y:integer;
begin
x:=GetSystemMetrics(SM_CXFULLSCREEN);
y:=GetSystemMetrics(SM_CYFULLSCREEN);
Form1.Left:=x-Form1.Width;
Form1.Top:=y-Form1.Height
end;
procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
RichEdit1.SelectAll;
RichEdit1.SelAttributes.Charset:=RUSSIAN_CHARSET;
RichEdit1.CopyToClipboard
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ListBox2.SetFocus
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Form2.ShowModal
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
Form3.Caption:='Добавление в группу ';
Form3.ShowModal
end; end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Unit1;
type
TForm2 = class(TForm)
Edit1: TEdit;
Bevel1: TBevel;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
CheckBox1: TCheckBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Button1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
cfg.db_path:=Edit1.Text;
SaveConfig(cfg);
Close
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
Close
end;
procedure TForm2.FormShow(Sender: TObject);
begin
Edit1.Text:=cfg.db_path
end;
procedure TForm2.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=vk_return then Button1Click(Form2);
if Key=vk_escape then Close
end;
procedure TForm2.Button1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=vk_escape then Close
end;
end.
5















