[译]外壳托盘信息-排列系统托盘图标
By robot-v1.0
本文链接 https://www.kyfws.com/applications/shell-tray-info-arrange-your-system-tray-icons-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2350 个词 阅读量 0[译]外壳托盘信息-排列系统托盘图标
原文地址:https://www.codeproject.com/Articles/10807/Shell-Tray-Info-Arrange-your-system-tray-icons
原文作者:Nish Nishant
译文由本站 robot-v1.0 翻译
前言
A tool with full source code that enumerates tray icons and allows you to reposition them as well as send mouse messages.
具有完整源代码的工具,该工具枚举任务栏图标并允许您重新放置它们以及发送鼠标消息.
- 下载源(Visual C ++ 7.1)-19.7 Kb(Download Source (Visual C++ 7.1) - 19.7 Kb)
- 下载二进制(静态MFC构建)-148 Kb(Download Binary (Static MFC Build) - 148 Kb)
总览(Overview)
“任务栏图标信息"应用程序使您可以枚举系统任务栏图标并重新排列它们的位置,以便可以将更常用的图标放置在最左侧(或根据个人喜好而定位在最右侧).当我习惯于将MSN Messenger图标放在托盘的最左侧时,我写了这篇文章,发现当新添加的图标将其推到右侧时,它很烦人且不便.我必须退出并重新启动MSN Messenger才能将其重新放置在需要的位置.此应用程序为我简化了事情.(The Tray Icon Info application lets you enumerate your system tray icons and rearrange their positions, so that you can have your more frequently used icons positioned to the left most side (or right most depending on your personal preference). I wrote this as I got used to having the MSN Messenger icon on the left most side of the tray and found it annoying and inconvenient when newly added icons pushed it to the right. I had to exit and restart MSN Messenger to reposition it where I wanted. This application simplifies things for me.)
支持的操作系统(Supported OS)
此应用程序仅适用于Windows XP.它可能也可以在Windows 2003上运行,但是由于我不确定,并且因为我没有选择对其进行测试,因此我进行了版本检查,如果该程序不是XP操作系统,则该程序退出.如果有人感兴趣,他们可以注释掉版本检查并在2003年上运行它-但我不知道它是否可以工作.(This application only works on Windows XP. It may run on Windows 2003 too, but since I wasn’t sure and since I didn’t have the option to test it out, I have a version check and the program exits if it’s a non-XP OS. If anyone’s interested, they can comment out the version check and run it in on 2003 - but I have no idea as to whether it’ll work or not.)
笔记(Notes)
- 对于某些任务栏图标,我无法检索该图标,因此我显示带有白色问号的红色八边形.(For some tray icons, I am unable to retrieve the icon, so I show a red octagon with a white question mark.)
- 使用工具栏或菜单,您可以向托盘图标发送左键单击,右键单击或双击消息.(Using the toolbar or the menu, you can send a left click, right click or a double click message to the tray icon.)
- 您可以使用«和»图标在托盘中移动图标.(You can use the « and » icons to move the icons around the tray.)
- 复制(Ctrl-C)会将一些文本信息复制到剪贴板(包括工具提示文本以及所有者处理路径).(Copy (Ctrl-C) will copy some textual info to the clipboard (includes both the tool-tip text as well as the owner process path).)
- 双击列表视图中的条目等同于发送双击消息.(Double clicking an entry in the list view is equivalent to sending a double-click message.)
- 任务栏上有隐藏的图标-大多数由资源管理器放置在其中.这些图标没有工具提示.(The tray has hidden icons - mostly put there by Explorer. These icons won’t have tool-tips.)
- 而且,如果您想知道为什么工具栏图标看起来如此可怕,请猜猜是谁设计的!(And er, if you are wondering why the toolbar icons look so ghastly, guess who designed them!)
技术说明(Technical notes)
这里使用的技巧是枚举(The trick used here is to enumerate the buttons of the) ToolbarWindow32
代表系统托盘的窗口.以下代码用于定位此窗口(例程(window that represents the system tray. The following code is used to locate this window (routine) FindWindow
/(/) FindWindowEx
东东) :-(stuff) :-)
HWND FindTrayToolbarWindow()
{
HWND hWnd = ::FindWindow(_T("Shell_TrayWnd"), NULL);
if(hWnd)
{
hWnd = ::FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
if(hWnd)
{
hWnd = ::FindWindowEx(hWnd,NULL,_T("SysPager"), NULL);
if(hWnd)
{
hWnd = ::FindWindowEx(hWnd, NULL,_T("ToolbarWindow32"), NULL);
}
}
}
return hWnd;
}
现在,我检索托盘图标的数量:-(Now I retrieve the count of tray icons :-)
int count = (int)::SendMessage(m_hTrayWnd, TB_BUTTONCOUNT, 0, 0);
该数字与可见图标的数量不匹配,因为资源管理器插入了一些隐藏的图标+可能启用了"隐藏非活动图标"设置.(The number won’t match the number of visible icons because of some hidden icons inserted by Explorer + the Hide Inactive Icons setting may be enabled.)
顺便说一句,检索每个按钮的工具栏信息,我用我的(BTW to retrieve toolbar info for each button, I use my*) CProcessData(CProcessData) 类. [(class. ) CProcessData
是一个模板类,可以轻松使用在不同进程中分配的数据,并且在进行进程间交互时非常有用(is a template class that makes it easy to use data allocated in a different process, and is useful when making inter-process) SendMessage
/(/*) PostMessage
来电
的(The) dwData
每个成员(member of each) TBBUTTON
工具栏的结构指向未记录的结构.结构的前几个字节如下(无论如何在XP上):(structure of the toolbar points to an undocumented structure. The first few bytes of the structure are as follows (on XP anyway) :-)
struct TRAYDATA
{
HWND hwnd;
UINT uID;
UINT uCallbackMessage;
DWORD Reserved[2];
HICON hIcon;
};
有更多信息,但我不确定其余内容是什么.(There’s more info, but I am not sure what the rest of it means.) Reserved[0]
启用"隐藏不活动的图标"设置后,它与图标的可见性状态有关,但是对于我来说,它的行为过于零星,以至于无法赋予它适当的含义,并且由于我真的不想要该信息,因此我无需打扰太多了.我在这个未公开文档的结构上进行的所有Google搜索都没有结果.您希望Windows提供完整的源代码时就是这样:-((has something to do with the visibility state of an icon when the Hide Inactive Icons setting is enabled, but it’s behavior was too sporadic for me to give it a proper meaning and since I didn’t really want that info, I didn’t bother too much. All my Google searches on this undocumented structure resulted in nothing. It’s times like this when you wish Windows provided full source code :-()
无论如何,这是我用来检索所需的其余信息的代码.(Anyway here’s the code I use to retrieve the rest of the information I require.)
CProcessData<TBBUTTON> data(dwTrayPid);
TBBUTTON tb = {0};
TRAYDATA tray = {0};
TrayItemInfo tifo = {0};
for(int i=0; i<count; i++)
{
::SendMessage(m_hTrayWnd, TB_GETBUTTON, i, (LPARAM)data.GetData());
data.ReadData(&tb);
data.ReadData<TRAYDATA>(&tray,(LPCVOID)tb.dwData);
DWORD dwProcessId = 0;
GetWindowThreadProcessId(tray.hwnd,&dwProcessId);
tifo.sProcessPath = GetFilenameFromPid(dwProcessId);
wchar_t TipChar;
wchar_t sTip[1024] = {0};
wchar_t* pTip = (wchar_t*)tb.iString;
if(!(tb.fsState&TBSTATE_HIDDEN))
{
int x = 0;
do
{
if(x == 1023)
{
wcscpy(sTip,L"[ToolTip was either too long or not set]");
break;
}
data.ReadData<wchar_t>(&TipChar, (LPCVOID)pTip++);
}while(sTip[x++] = TipChar);
}
else
wcscpy(sTip,L"[Hidden Icon]");
USES_CONVERSION;
tifo.sTip = W2T(sTip);
tifo.hwnd = tray.hwnd;
tifo.uCallbackMessage = tray.uCallbackMessage;
tifo.uID = tray.uID;
tifo.bVisible = !(tb.fsState & TBSTATE_HIDDEN);
int iconindex = 0;
ICONINFO iinfo;
if(GetIconInfo(tray.hIcon,&iinfo) != 0)
{
iconindex = m_Image16List.Add(tray.hIcon);
}
有关其余代码,请参见随附的源代码zip.(For the rest of the code, see the included source code zip.)
谢谢(Thanks)
- Mike Dunn-有关他的CP文章:(Mike Dunn - for his CP article :) 使用自定义绘图在列表控件中完成的工作(Neat Stuff to do in List Controls Using Custom Draw) .(.)
- 詹博`约翰逊((Jambo Johnson () NET先生(Mr .NET) ):用于为我测试应用程序.() : For testing out the application for me.)
历史(History)
- 2005年6月21日:开始开发该应用程序.(June 21, 2005 : Began work on the app.)
- 2005年6月27日:发布在The Code Project上.(June 27, 2005 : Published on The Code Project.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC7.1 Windows WinXP Visual-Studio VS.NET2003 Dev 新闻 翻译