简体   繁体   English

如何在Windows系统任务栏提示中显示与号?

[英]How to display an ampersand in a Windows system tray prompt?

I'm programming using C++ and WinAPIs. 我正在使用C ++和WinAPI进行编程。 I've added a system tray icon using Shell_NotifyIcon(NIM_ADD, ...) API. 我使用Shell_NotifyIcon(NIM_ADD,...)API添加了系统任务栏图标。 That icon also has an associated user prompt that contains an ampersand symbol in it, something like this, "View & Copy." 该图标还具有一个关联的用户提示,其中包含一个&符号,类似于“查看并复制”。 But what a user sees though when the prompt pops up, is "View Copy". 但是,当弹出提示时,用户看到的是“查看副本”。 I tried doubling the ampersand, like so "View && Copy" but that didn't help. 我尝试将与号加倍,例如“查看并复制”,但这没有帮助。

Does anyone have any idea how to display an ampersand in a Windows tray prompt? 有谁知道如何在Windows托盘提示中显示&符号?

It's not a matter of escaping the ampersand - Windows by design will strip any ampersands from tooltip text , for a generally good reason: 这不是逃脱&号的问题-Windows 设计使之从工具提示文本中删除所有&号 ,这通常是有充分理由的:

Many applications create toolbars containing tools that correspond to menu commands. 许多应用程序会创建工具栏,其中包含与菜单命令相对应的工具。 For such tools, it is convenient for the tooltip control to display the same text as the corresponding menu item. 对于此类工具,工具提示控件将显示与相应菜单项相同的文本,这很方便。 The system automatically strips the ampersand (&) accelerator characters from all strings passed to a tooltip control, and terminates the string at the first tab character (\\t), unless the control has the TTS_NOPREFIX style. 系统会自动从传递给工具提示控件的所有字符串中删除与符号(&)加速器字符,并在第一个制表符(\\ t)处终止该字符串,除非该控件具有TTS_NOPREFIX样式。

As you can see, the answer is very easy: you just need to add TTS_NOPREFIX to the tooltip class and you'll be set. 如您所见,答案非常简单:您只需将TTS_NOPREFIX添加到工具提示类中即可进行设置。

Apparently, ampersands require double-escaping, like this &&& . 显然,“&”号需要两次转义,例如&&&

I'm not sure why but it seems to work. 我不知道为什么,但是它似乎有效。

My source: this link . 我的资料来源: 此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测对Windows系统托盘的更改? - How to detect changes to the Windows system tray? 如何在Windows中创建任务栏(系统托盘)应用程序 - How to make a taskbar (system tray) application in Windows C ++ Windows系统托盘不会显示消息 - C++ Windows System Tray wont display message 如何获取显示隐藏的系统任务栏图标的窗口的隐藏窗口句柄 - How to get hidden windows handle of the windows that show hidden system tray icons 如何使用Win32 API C ++在系统任务栏图标中显示文本-第2部分 - How to display text in system tray icon with win32 api C++ - part 2 如何在Windows中编写一个最小化到系统托盘的控制台应用程序? - How do I write a console application in Windows that would minimize to the system tray? 从非托管C程序在Windows系统托盘图标上写入文本时如何保持透明度 - How to maintain transparency when writing text on a Windows System Tray icon from unmanaged C program 如何在Linux中编写系统托盘的应用程序 - How to write an application for the system tray in Linux 系统托盘通知:它们是标准窗口还是所有者绘制的弹出菜单或其他? - System Tray Notifications: Are they standard windows or Owner Drawn Popup Menus or other? 系统托盘图标无响应 - System tray icon is not responsive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM