MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / TrayTip

Method TrayTip

source/script2.cpp:259–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257
258
259ResultType Line::TrayTip(LPTSTR aText, LPTSTR aTitle, LPTSTR aOptions)
260{
261 NOTIFYICONDATA nic = {0};
262 nic.cbSize = sizeof(nic);
263 nic.uID = AHK_NOTIFYICON; // This must match our tray icon's uID or Shell_NotifyIcon() will return failure.
264 nic.hWnd = g_hWnd;
265 nic.uFlags = NIF_INFO;
266 // nic.uTimeout is no longer used because it is valid only on Windows 2000 and Windows XP.
267 if (!TrayTipParseOptions(aOptions, nic))
268 return FAIL;
269 if (*aTitle && !*aText)
270 // As passing an empty string hides the TrayTip (or does nothing on Windows 10),
271 // pass a space to ensure the TrayTip is shown. Testing showed that Windows 10
272 // will size the notification to fit only the title, as if there was no text.
273 aText = _T(" ");
274 if (nic.dwInfoFlags & NIIF_USER)
275 {
276 // Windows 10 toast notifications display the small tray icon stretched to the
277 // large size if NIIF_USER is passed but without NIIF_LARGE_ICON or hBalloonIcon.
278 // If a large icon is passed without the flag, the notification does not show at all.
279 // But since this could change, let the script pass 0x24 to use the large icon.
280 //if (g_os.IsWin10OrLater())
281 // nic.dwInfoFlags |= NIIF_LARGE_ICON;
282 if (nic.dwInfoFlags & NIIF_LARGE_ICON)
283 nic.hBalloonIcon = g_script.mCustomIcon ? g_script.mCustomIcon : g_IconLarge;
284 else
285 nic.hBalloonIcon = g_script.mCustomIconSmall ? g_script.mCustomIconSmall : g_IconSmall;
286 }
287 tcslcpy(nic.szInfoTitle, aTitle, _countof(nic.szInfoTitle)); // Empty title omits the title line entirely.
288 tcslcpy(nic.szInfo, aText, _countof(nic.szInfo)); // Empty text removes the balloon.
289 if (!Shell_NotifyIcon(NIM_MODIFY, &nic) && (nic.dwInfoFlags & NIIF_USER))
290 {
291 // Passing NIIF_USER without NIIF_LARGE_ICON on Windows 10.0.19018 caused failure,
292 // even though a small icon is displayed by default (without NIIF_USER), the docs
293 // indicate it should work, and it works on Vista. There's a good chance that
294 // removing the flag and trying again will produce the desired result, or at least
295 // show a TrayTip without the icon, which is preferable to complete failure.
296 nic.dwInfoFlags &= ~NIIF_USER;
297 Shell_NotifyIcon(NIM_MODIFY, &nic);
298 }
299 return OK; // i.e. never a critical error if it fails.
300}
301
302
303

Callers

nothing calls this directly

Calls 1

TrayTipParseOptionsFunction · 0.85

Tested by

no test coverage detected