Problem with tooltips on Windows

Bill Baxter dnewsgroup at billbaxter.com
Tue May 20 10:27:31 PDT 2008


Bill Baxter wrote:
> snippets\tooltips\Snippet41 does not work properly for me.  Instead of 
> the intended tooltip text I see random strings of Japanese characters.
> It could be related to the fact that my default codepage is set to 932 
> (Japanese).  Probably for someone else it would just look like random 
> garbage instead of random Japanese garbage.
> 
> --bb

I think the problem may be in Shell.d:1690, this function:

void setToolTipText (NMTTDISPINFO* lpnmtdi, char [] buffer) {
     ...
     if (!hasCursor ()) return;
     auto hHeap = OS.GetProcessHeap ();
     if (lpstrTip !is null) OS.HeapFree (hHeap, 0, lpstrTip);
     int byteCount = buffer.length;
     lpstrTip = cast(TCHAR*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, 
byteCount);
     OS.MoveMemory (lpstrTip, buffer.ptr, byteCount);
     lpnmtdi.lpszText = lpstrTip;
}

It's taking a utf8 string and pointing to it with a TCHAR* which is 
actually a wide char string type.

This fixes it for me:

void setToolTipText (NMTTDISPINFO* lpnmtdi, char [] buffer) {
     /*
     * Ensure that the current position of the mouse
     * is inside the client area of the shell.  This
     * prevents tool tips from popping up over the
     * shell trimmings.
     */
     if (!hasCursor ()) return;
     auto hHeap = OS.GetProcessHeap ();
     if (lpstrTip !is null) OS.HeapFree (hHeap, 0, lpstrTip);
     TCHAR[] tbuffer = StrToTCHARs(buffer);
     int byteCount = tbuffer.length * TCHAR.sizeof;
     lpstrTip = cast(TCHAR*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, 
byteCount);
     OS.MoveMemory (lpstrTip, tbuffer.ptr, byteCount);
     lpnmtdi.lpszText = lpstrTip;
}


--bb


More information about the Digitalmars-d-dwt mailing list