Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

program with icon next to the clock

Posted on 2004-09-14
9
Medium Priority
?
188 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 23

Accepted Solution

by:
Ferruccio Accalai earned 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

885 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