Tooltips not working on MSW
brianhray at gmail.com
brianhray at gmail.com
Fri Jan 5 08:20:46 PST 2007
I could not get the tooltips to work on MSW in my situation. So
instead, I made a work around. The work around is posted here in case
if gives someone else any clue what went wrong.
#ifdef __WXMSW__
void MSWToolTipHack(HWND hwnd,wxString strTT)
{
INITCOMMONCONTROLSEX iccex;
HWND hwndTT;
TOOLINFO ti;
unsigned int uid = 0;
LPTSTR lptstr = (char*) strTT.mb_str(wxConvUTF8);
RECT rect;
iccex.dwICC = ICC_WIN95_CLASSES;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCommonControlsEx(&iccex);
hwndTT = CreateWindowEx(WS_EX_TOPMOST,
TOOLTIPS_CLASS,
NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hwnd,
NULL,
wxGetInstance(),
NULL
);
SetWindowPos(hwndTT,
HWND_TOPMOST,
0,
0,
0,
0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
GetClientRect (hwnd, &rect);
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hwnd;
ti.hinst = wxGetInstance();
ti.uId = uid;
ti.lpszText = lptstr;
ti.rect.left = rect.left;
ti.rect.top = rect.top;
ti.rect.right = rect.right;
ti.rect.bottom = rect.bottom;
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
}
#endif // __WXMSW__
/* Usage (works with other controls also): */
class MywxTextCtrl: public wxTextCtrl
{
public:
// ... other stuff
#ifdef __WXMSW__
void SetToolTip( const wxString &tip ) {
MSWToolTipHack((HWND)GetHWND(), tip); }
#endif
}
So, I just overwrote the SetToolTip(). Because it was working on other
platforms, I just if-def'ed for MSW.
This fixes my tooltips on MSW, but still am wondering why it did not
work. Possibly, it has something to do with the fact that I am running
this in a DLL. Maybe the HINSTANCE used by wx is different than the
one it wants. Or, maybe because this code uses HWNDs only, it fixes in
this regard. Or maybe its some other subtle thing. All I know is that
with the code above it works, but if I just call SetToolTip on the
control, it does not.
-- Brian Ray (http://kazavoo.com)
More information about the wx-users
mailing list