views:

775

answers:

5

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?

A: 

bk1e here says that the limit is 128 chars, now, if you use UTF-16, which is the native unicode format in windows and especially .NET, that means you are limited to 64 characters, including the NUL.

I would believe that you're using a unicode API which limits tooltips to 64 16-bit characters (including the null), and that VNC Server uses ascii (or ANSI) api's instead, allowing the use of 128 8-bit characters (including the null).

Arafangion
Where did you find 32-bit characters? I want some too!
configurator
I don't think they exist, strictly speaking, but UTF-32 uses them as a convenience even though it only needs about 24-bits per character. :)It's odd, though - I suspect that windows uses UTF-16, so it is curious why they've limited it to 64 characters. Maybe they're allowing for surrogates?
Arafangion
I would merely suspect that this is a typical bullshit limit. Someone at MS came up with 64 characters and that's how it is. No rocket science involved, or there simply would not be a limit like this.
ypnos
See http://catb.org/~esr/jargon/html/C/C-Programmers-Disease.html :-)
Jeffrey Hantin
+3  A: 

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.

bk1e
+1  A: 

Expanding on bk1e's correct answer.

Under the hood, a system tray icon in WinForms is implemented as a Win32 Notify Icon. Therefore the winforms version has all of the limitations as the native one. The tooltip size limitation is just one example.

JaredPar
+4  A: 

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 });
      }
    }
Hans Passant
A: 

Thanks!

Helped me to workaround 64char-Limit for NotifyIcon.Text in some seconds.

Thilo

Thilo Bauer