Вот попробовал сделать или здесь
http://dumpz.org/11101/ или ниже:
program PlasticNote;
uses
Windows,
Messages,
Kol;
type
PProgramm = ^TProgramm;
TProgramm = object(TObj)
private
Form,
Memo: PControl;
Tray: PTrayIcon;
MenuTray: PMenu;
procedure IniFileSaveLoad(Save: Boolean);
procedure FormShowHide(Show: Boolean);
procedure DoTrayMouse(Sender: PObj; Message: Word);
procedure DoMenuTrayMenuItem(Sender: PMenu; Item: Integer);
procedure DoFormClose(Sender: PObj; var Accept: Boolean);
function DoFormMessage(var Msg: TMsg; var Rslt: Integer): Boolean;
end;
var
Programm: PProgramm;
optCloseToHide: Boolean = False;
optMinToHide: Boolean = False;
optStartHide: Boolean = False;
procedure TProgramm.DoFormClose(Sender: PObj; var Accept: Boolean);
begin
IniFileSaveLoad(True);
end;
function TProgramm.DoFormMessage(var Msg: TMsg;
var Rslt: Integer): Boolean;
begin
Result := False;
if Msg.message = WM_SYSCOMMAND then
case Msg.wParam of
SC_MINIMIZE:
if optMinToHide then begin
FormShowHide(False);
Result := True;
end;
SC_CLOSE:
if optCloseToHide then begin
FormShowHide(False);
Result := True;
end
end;
end;
procedure TProgramm.DoMenuTrayMenuItem(Sender: PMenu; Item: Integer);
begin
case Item of
0: FormShowHide(not Programm.Form.Visible);
2: Programm.Form.Close;
end;
end;
procedure TProgramm.DoTrayMouse(Sender: PObj; Message: Word);
var
p: TPoint;
begin
case Message of
WM_RBUTTONUP: begin
SetForegroundWindow(Programm.Form.Handle);
GetCursorPos(p);
MenuTray.PopUp(p.x, p.y);
end;
WM_LBUTTONDBLCLK: FormShowHide(not Programm.Form.Visible);
end;
end;
procedure TProgramm.FormShowHide(Show: Boolean);
var
s: String;
begin
Programm.Form.Visible := Show;
if Programm.Form.Visible then begin
ShowWindow(Programm.Form.Handle, SW_RESTORE);
SetForegroundWindow(Programm.Form.Handle);
s := 'Hide';
end else
s := 'Show';
Programm.MenuTray.ItemText[0] := s;
end;
procedure TProgramm.IniFileSaveLoad(Save: Boolean);
var
IniFile: PIniFile;
begin
IniFile := OpenIniFile(GetStartDir + 'settings.ini');
try
if Save then IniFile.Mode := ifmWrite;
IniFile.Section := 'Main';
optMinToHide := IniFile.ValueBoolean('MinToHide', optMinToHide);
optCloseToHide := IniFile.ValueBoolean('CloseToHide', optCloseToHide);
optStartHide := IniFile.ValueBoolean('StartHide', optStartHide);
finally
IniFile.Free;
end;
end;
begin
New(Programm, Create);
with Programm^ do begin
IniFileSaveLoad(False);
Form := NewForm(nil, 'Programm');
Form.Add2AutoFree(Programm);
Form.OnMessage := DoFormMessage;
Form.OnClose := DoFormClose;
Form.IconLoad(hInstance, 'MAINICO');
Form.SetClientSize(439, 275);
Form.Border := 0;
Form.CenterOnParent;
Form.CanResize := False;
Form.Style := Form.Style and not WS_MAXIMIZEBOX;
Form.Font.FontHeight := 13;
Form.Font.FontName := 'Tahoma';
NewMenu(Form, 0, [], nil);
MenuTray := NewMenu(Form, 0, ['show/hide', '-', 'Exit' ], DoMenuTrayMenuItem);
MenuTray.Items[0].DefaultItem := True;
Tray := NewTrayIcon(Form, Form.Icon);
Tray.AutoRecreate := True;
Tray.Active := True;
Tray.OnMouse := DoTrayMouse;
FormShowHide(not optStartHide);
Run(Form);
end;
end.