Здравствуйте всем,перейду к сути вопроса.В C++Builder есть компанент который прячет прграмму в трей (с течение времени меняет её иконку и т.д. вобшем красота), мне хотелось бы узнать можно ли в Delphi 5 тоже сотворить что-то подобное.Заранее спасибо
WishMaster, а что это такое по-твоему, "компанент который прячет прграмму в трей" ? Нет такого понятия "прятать в трей". Есть - добавлять в трей иконку, и скрывать основное окно приложения... Это прекрасно делает, например, RxTrayIcon из библиотеки RxLib ...
А вообще - см. http://forum.pascal.net.ru/index.php?showtopic=6361 -> Системные функции и WinAPI -> System tray -> Как свернуть прогу в tray? + Как изменить иконку на Tray? + Как удалить иконку с Tray?
Компанент называется TreyIcon , но все равно спасибо
Скачал я этот DRKB нашол код как сворачивать в трей вот этот код
Procedure TForm1.Ic(n:Integer;Icon:TIcon);
Var Nim:TNotifyIconData;
begin
With Nim do
Begin
cbSize:=SizeOf(Nim);
Wnd:=Form1.Handle;
uID:=1;
uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
hicon:=Icon.Handle;
uCallbackMessage:=wm_user+1;
szTip:='Хинт, который будет появляться у значка';
End;
Case n OF
1: Shell_NotifyIcon(Nim_Add,@Nim);
2: Shell_NotifyIcon(Nim_Delete,@Nim);
3: Shell_NotifyIcon(Nim_Modify,@Nim);
End;
end;
[Error] Unit1.pas(182): Undeclared identifier: 'TNotifyIconData'
[Error] Unit1.pas(190): Undeclared identifier: 'cbSize'
[Error] Unit1.pas(192): Undeclared identifier: 'Wnd'
[Error] Unit1.pas(194): Undeclared identifier: 'uID'
[Error] Unit1.pas(196): Undeclared identifier: 'NIF_MESSAGE'
[Warning] Unit1.pas(196): Combining signed and unsigned types - widened both operands
[Error] Unit1.pas(200): Undeclared identifier: 'uCallbackMessage'
[Error] Unit1.pas(202): Undeclared identifier: 'szTip'
[Error] Unit1.pas(211): Undeclared identifier: 'Shell_NotifyIcon'
[Error] Unit1.pas(211): Undeclared identifier: 'Shell_NotifyIcon'
[Error] Unit1.pas(213): Undeclared identifier: 'Nim_Delete'
[Error] Unit1.pas(215): Undeclared identifier: 'Nim_Modify'
Во-первых, этот код сам по себе ничего не делает, ты забыл добавить еще обработку WM_SYSCOMMAND (там же ниже написано), а во-вторых, добавь в список Uses модуль ShellApi...
Телепатия?
Откуда МЫ видим, что именно ДОЛЖНО у тебя там происходить?
procedure TForm1.ControlWindow(var Msg: TMessage);
begin
if Msg.WParam = SC_MINIMIZE then begin
Ic(1, Application.Icon);
ShowWindow(Handle, SW_HIDE);
end
else inherited;
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);
end;
WM_RBUTTONUP:
begin
PopupMenu1.Popup(p.X, p.Y);
PostMessage(Handle, WM_NULL, 0, 0)
end;
end;
SetForegroundWindow(Handle);
end;
Все равно все работает не так как мне бы хотелось.
1. В каждой форме приходиться встовлять этот код и каждая оддельная форма сворачиваеься в оодельную иконку в треии.
2. Не получаеться чтобы программа при запуске сразу была свернута в трей(тоесть для того чтобы она свернулась приходиться нажимать кнопку свертывания формы)
3. В панели около "пуск" программа не исчезает (она сворачиваеться в трей и продолжает висеть в в панели около кнопки пуск)
4. А есть какойнибуть более лекгий код свертывания в трей или нету.
Ну так вот может ктонибуть поможет мне оптимизировать код свертывания в трей?
Вот код моей программы:(приведен без процедур свертывания в трей)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, shellapi;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
ComboBox1: TComboBox;
ComboBox: TComboBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Label3: TLabel;
Label2: TLabel;
PopupMenu1: TPopupMenu;
N2: TMenuItem;
procedure ComboBox1Change(Sender: TObject);
procedure ComboBoxChange(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
skupoy,osnovnoy,standart,samuray,vip:integer;
vnesh,vnutren:integer;
vivod:real;
s:string;
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
skupoy:=0;
osnovnoy:=0;
standart:=0;
samuray:=0;
vip:=0;
if combobox1.ItemIndex=0 then skupoy:=1; ComboBox.Visible:=true;
if combobox1.ItemIndex=1 then osnovnoy:=1; ComboBox.Visible:=true;
if combobox1.ItemIndex=2 then standart:=1; ComboBox.Visible:=true;
if combobox1.ItemIndex=3 then samuray:=1; ComboBox.Visible:=true;
if combobox1.ItemIndex=4 then vip:=1;
combobox1.top:=-1;
end;
procedure TForm1.ComboBoxChange(Sender: TObject);
begin
vnesh:=0;
vnutren:=0;
if ComboBox.ItemIndex=0 then vnesh:=1; GroupBox1.Visible:=true;
if ComboBox.ItemIndex=1 then vnutren:=1; GroupBox1.Visible:=true;
GroupBox1.Enabled:=true;
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
vivod:=0;
GroupBox2.Visible:=true;
label1.caption:='';
label2.Caption:='';
if s='' then label2.Caption:='Текст : )' else begin
if (skupoy=1) and (vnesh=1) then vivod:=strtofloat(s)*2;
if (skupoy=1) and (vnutren=1) then vivod:=strtofloat(s)*0.05;
if (osnovnoy=1) and (vnesh=1) then vivod:=strtofloat(s)*1.8;
if (osnovnoy=1) and (vnutren=1) then vivod:=strtofloat(s)*0.05;
if (standart=1) and (vnesh=1) then vivod:=strtofloat(s)*1.5;
if (standart=1) and (vnutren=1) then vivod:=strtofloat(s)*0.05;
if (samuray=1) and (vnesh=1) then vivod:=strtofloat(s)*1.25;
if (samuray=1) and (vnutren=1) then vivod:=strtofloat(s)*0.05;
if (vip=1) and (vnesh=1) then vivod:=strtofloat(s)*0.98;
if (vip=1) and (vnutren=1) then vivod:=strtofloat(s)*0.05;
label1.Caption:=floattostr(vivod)+'р';
edit1.clear;end;
end;
procedure TForm1.Button13Click(Sender: TObject);
begin
edit1.Clear;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.SelText:='1';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.SelText:='2';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
edit1.SelText:='3';
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
edit1.SelText:='4';
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
edit1.SelText:='5';
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
edit1.SelText:='6';
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
edit1.SelText:='7';
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
edit1.SelText:='8';
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
edit1.SelText:='9';
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
edit1.SelText:='0';
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
edit1.SelText:=',';
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
s:=edit1.Text;
end;
end.
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,winsock,shellapi, Menus, ExtCtrls;
type
TForm4 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
Timer1: TTimer;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
t1,t2,t3:integer;
Form4: TForm4;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm4.FormCreate(Sender: TObject);
type
TaPInAddr = Array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
i:Integer;
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: Array[0..63] of Char;
GInitData: TWSAData;
begin
label4.Caption:='Время соединения'+inttostr(t2)+'ч'+inttostr(t1)+'мин'+inttostr(t1)+'сек';
form4.Visible:=false;
WSAStartup($101, GInitData);
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then Exit;
pPtr := PaPInAddr(phe^.h_addr_list);
I := 0;
while pPtr^[I] <> nil do
begin
Tlabel(FindComponent('label'+IntToStr(i+1))).caption:=inet_ntoa(pptr^[I]^);
Inc(I);
end;
if label2.Caption='' then label1.Caption:=' ';
if label2.Caption<>''then label1.caption:=' ';
WSACleanup;
end;
procedure TForm4.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled:=true;
t1:=t1+1;
if t1=60 then t2:=t2+1; t1:=0;
if t2=60 then t3:=t3+1; t2:=0;
end;
end.
Type
TForm1 = Class(TTrayedForm)
...
End;
{ Эту процедуру не забудь добавить в класс формы }
procedure TForm1.OnMinimizeProc(Sender: TObject);
begin
PostMessage(Handle,WM_SYSCOMMAND,SC_MINIMIZE,0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.onMinimize:=OnMinimizeProc;
Application.Minimize; { <--- Вот этого не хватало }
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); { <--- Добавлять не пробовал? }
end
else inherited;
end;