beji
asked on
My component dosent work
Hi..
I'm working on a komponent who should add a icon to systray and stuff like that..=)
I can add a icon but not delete my icon
I dont understand why cause my code work when i dont have it in a komponent..
here my code:
unit sysIcong;
interface
uses
Windows, Messages, SysUtils, Classes,ShellApi,Menus;
const WM_ICONTRAY = WM_USER + 1;
type
TsysIcong = class(Tcomponent)
private
TrayIcon : TNotifyIconData;
popup1:TPopupMenu;
procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY;
protected
public
procedure Add(icon: HICON;tooltiptext:string;h wnd:Thandl e;popupmen y:TPopupMe nu);
published
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('bjs', [TsysIcong]);
end;
{ TsysIcong }
procedure TsysIcong.Add(icon: HICON; tooltiptext:string;hwnd:Th andle;popu pmeny:TPop upMenu);
begin
//do i really have to show how i add my icon? ;)
end;
procedure TsysIcong.TrayMessage(var Msg: TMessage);
begin
case Msg.lParam of
WM_LBUTTONDOWN:
begin
Shell_NotifyIcon(NIM_DELET E,@TrayIco n);
end;
end;
end;
end.
/bj
www.pellesoft.nu
I'm working on a komponent who should add a icon to systray and stuff like that..=)
I can add a icon but not delete my icon
I dont understand why cause my code work when i dont have it in a komponent..
here my code:
unit sysIcong;
interface
uses
Windows, Messages, SysUtils, Classes,ShellApi,Menus;
const WM_ICONTRAY = WM_USER + 1;
type
TsysIcong = class(Tcomponent)
private
TrayIcon : TNotifyIconData;
popup1:TPopupMenu;
procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY;
protected
public
procedure Add(icon: HICON;tooltiptext:string;h
published
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('bjs', [TsysIcong]);
end;
{ TsysIcong }
procedure TsysIcong.Add(icon: HICON; tooltiptext:string;hwnd:Th
begin
//do i really have to show how i add my icon? ;)
end;
procedure TsysIcong.TrayMessage(var Msg: TMessage);
begin
case Msg.lParam of
WM_LBUTTONDOWN:
begin
Shell_NotifyIcon(NIM_DELET
end;
end;
end;
end.
/bj
www.pellesoft.nu
ASKER
procedure TsysIcong.Add(icon: HICON; tooltiptext:string;hwnd:Th andle;popu pmeny:TPop upMenu);
begin
Trayicon.cbSize := SizeOf(TNotifyIconData);
Trayicon.Wnd := hwnd;
Trayicon.szTip := 'hmm';
Trayicon.uID := 1;
TrayIcon.hIcon := icon;
TrayIcon.uCallbackMessage := WM_ICONTRAY;
Trayicon.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,@ trayicon);
//for menu later:
popup1 := popupmeny;
end;
there how i add my icon..
and one more question:
i cant do like this:
Trayicon.szTip := tooltiptext;
how should i do to get my text on "szTip" ?
/bj
www.pellesoft.nu
begin
Trayicon.cbSize := SizeOf(TNotifyIconData);
Trayicon.Wnd := hwnd;
Trayicon.szTip := 'hmm';
Trayicon.uID := 1;
TrayIcon.hIcon := icon;
TrayIcon.uCallbackMessage := WM_ICONTRAY;
Trayicon.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,@
//for menu later:
popup1 := popupmeny;
end;
there how i add my icon..
and one more question:
i cant do like this:
Trayicon.szTip := tooltiptext;
how should i do to get my text on "szTip" ?
/bj
www.pellesoft.nu
ASKER
ohh.. i forgot:
sysIcong1.Add(application. Icon.Handl e,'text',f orm1.Handl e,nil);
thats how i use my "add" procedure...;)
/bj
www.pellesoft.nu
sysIcong1.Add(application.
thats how i use my "add" procedure...;)
/bj
www.pellesoft.nu
ASKER
ohh.. i forgot:
sysIcong1.Add(application. Icon.Handl e,'text',f orm1.Handl e,nil);
thats how i use my "add" procedure...;)
/bj
www.pellesoft.nu
sysIcong1.Add(application.
thats how i use my "add" procedure...;)
/bj
www.pellesoft.nu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
if not - check how you register icon i.e. ensure all parameters (hwnd, id (must be unique in context of app), callback, etc.) are valid
wbr, mo.