?
Solved

My own system Tray

Posted on 1997-11-06
10
Medium Priority
?
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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
 

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 1400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

752 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