系统托盘访问 [英] Systray Access
问题描述
有没有一种方法(在C#)来访问系统托盘? 我不是说做一个通知图标。 我想通过项目迭代中盘(我猜通过过程,但我不知道如何确定什么是真正的盘,什么只是一个过程),并重新present与项目的图标在我自己的用户界面。
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.
推荐答案
如何你觉得Win32的互操作?我发现 C / Win32的code 可能做的伎俩为您服务。 (事实上,它看起来像一个有趣的问题,所以我可能会尝试解决它自己,只是不是现在)。
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定义与GetProcAddress的,并分序数的Comctl32.dll 332 - 根据我的检查与依赖浏览器,这是的 DPA_GetPtr ,它从一个动态的指针数组中获取数据。我不熟悉,这是怎么回事幕后存在,但它似乎并没有完全出了问题。
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. :)
这篇关于系统托盘访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!