My own system Tray

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
MirkoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TomunCommented:
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
MirkoAuthor Commented:
Hi Tomun,

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

Regards
  Mirko
0
TomunCommented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

MirkoAuthor Commented:
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
fasterCommented:
How about hook the messages (for example, WM_SIZE) and then get the icon and caption to draw them yourself?
0
MirkoAuthor Commented:
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
2goodCommented:
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
MirkoAuthor Commented:
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
2goodCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MirkoAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

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.