System Delphi

Title: Windows Ballon
Question: How to make the windows ballon
Answer:
unit NotifyBalloon;
interface
uses
SysUtils,Windows, Classes, ShellApi,Forms,Dialogs;
const
NIF_INFO = $10;
type
TNotifyIcons = (NIIF_NONE , NIIF_INFO ,NIIF_WARNING ,NIIF_ERROR ,NIIF_USER );
TNOTIFYICONDATA = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: array [0..127] of AnsiChar;
dwState: DWORD;
dwStateMask: DWORD;
szInfo: array [0..255] of AnsiChar;
uTimeout: UINT;
szInfoTitle: array [0..63] of AnsiChar;
dwInfoFlags: DWORD;
end;
TNotifyBalloon = class(TComponent)
private
FTitle: String;
FText: String;
NIcon : Integer;
protected
{ Protected declarations }
FIcon: TNotifyIcons;
Data: TNOTIFYICONDATA;
procedure SetIcon;
public
{ Public declarations }
ClientHandle : HWND;
IconHandle : HWND;
constructor Create(AOwner: Tcomponent); override;
procedure ShowNotifyBalloon;
procedure NotifyIcon;
procedure DeleteIcon;
published
{ Published declarations }
property Icon : TNotifyIcons read FIcon write FIcon;
property Title : String read FTitle write FTitle ;
property Text : String read FText write FText ;
end;
procedure Register;
implementation
{*.res}
constructor TNotifyBalloon.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FIcon := NIIF_NONE;
end;
procedure TNotifyBalloon.NotifyIcon;
begin
FillChar(Data,Sizeof(Data),0);
with Data do
begin
cbSize:= Sizeof(Data);
Wnd:= ClientHandle;
uID:= 100;
uFlags:= NIF_ICON;
hIcon:= IconHandle;
end;
Shell_NotifyIcon(NIM_ADD,@Data);
end;
procedure TNotifyBalloon.DeleteIcon;
begin
FillChar(Data,Sizeof(Data),0);
with Data do
begin
cbSize:= Sizeof(Data);
Wnd:= ClientHandle;
uID:= 100;
hIcon:= IconHandle;
end;
Shell_NotifyIcon(NIM_DELETE, @Data);
end;
procedure TNotifyBalloon.SetIcon ;
begin
if FIcon = NIIF_NONE then NIcon := $0;
if FIcon = NIIF_INFO then NIcon := $1;
if FIcon = NIIF_WARNING then NIcon := $2;
if FIcon = NIIF_ERROR then NIcon := $3;
if FIcon = NIIF_USER then NIcon := $4;
end;
procedure TNotifyBalloon.ShowNotifyBalloon;
begin
FillChar(Data,Sizeof(Data),0);
with Data do
begin
cbSize:= Sizeof(Data);
Wnd:= ClientHandle;
uID:= 100;
uFlags := NIF_ICON or NIF_INFO;
hIcon:= Application.Icon.Handle;
StrLCopy(szInfoTitle,PChar(FTitle),Sizeof(szInfoTitle)-1);
StrLCopy(szInfo,PChar(FText),Sizeof(szInfo)-1);
SetIcon;
dwInfoFlags := NIcon;
end;
Shell_NotifyIcon(NIM_MODIFY,@data);
end;
procedure Register;
begin
RegisterComponents('Win32', [TNotifyBalloon]);
end;
end.
//an example to use it....
procedure TForm1.FormCreate(Sender: TObject);
begin
NotifyBalloon1.ClientHandle := Handle;
NotifyBalloon1.IconHandle := Application.Icon.Handle;
NotifyBalloon1.NotifyIcon;
with NotifyBalloon1 do
begin
Title := 'Atencin';
Text := 'Se est quedando sin espacio en el disco C:\';
Icon := NIIF_WARNING;
ShowNotifyBalloon;
end;
end;