简体   繁体   中英

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

I'm programming using C++ and WinAPIs. I've added a system tray icon using 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?

It's not a matter of escaping the ampersand - Windows by design will strip any ampersands from tooltip text , for a generally good reason:

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.

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.

Apparently, ampersands require double-escaping, like this &&& .

I'm not sure why but it seems to work.

My source: this link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM