Solved

My own system Tray

Posted on 1997-11-06
10
297 Views
Last Modified: 2013-12-03
Here is a hard one, for real pros:

I am currently writing a replacement for the WinNT taskbar, not very much problems so far, but how can I implement a system tray on my own? So that my taskbar shows, e.g. the printer manager or the McAffie shield parallel or instead of the original one?

I now its easy to minimize an application to the tray, but how can you BE the tray?

Sincerly
  Mirko
0
Comment
Question by:Mirko
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 4

Expert Comment

by:Tomun
Comment Utility
You will probably need to replace the Shell_NotifyIcon function.
You could use a technique like the 16bit prochook.dll because you wouldnt want to have to replace the entire shell32.dll

0
 

Author Comment

by:Mirko
Comment Utility
Hi Tomun,

how can I replace a WinAPI function under Windows NT and what is the prochook.dll ?

Regards
  Mirko
0
 
LVL 4

Expert Comment

by:Tomun
Comment Utility
Prochook was a Microsoft Systems Journal article from January 1994 :
"Hook and Monitor Any 16-Bit Windows Function with
Our ProcHook DLL," by James Finnegan.

Source code is still availabl at:
ftp://ftp.microsoft.com/DEVELOPR/MSJ/MSJJAN94.ZIP

It allowed you to replace any 16bit function in any dll with
you own function and optionally call the original function too.

I dont know how it worked, and the same techniques are probably
illegal under NT anyway, but its worth a look just in case.

The text of the prochook article can be found on older MSDN CDs
from about a year ago or two.



0
 

Author Comment

by:Mirko
Comment Utility
The technique explained in this article suggested by Tomun does not work under NT, because they directly manipulate executable regions of memory.

Anyone any other suggestion?
0
 
LVL 7

Expert Comment

by:faster
Comment Utility
How about hook the messages (for example, WM_SIZE) and then get the icon and caption to draw them yourself?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Mirko
Comment Utility
That is not enough, I think. I need the full system-taskbar-tray functionality, e.g. I need to catch the handler routine (and be able to call it, e.g. for the right-click-context menu), I need to be notified, when an Icon changes it's shape, etc. etc.

Perhaps, I should clearify my question a little bit: I want to be able to "catch" everything related to the API call "Shell_NotifyIcon".
0
 
LVL 1

Expert Comment

by:2good
Comment Utility
I poked into SHELL32.DLL once to find out. This happens inside  Shell_NotifyIcon on Windows 95.

1. hWnd = FindWindow(NULL, "TrayNotifyWnd");
3. Assemble a data package
2. SendMessage(hWnd, WM_COPYDATA, ...)

I think the COPYDATASTRUCT is filled in like this, but I'm not sure:
cds.dwData = dwMessage;  // Parameter to Shell_NotifyIcon
cds.cbData = sizeof(NOTIFYICONDATA);
cds.lpData = pnid;  // Parameter to Shell_NotifyIcon

0
 

Author Comment

by:Mirko
Comment Utility
Sorry, but your proposal has a quite big disadvantage:
How can I distinct between "normal" WM_COPYDATA calls and those? (Remember: I also want to react on "online" changes of the icons)
How can I invoke callback functions passed inside of the NOTIFYICONDATA data structure?

Does this work under NT, too?

Sorry, for not giving you an "A", but I also need this information.
0
 
LVL 1

Accepted Solution

by:
2good earned 350 total points
Comment Utility
I looked at the function again, and rewrote it in C, but I haven't tested it.

//
// Windows 95
// SHELL32.DLL
//
// Shell_NotifyIcon - Source code version.
//

typedef struct
{
      DWORD dwId;
      DWORD dwMessage;
      NOTIFYICONDATA nid;
} MSGBUFFER;

BOOL Shell_NotifyIcon(DWORD dwMessage, PNOTIFYICONDATA pnid)
{
      MSGBUFFER mb;
      COPYDATASTRUCT cds;
      HWND hWnd;

      hWnd = FindWindow("Shell_TrayWnd", NULL);

      if( !hWnd )
            return FALSE;

      memcpy( &mb.nid, pnid, sizeof(NOTIFYICONDATA) );

      mb.nid.uFlags &= (NIF_MESSAGE | NIF_ICON | NIF_TIP);
      mb.nid.dwId = 0x34753423;            // "#4u4"

      cds.dwData = 1;
      cds.cbData = sizeof(MSGBUFFER);
      cds.lpData = &mb;

      return (BOOL) SendMessage(hWnd, WM_COPYDATA, (WPARAM) pnid->hWnd, (LPARAM) &cds );
}


To separate these WM_COPYDATA messages, you verify the cds.dwData and mb.dwId values.

Callback functions are invoked like below, where uMsg is the mouse event on the tray icon.
 SendMessage(nid.hWnd, nid.uCallbackMessage, (WPARAM) nid.uID, (LPARAM) uMsg);

The code will theoretically work on Windows NT. The NOTIFYICONDATA structure differs in size between ANSI and UNICODE versions. One or both of cds.dwData and mb.dwId is probably changed in the UNICODE version.
Try it by creating/opening a project which puts an icon in the system tray and use this function instead of calling the API.

0
 

Author Comment

by:Mirko
Comment Utility
Thank you, this seems a really good approach. I haven't tested it yet, but I think it should work. Grade A for your trouble...

Regards
  Mirko
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

763 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

7 Experts available now in Live!

Get 1:1 Help Now