
17.10.2009, 18:21
|
Прохожий
|
|
Регистрация: 17.10.2009
Сообщения: 3
Репутация: 10
|
|
я использую этот код:
Код:
.....
type
TForm1 = class(TForm)
......
public
procedure CREATETRAYICON(n:integer);
procedure DELETETRAYICON(n:integer);
procedure WMICON(var msg:Tmessage); message WM_MYTRAYNOTIFY;
procedure WMSYSCOMMAND(var msg:Tmessage);message WM_SYSCOMMAND;
procedure HIDEmainForm;
procedure RestoreMainForm;
.....
procedure TForm1.WMSYSCOMMAND(var msg:Tmessage);
begin
inherited;
if (msg.WParam=SC_MINIMIZE) then
begin
hidemainform;
// createtrayicon(1); иконку можно создать при запуске а не только при сворачивании
end;
end;
procedure TForm1.HIDEmainForm;
begin
application.ShowMainForm:=false;
ShowWindow(application.Handle, SW_HIDE);
ShowWindow(application.Mainform.Handle, SW_HIDE);
end;
procedure TForm1.RestoreMainForm;
var i,j:integer;
begin
application.ShowMainForm:=true;
ShowWindow(application.Handle, SW_RESTORE);
ShowWindow(application.Mainform.Handle, SW_RESTORE);
if not ShownOnce then
begin
for i:= 0 to application.MainForm.ComponentCount -1 do
if application.MainForm.Components[i] is Twincontrol then
with application.MainForm.Components[i] as Twincontrol do
if visible then
begin
showWindow(handle, SW_SHOWDEFAULT);
for j:=0 to componentcount -1 do
if components[j] is twincontrol then
showWindow((components[j] as Twincontrol).handle,SW_SHOWDEFAULT);
end;
shownonce:=true;
end;
end;
procedure TForm1.CREATETRAYICON(n:integer);
var nidata:TnotifyIcondata;
begin
with nidata do
begin
cbSize:=Sizeof(TnotifyIcondata);
Wnd:=Self.Handle;
uId:=n;
uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallBackMessage:=WM_MYTRAYNOTIFY;
hIcon:=Application.Icon.Handle;
szTip:='подсказка';
end;
Shell_notifyIcon(NIM_ADD,@nidata);
////
end;
procedure TForm1.WMICON(var msg:Tmessage);
var p:Tpoint;
begin
case msg.LParam of
WM_RBUTTONDOWN: begin
getcursorpos(p);
setForegroundWindow(application.MainForm.Handle);
sysMenu.Popup(p.X,p.Y);
end;
end
///
end;
procedure TForm1.DELETETRAYICON(n:integer);
var nidata:TnotifyIcondata;
begin
with nidata do
begin
cbSize:=Sizeof(TnotifyIcondata);
Wnd:=Self.Handle;
uId:=n;
end;
Shell_notifyIcon(NIM_DELETE,@nidata);
end;
после события формы FormCreate
делаем
form1.CREATETRAYICON(1);
и
form1.hidemainform;
а в событии OnClick одного из пунктов sysMenu
делаем
restoremainform;
|