Discussion:
Tooltips disappear when compiled under Unicode
(too old to reply)
Psychopasta
2010-08-27 17:23:19 UTC
Permalink
Raw Message
Hi,

I'm having problems getting Unicode tooltips to work. Here's my code:

// Description:
// Creates a tooltip for an item in a dialog box.
// Parameters:
// idTool - identifier of an dialog box item.
// nDlg - window handle of the dialog box.
// pszText - string to use as the tooltip text.
// Returns:
// The handle to the tooltip.
//
HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText)
{
if (!toolID || !hDlg || !pszText)
{
return FALSE;
}
// Get the window of the tool.
HWND hwndTool = GetDlgItem(hDlg, toolID);

// Create the tooltip. g_hInst is the global instance handle.
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP |TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
g_hInst, NULL);

if (!hwndTool || !hwndTip)
{
return (HWND)NULL;
}

// Associate the tooltip with the tool.
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hDlg;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hwndTool;
toolInfo.lpszText = pszText;
SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);

return hwndTip;
}

It works fine under ANSI but just plain-doesn't-work when I use
Unicode. Can anyone see what I'm doing wrong?

- Pasta
Psychopasta
2010-08-27 17:30:16 UTC
Permalink
Raw Message
Post by Psychopasta
It works fine under ANSI but just plain-doesn't-work when I use
Unicode. Can anyone see what I'm doing wrong?
- Pasta
I should add that the whole app is Unicode enabled, and this is the
only piece that doesn't work...

- P
Guillermo Amodeo
2010-09-09 14:25:30 UTC
Permalink
Raw Message
I had the same problem and found your question googling for the answer few days ago, now that I fixed it, I'll tell you how in case you have not yet fixed your problem.

I re-defined the TOOLTIP struct as someone said in a forum somewhere and it did work for him (and for me too).

typedef struct {
UINT cbSize;
UINT uFlags;
HWND hwnd;
UINT_PTR uId;
RECT rect;
HINSTANCE hinst;
LPWSTR lpszText;
LPARAM lParam;
} myTOOLINFO;

...

myTOOLINFO ti;

ti.cbSize=sizeof(myTOOLINFO);
...

SendMessageW(hwndToolTip,TTM_ADDTOOLW,0,(LPARAM)&ti);



Submitted via EggHeadCafe - Software Developer Portal of Choice
A Comparison of Managed Compression Algorithms
http://www.eggheadcafe.com/tutorials/aspnet/71485ecc-2d2d-435a-9c35-3d12b279f9ae/a-comparison-of-managed-compression-algorithms.aspx
Psychopasta
2010-09-13 15:19:06 UTC
Permalink
Raw Message
Thank you! I'll give that a try!

- Pasta
Psychopasta
2010-09-13 17:19:54 UTC
Permalink
Raw Message
Hi again Guillermo,

Thank you so much!. It works!!!

There is a 4 byte difference between the two structures. It appears
the MS Winxx API docs and declarations are just plain wrong. I'm
shocked they have not fixed this - using the documented structure the
feature will never work as documented. Wild.

But thanks again,

- Pasta
n***@rtrussell.co.uk
2010-09-14 08:18:27 UTC
Permalink
Raw Message
Post by Psychopasta
There is a 4 byte difference between the two structures. It appears
the MS Winxx API docs and declarations are just plain wrong.
I don't think so. According to MSDN the structure is declared as
follows:

typedef struct {
UINT cbSize;
UINT uFlags;
HWND hwnd;
UINT_PTR uId;
RECT rect;
HINSTANCE hinst;
LPTSTR lpszText;
#if (_WIN32_IE >= 0x0300)
LPARAM lParam;
#endif
#if (_WIN32_WINNT >= Ox0501)
void *lpReserved;
#endif
} TOOLINFO;

so the length depends on the values of _WIN32_IE and _WIN32_WINNT:

http://msdn.microsoft.com/en-us/library/bb760256.aspx

Richard.
http://www.rtrussell.co.uk/
Psychopasta
2010-09-14 15:45:53 UTC
Permalink
Raw Message
Hi Richard,

Thanks for that! I was using that structure, as documented. The
problem is, even if the windows version is greater than 501, the
*lpReserved does not exist - including it causes the tooltip functions
to fail to work, without error or report. It appears those constants,
which are supposed to be defined inside of the windows headers itself,
are not properly defined in the tooltip libraries. This is a screw up
on the MS side as far as I can see and we can't fix it as the tooltips
are part of the common controls libs that come with windows. If we
simply omit the lpReserved parameter, which is unused anyway,
everything works fine.

But I'm totally up for being corrected if you think I'm missing
something. I'd really like to be able to use 100% boilerplate code.

- Pasta
Psychopasta
2010-09-14 15:55:01 UTC
Permalink
Raw Message
Hi again Richard,

BTW, I should point out that the code MS give works fine with ANSI
text. Its when Unicode is ON that it fails.

- P

Loading...