Link to home
Start Free TrialLog in
Avatar of beji
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;hwnd:Thandle;popupmeny:TPopupMenu);
 published
 end;

procedure Register;

implementation

procedure Register;
begin
 RegisterComponents('bjs', [TsysIcong]);
end;

{ TsysIcong }

procedure TsysIcong.Add(icon: HICON; tooltiptext:string;hwnd:Thandle;popupmeny:TPopupMenu);
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_DELETE,@TrayIcon);
   end;
 end;
end;

end.

/bj
www.pellesoft.nu
Avatar of mocarts
mocarts

when debugging - do you receive that WM_LBUTTONDOWN message?
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.
Avatar of beji

ASKER

procedure TsysIcong.Add(icon: HICON; tooltiptext:string;hwnd:Thandle;popupmeny:TPopupMenu);
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
Avatar of beji

ASKER

ohh.. i forgot:

sysIcong1.Add(application.Icon.Handle,'text',form1.Handle,nil);

thats how i use my "add" procedure...;)

/bj
www.pellesoft.nu
Avatar of beji

ASKER

ohh.. i forgot:

sysIcong1.Add(application.Icon.Handle,'text',form1.Handle,nil);

thats how i use my "add" procedure...;)

/bj
www.pellesoft.nu
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of beji

ASKER

I fixed with 5lines code..;)
thx Slick812 =D

/bj
www.pellesoft.nu