Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show a systray tooltip longer than 63 chars?

Tags:

How can I show a systray tooltip longer than 63 chars? NotifyIcon.Text has a 63 chars limit, but I've seen that VNC Server has a longer tooltip.

How can I do what VNC Server does?

like image 550
Jeno Csupor Avatar asked Feb 23 '09 22:02

Jeno Csupor


2 Answers

Actually, it is a bug in the property setter for the Text property. The P/Invoke declaration for NOTIFYICONDATA inside Windows Forms uses the 128 char limit. You can hack around it with Reflection:

using System;
using System.Windows.Forms;
using System.Reflection;

    public class Fixes {
      public static void SetNotifyIconText(NotifyIcon ni, string text) {
        if (text.Length >= 128) throw new ArgumentOutOfRangeException("Text limited to 127 characters");
        Type t = typeof(NotifyIcon);
        BindingFlags hidden = BindingFlags.NonPublic | BindingFlags.Instance;
        t.GetField("text", hidden).SetValue(ni, text);
        if ((bool)t.GetField("added", hidden).GetValue(ni))
          t.GetMethod("UpdateIcon", hidden).Invoke(ni, new object[] { true });
      }
    }
like image 184
Hans Passant Avatar answered Sep 29 '22 22:09

Hans Passant


From the MSDN documentation on the Win32 NOTIFYICONDATA structure:

szTip

A null-terminated string that specifies the text for a standard ToolTip. It can have a maximum of 64 characters, including the terminating null character.

For Windows 2000 (Shell32.dll version 5.0) and later, szTip can have a maximum of 128 characters, including the terminating null character.

It looks like the Windows Forms library supports the lowest common denominator here.

like image 36
bk1e Avatar answered Sep 29 '22 22:09

bk1e