Minimize to TNA (2)

Once, I have already asked this, but it didn't work, because I got Error "Shell_NotifyIcon (Proc) is unknown Identifer".
So, how to hide an Application, and minimize it to the SystemTray or TNA (where the Win32-Clock, ICQ-Flower etc) is
and show it when clicking on the Icon there.

A little Sub-Menu with 'EXIT'-Function would also be usefull.
thanx, Omsec
LVL 2
omsecAsked:
Who is Participating?
 
BoRiSConnect With a Mentor Commented:
omsec

Here is code to do just that... or if you leave your email address I will mail you a component that does the whole thing for you...

unit systryico;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Stdctrls, comctrls, Shellapi;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  procedure IconCallBackMessage( var Mess : TMessage ); message WM_USER
  + 100;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
   Icd : TNotifyIconData;
begin
     ShowWindow(Application.handle, SW_HIDE);
     Self.Hide;
     with Icd do
     begin
           cbSize := SizeOf( TNotifyIconData );
           Wnd := Form1.Handle;
           uID := 1;
           uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
           uCallbackMessage := WM_USER + 100;
           hIcon := Application.Icon.Handle;
           szTip := 'Cool I got it right Wooooo Weeeee';
     end;
     Shell_NotifyIcon( NIM_ADD, @Icd );
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
   Icd : TNotifyIconData;
begin
     with Icd do
     begin
           cbSize := SizeOf( TNotifyIconData );
           Wnd := Form1.Handle;
           uID := 1;
           uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
           uCallbackMessage := WM_USER + 100;
           hIcon := Application.Icon.Handle;
           szTip := 'Cool I got it right Wooooo Weeeee';
// All the above is probably not needed.
     end;
     Shell_NotifyIcon( NIM_DELETE, @Icd );
end;

procedure TForm1.IconCallBackMessage( var Mess : TMessage );
var
   sEventLog : String;
begin
     case Mess.lParam of
// Do whatever you wish here. For example popup up a menu on a right click.
          WM_LBUTTONDBLCLK  : sEventLog := 'Left Double Click';
          WM_LBUTTONDOWN    : sEventLog := 'Left Down';
          WM_LBUTTONUP      : sEventLog := 'Left Up';
          WM_MBUTTONDBLCLK  : sEventLog := 'M Dbl';
          WM_MBUTTONDOWN    : sEventLog := 'M D';
          WM_MBUTTONUP      : sEventLog := 'M U';
          WM_MOUSEMOVE      : sEventLog :=  'movement';
          WM_MOUSEWHEEL     : sEventLog := 'Wheel';
          WM_RBUTTONDBLCLK  : sEventLog := 'r dbl';
          WM_RBUTTONDOWN    : sEventLog := 'r down';
          WM_RBUTTONUP      : sEventLog := 'r up';
     end;
end;

end.

Later
BoRiS
0
 
bryan7Commented:
hi there !

it works, but.. I think he means to use a popup menu just above the system tray icon.
How to do it ?

bryan

0
 
bryan7Commented:
and how to change the icon ? and to have an animated icon ?

bryan

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
BoRiSCommented:
omsec/bryan7

Like I siad leave your email address and I'll send you a component I wrote that allows a popup menu, animated icons, onDblclick etc.

Also I need to now what version of delphi you are on... the component is for D3 & 4.

Later
BoRiS
0
 
omsecAuthor Commented:
Hi,
I'm actually at work and don't have Delphi here, so I can't check it out. You may send it to me at Home to rbieri@centralnet.ch
I use Delphi 4 Standard
By saying Menu, i meant, I need a PopUp that is activated on RightMouse Click and says EXIT to quit the program.

thx ;)
0
 
bryan7Commented:
this is: AerithFantasy@earthling.net         AERITHFANTASY@EARTHLING.NET ( just in case =)   )

I use Delphi 3 c/s. Hmm.. how can I add some items to popup menu that appears by clicking on the application 'button' on the task bar ?

I'll drop some points for this, you are helping us both.
thanx.

bryan =)

0
 
BoRiSCommented:
omsec/bryan7

I have sent my component to you, TBRSTrayIcon, this will allow you to asign a popupmenu to the icon, just drop a popup menu on the form and assign it to the popup filed in the object inspector on the trayicon component...

You'll see what I mean, if a popupmenu is assigned then the will atomatically popup on the rightbutton click...

Later
BoRiS
0
 
viktornetCommented:
Boris

Wuz up?

I see you've been working hard around here, eh??  ;-)

Cheers,
Viktor
0
 
BoRiSCommented:
Viktornet

Yo, Yip you got that right :-)

You been busy wih exams or what¿

Later
BoRiS
0
 
viktornetCommented:
naw.... just exploring some new stuff :)

I'm also working out so I don't have time to program that much...after I come from my workout, I just go to sleep.. I'm usually tired out after it, so...maybe I'll see you around on saturday or something like that :)

btw- Like da up side down question mark ;-)

Keep the good work ya :)

Cheers,
Viktor
0
 
BoRiSCommented:
Viktor

Hmmm, working out, at gym or boxing or what ¿, I have gone back to kick boxing and tai chi myself...

I will see you around, and you keep up the good work 2...

Later
BoRiS
0
 
omsecAuthor Commented:
hmh, the program deosn't exactly do what i need. it should first be in the normal task list, where you can switch programs. if the user click on the _ - Button (minimize) it should remove itself from the taskbar and just leave an icon in the SystemTray. On Click, it should appear again in maximized size.
maybe, i should mention, that my programs displays a splash form at start up
0
 
BoRiSCommented:
omsec

Did you receive the component I sent you for the taskbar icon, what you can do is create an onminimize event and then Set the BRSTrayIcon.Enabled to true and BRSTrayIcon.Showapp := False; and BRSTrayIcon.showManForm := False;...or you could use Application.OnMinimize event to pass the above stuff...

Then to get it back just set the stuff above to true and false on the BRSTrayIcon's on click event...

If you want I will send you a little example of the use of BRSTrayIcon, with the above done in the example...

Later
BoRiS
0
 
omsecAuthor Commented:
yeah thanx, and how do i sintall it ?
COMPONENT|INSTALL.. ?
0
 
BoRiSCommented:
Yip components / install component... select .dcu format

Later
BoRiS
0
 
bryan7Commented:
Hi Boris, yeah, that works.

what are these properies for and how to use them ?
-Animated
-IconIndex
-IconList
-Interval
-ShowDesign

can you add these events ?

              WM_LBUTTONDBLCLK  : sEventLog := 'Left Double Click';
              WM_LBUTTONDOWN    : sEventLog := 'Left Down';
              WM_LBUTTONUP      : sEventLog := 'Left Up';
              WM_MBUTTONDBLCLK  : sEventLog := 'M Dbl';
              WM_MBUTTONDOWN    : sEventLog := 'M D';
              WM_MBUTTONUP      : sEventLog := 'M U';
              WM_MOUSEMOVE      : sEventLog :=  'movement';
              WM_MOUSEWHEEL     : sEventLog := 'Wheel';
              WM_RBUTTONDBLCLK  : sEventLog := 'r dbl';
              WM_RBUTTONDOWN    : sEventLog := 'r down';
              WM_RBUTTONUP      : sEventLog := 'r up';

wm_mousewheel ?

how to detect RBUTTONDBLCLK on any componenet ?

how do I make the icon blink ?
and to have an animated icon ?
and how to have icons in the popup menu ?
how do you get the coords(x,y) so the popup menu pops up above the icon ?


well, maybe too many questions.. sorry.

bryan

0
 
BoRiSCommented:
bryan7

All of these questions will be revealed when I release my components with source in a week or two...but here are a couple of answeres

For the right click event try something like this

 procedure WMRButtonDown(var M: TWMRButtonDown); message WM_RBUTTONDOWN; //under the public heading

 then call

procedure TForm1.WMRButtonDown(var M: TWMRButtonDown);
var
Pt: Tpoint;
begin
inherited;
GetCursorPos(Pt);
 if M.Result = htClient then
  PopupMenu1.Popup(pt.x, pt.y);
end;

To get the x, y cord...

TrackPopupMenu API call

To set image Items in your popupmenu use the API call

SetMenuItemBitmaps(Menu1.Handle, 1, MF_BTCOMMAND, Bitmap1, Btimap2);

for more info on the above API's just check the win32.hlp file

Later
BoRiS
0
 
BoRiSCommented:
omsec

Did the component do what you needed it to...if so please evaluate this answer...

bryan7

did the component work for you, I will be releasing the source soon just added WM_MOUSEWHEEL event and MOUSEENTER and MOUSELEAVE...so I'm updating it and getting it cleaned up...

Later
BoRiS
0
 
bryan7Commented:
I've tried to use teh TrackPopUpMenu, but had no succes..
and how do I have an ANIMATEDicon in the systray ?

the rest of things worked perfectly..

MOUSEENTER and MOUSELEAVE are functions like OnMouseMove ?
it would be great if components had something like "OnMouseMoveOut" ..

bryan

0
 
BoRiSCommented:
bryan7

If you assign an Imagelist to my tray component and add you images to it, then set th animated to true then when the tray icon is shown it will animate the images in the image list.

The OnMouseEnter and OnMouseLeave are like "OnMouseOut" when the mouse enters the control it for example changes the text and when the mouse is moved out the control the text is set back to normal...

I'll mail you an example if you wish...

Later
BoRiS
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.