Solved

My own system Tray

Posted on 1997-11-06
10
312 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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 …
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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