Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unicode tooltips

219 views
Skip to first unread message

Robert Scott

unread,
Dec 5, 2007, 7:49:47 AM12/5/07
to
I have a non-unicode Win32 app, but in one place I would like to use wide
characters - in the tooltips for a toolbar. I don't want to set the global
compile flag for Unicode because that would require that I visit every instance
of a string and change it to wide characters. But here is why I think I can use
Unicode is just one spot.

I have already verified that I can force a wide character version of
SetWindowText by explicitly calling it SetWindowTextW and using a wide character
string for the second parameter. So what about tooltips? Here is my existing
handler for the tooltip notification message:

case WM_NOTIFY:
LPNMHDR pnmh = (LPNMHDR)lParam;
if(pnmh->code == TTN_NEEDTEXT)
{
LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam;
LPSTR pReply = (***some char string***);
lstrcpy(lpttt->szText,pReply);
}
break;

Now the message TTN_NEEDTEXT is defined as TTN_NEEDTEXTA for a non-Unicode
compile and TTN_NEEDTEXTW for a Unicode compile. But if I change my
TTN_NEEDTEXT to TTN_NEEDTEXTW I have verified that such a message is never sent
to my window proc. So something is telling the system that my code is not
Unicode. But what is it? My toolbar is created with:

hwndTB = CreateToolbarEx(
hwndParent,
(WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
CCS_TOP | TBSTYLE_TOOLTIPS),
1, // Child window ID #
22, // number of images in TOOLS.BMP
instMain,
207, // Bitmap resource ID
tbb, // pointer to TBBUTTON array
sizeof(tbb)/sizeof(TBBUTTON), // iNumButtons
0,0,
24, // dxBitmap
24, // dyBitmap
sizeof(TBBUTTON));

I see nothing in this call that tells the system whether I am Unicode or not, so
why do I just get TTN_NNEDTEXTA notification messages and not TTN_NEEDTEXTW
messages? I am running on WinXP.

Any idea as to the correct method to force Unicode tooltips without converting
the whole project over to Unicode?


Robert Scott
Ypsilanti, Michigan

Sam of California

unread,
Dec 6, 2007, 10:43:01 PM12/6/07
to
I suspect that it is not as easy as you hope, but I think you can answer
this question yourself using Spy++. Set a breakpoint in the WM_CREATE to get
the handle. Then use the handle in Spy++ to see what other messages are sent
to the window. There is one sent very soon after WM_CREATE, perhaps the next
one after WM_CREATE, that determines whether the window is Unicode or not.

I know about the message because there is (was) a bug in MFC, but I forget
the details of the bug; I understood the problem quite well in the past but
now I have forgotten. I hope it is easy enough to find the relevant message
using the technique I describe above.


"Robert Scott" <---@---> wrote in message
news:4756996a...@newsgroups.comcast.net...

Sam of California

unread,
Dec 6, 2007, 11:09:42 PM12/6/07
to
Sorry, ignore my first reply; the message I was referring to seems to be a
MFC-only thing.

Sam of California

unread,
Dec 6, 2007, 11:15:19 PM12/6/07
to
Since there are not separate CreateToolbarEx functions for Unicode and not
for Unicode, I suspect that the tooltips use Unicode if and only if the
window uses Unicode.

"Robert Scott" <---@---> wrote in message
news:4756996a...@newsgroups.comcast.net...

Robert Scott

unread,
Dec 7, 2007, 5:50:28 AM12/7/07
to
On Thu, 6 Dec 2007 20:15:19 -0800, "Sam of California"
<sam...@social.rr.com_change_social_to_socal> wrote:

>Since there are not separate CreateToolbarEx functions for Unicode and not
>for Unicode, I suspect that the tooltips use Unicode if and only if the
>window uses Unicode.

Yes, I am beginning to suspect that the Unicode information is being extracted
from the parent window (the first parameter to CreateToolbarEx). Anyway, this
is all academic now because I have resigned myself to the fact that if I want to
support Unicode in tooltips I will have to convert the entire application to
Unicode (at least as far as any string handling that involves the Win32 API).


Robert Scott
Ypsilanti, Michigan

Robert Scott

unread,
Dec 7, 2007, 9:02:25 PM12/7/07
to
OK, I have made my application all Unicode by setting the global UNICODE. So I
can set Unicode Tooltips, but I can't see any Asian characters, and I have
looked through all 65536 characters. This computer displays Asian fonts
correctly in Wordpad. What more do I need to do to see Asian tooltips?


Robert Scott
Ypsilanti, Michigan

Sam of California

unread,
Dec 8, 2007, 7:48:47 AM12/8/07
to
All 65536 characters of what font? What font are you using for the Tooltips?


"Robert Scott" <---@---> wrote in message

news:4759fb29...@newsgroups.comcast.net...

Robert Scott

unread,
Dec 8, 2007, 5:23:40 PM12/8/07
to
On Sat, 8 Dec 2007 04:48:47 -0800, "Sam of California"
<sam...@social.rr.com_change_social_to_socal> wrote:

>All 65536 characters of what font? What font are you using for the Tooltips?

I have not explicitly selected a font. So whatever default font tooltips use is
what I have.


Robert Scott
Ypsilanti, Michigan

Sam of California

unread,
Dec 9, 2007, 4:35:01 AM12/9/07
to
"Robert Scott" <---@---> wrote in message
news:475b1942...@newsgroups.comcast.net...

> On Sat, 8 Dec 2007 04:48:47 -0800, "Sam of California"
> <sam...@social.rr.com_change_social_to_socal> wrote:
>
>>All 65536 characters of what font? What font are you using for the
>>Tooltips?
>
> I have not explicitly selected a font. So whatever default font tooltips
> use is
> what I have.


Then probably the font is not a Unicode font with the characters you need. I
am sorry I cannot help more than that; I hope someone can.

Sam of California

unread,
Dec 9, 2007, 4:45:46 AM12/9/07
to
"Robert Scott" <---@---> wrote in message
news:475b1942...@newsgroups.comcast.net...

> On Sat, 8 Dec 2007 04:48:47 -0800, "Sam of California"
> <sam...@social.rr.com_change_social_to_socal> wrote:
>
>>All 65536 characters of what font? What font are you using for the
>>Tooltips?
>
> I have not explicitly selected a font. So whatever default font tooltips
> use is
> what I have.


Based on the documentation of Tooltip Controls, you can send them a
WM_GETFONT. That can be done for diagnostic purposes. If the font is not a
Unicode font with the characters you need, then you can be confident that
you need to change the font. I am not sure how to do that, but based on the
documentation, it appears that a WM_SETFONT will help.

Robert Scott

unread,
Dec 9, 2007, 1:46:18 PM12/9/07
to
On Sun, 9 Dec 2007 01:45:46 -0800, "Sam of California"
<sam...@social.rr.com_change_social_to_socal> wrote:

>"Robert Scott" <---@---> wrote in message

>Based on the documentation of Tooltip Controls, you can send them a
>WM_GETFONT. That can be done for diagnostic purposes. If the font is not a
>Unicode font with the characters you need, then you can be confident that
>you need to change the font. I am not sure how to do that, but based on the
>documentation, it appears that a WM_SETFONT will help.

Well, I found that the HFONT does not tell you much until it is selected into a
DC. But you did point me in the right direction, because I found TB_GETTOOLTIPS
to get the handle to the tooltip control from the toolbar window handle. Then I
used GetDC() on that tooltip handle to get a DC for it. Using the DC I finally
called GetTextFace(), which yielded "System". No surprise there, I guess. So
apparently "System" is not a Unicode font. So my plan is now to get a specific
Unicode font with the Asian characters I need, then after the toolbar is
created, use CreateFont() and WM_SETFONT on the tooltips handle. I'll let you
know how it goes.


Robert Scott
Ypsilanti, Michigan

Robert Scott

unread,
Dec 10, 2007, 3:43:41 PM12/10/07
to
Success! I got Asian tooltips working without having to install Supplemental
Language Support. I just installed a specific Unicode font (arialuni.ttf), and
then use CreateFont and WM_SETFONT to make that the font for the tooltip window.

Thanks for all the advice!


Robert Scott
Ypsilanti, Michigan

Robert Scott

unread,
Jan 4, 2008, 6:28:57 PM1/4/08
to
Here is how things turned out on my project to get foreign language tooltips on
my application toolbar, which was the subject of a thread here about a month
ago.

Back then I reported here that I had successfully gotten a little test program
to display Unicode tooltips by getting a handle to the tooltips window using the
TB_GETTOOLTIPS message to the toolbar. Then I sent WM_SETFONT to the tooltip
window. Furthermore, the test application was compiled with the UNICODE and
_UNICODE symbols defined.

Then I began to apply what I had learned to my real application. It seemed that
I had to convert the entire application to Unicode. I soon realized that it
would be a huge job because the application used strings in many many places.
And if I really had to convert the entire application over to Unicode, I would
have to examine each and every instance where a string is used to see if it had
to be converted and if different string-handling functions had to be used. Of
course this would have been much simpler if I had written the application
initially using the Unicode-neutral functions. But I was ignorant of this stuff
10 years ago when I first wrote this application.

Fortunately I have found that it is not necessary to convert the entire
appliction to Unicode to get Unicode tooltips. Here is what I did.

I segregated into one file the following functions:

1. MyRegisterClass (where I call RegisterClass for my main window class)
2. MyCreateWindow (where I call CreateWindow for my main window)
3. MyDefWindowProc (where I call DefWindowProc for all message that my WndProc
does not handle)
4. MyInitToolbar (where I call CreateToolbarEx)
5. MyWmNotify (where I respond to the WM_NOTIFY message by checking for
TTN_NEETTEXT and if so, responding with the correct Unicode tooltip text)

This one file was compiled with the UNICODE and _UNICODE symbols defined before
any windows includes. Of course I could not use the pre-compiled header that I
used for all the other files in my application because of this difference. But
this allowed me to leave all the other files in ASCII mode. Even the main
WndProc was left in an ASCII mode file. And it all seems to be working
perfectly.

Now I might have done the same thing by explicitly calling out all the Unicode
versions of Win32 API functions, like RegisterClassW and CreateWindowW. But
that was too prone to error. This way it is all automatic. Having one little
file where UNICODE is defined ensured that these functions will play together
properly.

So to those who say that the only way to do Unicode is to set Unicode for the
entire application, I can now say that it is not necessary.


Robert Scott
Ypsilanti, Michigan

0 new messages