Solved

program with icon next to the clock

Posted on 2004-09-14
9
174 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:T0masz
9 Comments
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12056998
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
 

Author Comment

by:T0masz
ID: 12057837
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
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 12057899
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
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12058003
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 12058089
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
 
LVL 5

Expert Comment

by:snehanshu
ID: 12060964
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
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12061850
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
 
LVL 17

Expert Comment

by:geobul
ID: 12062013
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
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12062731
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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now