Solved

My own system Tray

Posted on 1997-11-06
10
300 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
ID: 1408213
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
ID: 1408214
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
ID: 1408215
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
ID: 1408216
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
ID: 1408217
How about hook the messages (for example, WM_SIZE) and then get the icon and caption to draw them yourself?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Mirko
ID: 1408218
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
ID: 1408219
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
ID: 1408220
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
ID: 1408221
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
ID: 1408222
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

22 Experts available now in Live!

Get 1:1 Help Now