Solved

Minimize app. to "System Tray"/Program Bar Status Area??

Posted on 1998-05-03
7
301 Views
Last Modified: 2010-04-06
All of you know the applications that don't show up in the Launch Bar, but instead only display a little icon at the right edge, e.g. the speaker icon, the printer icon, the dial-up monitor, but also Winfax and ICQ (to name a few "non-system" programs).

Can this be done in Delphi programs?
I tried to find a few hints in the Delphi help, but couldn't find anything useful. There is a reference to the "Taskbar status area", but no hint how to "get there".
Once again - I'd like my application to show up there minimized, but NOT be displayed in the Taskbar.

I guess 100 points are appropriate if there is an "easy" way of doing it. If this is possible but very complicated (maybe some direct WinAPI calls or the like), I'd also pay a lot more as soon as it works - whatever seems to be appropriate. I mostly answer questions (Web areas) and hardly ask any - I have lots of points available...

P.S.: I am using Delphi 3, so that shouldn't be a problem :-)
0
Comment
Question by:Holger101497
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 120 total points
ID: 1340658
This is something I have seen in one of the sites. I have made little modifications to make it work properly.
Place 3 buttons for Add, Delete and modify the Icon in the TaskBar.
Place a Popup menu with some items and write the following code:

uses ShellAPI;
..
var IconData :TNotifyIconData;
...
procedure TForm1.bbAddClick(Sender: TObject);
begin
  with IconData DO
  begin
    cbSize := SizeOf(IconData);
    uFlags := NIF_ICON OR NIF_TIP OR NIF_MESSAGE;
    uID := 0;
    Wnd := Handle;
    szTip := 'This is my Application'+#0;
    hIcon := Application.Icon.Handle;
    uCallBackMessage := WM_USER+$10;
  end;
  if Shell_NotifyIcon(NIM_ADD,@IconData) then MessageBeep(0);
end;

procedure TForm1.bbModifyClick(Sender: TObject);
begin
  with IconData do
  begin
    szTip := 'app is modified'+#0;
    hIcon := LoadIcon(0,IDI_ASTERISK);
  end;
  if Shell_NotifyIcon(NIM_MODIFY,@IconData) then MessageBeep(0);
end;

procedure TForm1.bbDeleteClick(Sender: TObject);
begin
  if Shell_NotifyIcon(NIM_DELETE,@IconData) then MessageBeep(0);
end;

procedure TForm1.WndProc(var MyMessage: TMessage);
var CursorPos: TPoint;
begin
  IF MyMessage.Msg = WM_USER+$10 THEN
  CASE MyMessage.LParam OF
  WM_RBUTTONUP :
  BEGIN
    GetCursorPos(CursorPos);
    PopupMenu1.Popup(CursorPos.X, CursorPos.Y);
  END;
  WM_LBUTTONDBLCLK :
  ShowMessage('This is my application');
  END;
  INHERITED WndProc(MyMessage);
end;

0
 
LVL 6

Author Comment

by:Holger101497
ID: 1340659
Hey! (Almost) cool!!
Everything is easy if you know how to do it ;-)

I got it to work, but have two or three little questions left:
1) Do I need to "register" WndProc? Where? Can this be done in Delphi or do I need another API-call in the onFormCreate? It doesn't work yet.
2) I wanted the application to be "hidden". I did this by setting Visible to false but don't get it to "reappear". Is this the proper way of doing it? What would I do? Set "Visible" in the "onDblClick" and/or in the Popup-Menu?
3) Of course I want to understand what I'm doing! Where do I find the reference for "TNotifyIconData" and the other constants and functions that are used? Anything in the online help? I don't have the printed documentation with me! I'll need to do more complicated things than just place an icon and of course I have to know where to find out more about the parameters I use...

       Thanks a lot!
0
 
LVL 6

Author Comment

by:Holger101497
ID: 1340660
Oooops! Stupid me! *lol*
well, not so stupid - noticed it myself after all --- I forgot the "override" :-))
I haven't used any API-functions so far :-)
question 1) done
question 2) almost done - is there any (different) standard way of doig this? My program works, though...

only question 3 left...
I added another 25 points for a nice explanation :-))

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 5

Expert Comment

by:ronit051397
ID: 1340661
Q2:
Usually with double click on the tray you should show your screen, but some times you add also an item in the popup menu.

Q3:
This is from shellapi.pas, if you have borland source code, then you can see it there, also look in the Win32.hlp:
....
  TNotifyIconDataA = record
    cbSize: DWORD;
    Wnd: HWND;
    uID: UINT;
    uFlags: UINT;
    uCallbackMessage: UINT;
    hIcon: HICON;
    szTip: array [0..63] of AnsiChar;
  end;

  TNotifyIconDataW = record
    cbSize: DWORD;
    Wnd: HWND;
    uID: UINT;
    uFlags: UINT;
    uCallbackMessage: UINT;
    hIcon: HICON;
    szTip: array [0..63] of WideChar;
  end;

  TNotifyIconData = TNotifyIconDataA;
....
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1340662
from win32.hlp:

typedef struct _NOTIFYICONDATA { // nid
    DWORD cbSize;          // sizeof(NOTIFYICONDATA)
    HWND hWnd;             // see below
    UINT uID;              // see below
    UINT uFlags;           // see below
    UINT uCallbackMessage; // see below
    HICON hIcon;           // see below
    char szTip[64];        // see below
} NOTIFYICONDATA, *PNOTIFYICONDATA;
 

Contains information that the system needs to process taskbar notification area messages.

hWnd

Handle of the window that receives notification messages associated with an icon in the taskbar notification area.

uID

Application-defined identifier of the taskbar icon.

uFlags

Array of flags that indicate which of the other structure members contain valid data. This member can be a combination of these values:

NIF_ICON      The hIcon member is valid.
NIF_MESSAGE      The uCallbackMessage member is valid.
NIF_TIP      The szTip member is valid.
uCallbackMessage

Application-defined message identifier. The system uses the specified identifier for notification messages that it sends to the window identified by hWnd whenever a mouse event occurs in the bounding rectangle of the icon.

hIcon

Handle of the taskbar icon to add, modify, or delete.

szTip

Tooltip text to display for the taskbar icon.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1340663
Well?...
0
 
LVL 6

Author Comment

by:Holger101497
ID: 1340664
YES! *g*

Sorry for taking such a long time with the grade - I would not have forgot it, though.

The program uses THTTP and I really can't get it to run on any computer but mine (must be some problem with registering ActiveX components and DLL's... ), so I figured I'd grade this answer as soon as everything works. Well, nobody knows how to do it :-(((

"Technically speaking", this question is answered and my other problems are not related to this question at all, so I guess I'll grade it now :-))

Thanks a lot, it all seems to work very nicely and easily :-)
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 120
When I am typing into a TEdit last word repeats 7 147
Help on project with Soap 10 57
Firemonkey allowing RTL on android 6 47
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

828 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