Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Systray Access

Tags:

c#

.net

Is there a way (in C#) to access the systray? I am not talking about making a notify icon. I want to iterate through the items in the tray (I would guess through the processes but I don't know how to determine what is actually in the tray and what is just a process) and also represent the items with their icons in my own ui.

like image 802
jvberg Avatar asked Nov 05 '08 03:11

jvberg


1 Answers

How do you feel about Win32 interop? I found C/Win32 code that might do the trick for you. (Actually, it looks like an interesting problem so I might try to tackle it myself, just not now).

The magic appears to be that he gets a handle to the system tray's window:

NotifyWnd = FindWindowEx(SysTray, 0, "TrayNotifyWnd", 0);

Then he sets a hook on its message pump:

hHook=SetWindowsHookEx(WH_CALLWNDPROC,HOOKPROC(MsgProc),
         hInstance,dwExplorerThreadId);

Then during the message pump hook callback, he gets a reference to some pointer data about the window:

TWDataT* twd=(TWDataT*)GetWindowLong(NotifyWnd,0);

The mystery is then his loop:

      pTWIconDataT p=COMCTL32_332(twd->iconsInfo,i);

COMCTL32_332 is defined with GetProcAddress and points to ordinal 332 of Comctl32.dll - according to my checking with Dependency Viewer, that's DPA_GetPtr, which gets data from a dynamic pointer array. I'm not familiar with what's going on behind the scenes there, but it doesn't seem entirely out of the question.

I'm going to play with this a bit myself, but hopefully it's a good place to get you started. :)

like image 103
Rob Avatar answered Sep 27 '22 23:09

Rob