program with icon next to the clock

Hey, Im wondering how to make a program that would have an icon sit next to the clock on the taskbar and not show up in the taskbar itself.

Regards,
Tom
T0maszAsked:
Who is Participating?
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Maybe in your case is better to use a ready to go component...
DOwnload CoolTrayIcon from here http://www.torry.net/vcl/system/trayicons/trayicon.zip
COmplete source, demo and tutorial available...
0
 
tzxie2000Commented:
define variant NotifyIcon:TNotifyIconData

in form create

TForm1.FormCreate(Sender:TObject);

Begin

with NotifyIcon do

begin

cbSize:=SizeOf(TNotifyIconData);

Wnd:=Handle; //set to current window's handle
uID:=1;

uFlags:=NIM_ICON or NIM_MESSAGE or NIM_TIP;

uCallBackMessage:=WM_NID;

hIcon:=Application.Icon.Handle;

szTip:=”this is a test”;//tips

end;.

Shell_NotifyIcon(NIM_ADD,@NotifyIcon);

End;
0
 
T0maszAuthor Commented:
where do I put this?
define variant NotifyIcon:TNotifyIconData

Im getting errors I tried defining just the notifyicon in public but I get some more errors ( undeclared NIM_ICON and so on )

Also How would I create a menu that pops out of the icon when I right click?
Regards,
Tom
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
tzxie2000Commented:
sorry for mis something

define const WM_NID=WM_USER+1000;
use ShellAPI
change that line to   uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
create popupmenu1

write WMNID

procedure TFormMain.WMNID(var msg:TMessage);

begin
  case msg.LParam of
    WM_LBUTTONUp:
      begin
        FormMain.Visible:=not FormMain.Visible;
      end;
    WM_RBUTTONUP:
          begin
      popupmenu1.Popup(1,1);//I just set 1,1 for simple

      end;//ShowMessage('您点击的是右键');
  End;
End;
0
 
Pierre CorneliusCommented:
For a very well documented article on all the how-to's of delphi tray icon applications with examples, look at the following:

http://delphi.about.com/library/weekly/aa122501a.htm
http://delphi.about.com/library/weekly/aa121801a.htm

Status and Animation of the icon:
http://delphi.about.com/library/weekly/aa122501a.htm

Regards

Pierre
0
 
snehanshuCommented:
Tom,
  Two approaches: one which involves coding directly and the other which involves third party components are discussed in this PAQ:
http://www.experts-exchange.com/Q_20792580.html

   Displaying a menu is also there.
Hope it helps,
...Shu
0
 
Ivanov_GCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ShellAPI, Menus;

const
  WM_SYSTRAYCLICK = WM_USER + 1;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    File1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    TrayIcon   : TNotifyIconData;
    procedure InitTrayIcon;
    procedure OnSysTrayClick (var Msg: TMsg); message WM_SYSTRAYCLICK;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.InitTrayIcon;
begin
  // initialize the icon
  with TrayIcon do
    begin
      cbSize := sizeof(TrayIcon);
      Wnd    := Handle;
      uFlags := NIF_MESSAGE + NIF_TIP + NIF_ICON;
      hIcon  := Application.Icon.Handle;
      StrPCopy(szTip, Application.Title);
      uCallbackMessage := WM_SYSTRAYCLICK;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  InitTrayIcon;
  Shell_NotifyIcon(NIM_ADD, @TrayIcon);
  Application.ShowMainForm := False;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Shell_NotifyIcon(NIM_ADD, @TrayIcon);
end;

procedure TForm1.OnSysTrayClick(var Msg: TMsg);
var
  Crs  : TPoint;
begin
  // handle the clicks
  if Msg.wParam = WM_LBUTTONDBLCLK then
    begin
      // show the form
      Self.Show;
    end
  else if Msg.wParam = WM_RBUTTONDOWN then
    begin
      // show the popup menu
      GetCursorPos(Crs);
      PopupMenu1.Popup(Crs.X, Crs.Y);
    end
  else
    inherited;
end;

end.
0
 
geobulCommented:
Hi,

I use this skeleton in my tray apps:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ShellAPI, ComCtrls;

type
  TForm1 = class(TForm)
    procedure ToTray;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure WndProc(var Msg : TMessage); override;
  public
    { Public declarations }
    IconNotifyData : TNotifyIconData;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ToTray;
begin
  Form1.Hide;
end;

procedure TForm1.WndProc(var Msg : TMessage);
begin
  case Msg.Msg of
    WM_USER+1:
    case Msg.lParam of
      WM_LBUTTONUP: begin
         Form1.Show;
         Application.BringToFront;
      end;
    end;
  end;
  if (Msg.Msg = WM_SYSCOMMAND) and (Msg.wParam = SC_MINIMIZE) then begin
    ToTray;
    Msg.wParam := 0;
    Msg.lParam :=0;
  end;
  inherited;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with IconNotifyData do begin
    hIcon :=Application.Icon.Handle;
    uCallbackMessage := WM_USER + 1;
    cbSize := sizeof(IconNotifyData);
    Wnd := Handle;
    uID := 100;
    uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
  end;
  StrPCopy(IconNotifyData.szTip, 'Hint Message'); // <-- modify the message
  Shell_NotifyIcon(NIM_ADD, @IconNotifyData);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Shell_NotifyIcon(NIM_DELETE, @IconNotifyData);
  Application.ProcessMessages;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  ShowWindow(Application.Handle, SW_HIDE);
  SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
end;

end.

Regards, Geo
0
 
Wim ten BrinkSelf-employed developerCommented:
There are many trayicon applications but most of them depend on using the Delphi VCL. If you try to keep it pure Windows API, check out http://www.workshop-alex.org/wallpaper/wallpaper.html for a nice trayicon application that can change your desktop background. All you need next to compiling this sourcefile to an exe is a file called wallpaper.lst with a list of bitmaps that you want to be used as background. (It will complain that it can't find the resource file and will recreate it.)

But basically it shows how to create a small trayicon application with simple popup menu. And no icon on the taskbar. With less than 25 kb in size for the whole EXE it is an interesting project.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.