Solved

Minimize to TNA (2)

Posted on 1998-11-16
20
210 Views
Last Modified: 2010-04-03
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
0
Comment
Question by:omsec
  • 10
  • 5
  • 3
  • +1
20 Comments
 
LVL 4

Accepted Solution

by:
BoRiS earned 50 total points
ID: 1347024
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
 
LVL 3

Expert Comment

by:bryan7
ID: 1347025
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
 
LVL 3

Expert Comment

by:bryan7
ID: 1347026
and how to change the icon ? and to have an animated icon ?

bryan

0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347027
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
 
LVL 2

Author Comment

by:omsec
ID: 1347028
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
 
LVL 3

Expert Comment

by:bryan7
ID: 1347029
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
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347030
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1347031
Boris

Wuz up?

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

Cheers,
Viktor
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347032
Viktornet

Yo, Yip you got that right :-)

You been busy wih exams or what¿

Later
BoRiS
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1347033
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:BoRiS
ID: 1347034
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
 
LVL 2

Author Comment

by:omsec
ID: 1347035
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
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347036
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
 
LVL 2

Author Comment

by:omsec
ID: 1347037
yeah thanx, and how do i sintall it ?
COMPONENT|INSTALL.. ?
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347038
Yip components / install component... select .dcu format

Later
BoRiS
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1347039
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
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347040
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
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347041
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
 
LVL 3

Expert Comment

by:bryan7
ID: 1347042
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
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347043
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

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

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

19 Experts available now in Live!

Get 1:1 Help Now