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

Tooltip for disabled controls

459 views
Skip to first unread message

Georg Deisinger

unread,
Mar 14, 1998, 3:00:00 AM3/14/98
to

Hallo!
How can I display tooltips for disabled controls (for example CEdit)??
I have my own CEdit derived class and handle the
"ON_NOTIFY_EX(TTN_NEEDTEXT......)-message" inside my class.
Everything works well as long as the control is enabled. What can I do
to get the above mentioned message passed to my disabled control?

Thanks!
Georg
georg.d...@t-online.de

Ken Rhodes

unread,
Mar 17, 1998, 3:00:00 AM3/17/98
to

George,
I was having a similar problem with a disabled
edit box but it was surrounded by a groupbox.
The group box was stopping the CEdit box from
receiving "messages?" Anyway, I was able to
ignore the group box in my OnToolHitTest() and
all seems to work now. Check out

Knowledge Base Q172276, Bug: CToolTipCtrl Not
Displaying After VS SP1 and SP2 Install.
Also, Q167650, Q133257, Q141758, Q143313
Ken

Georg Deisinger <Georg.D...@t-online.de> wrote in article
<6ee9jt$8sf$1...@news01.btx.dtag.de>...

David Lowndes

unread,
Mar 19, 1998, 3:00:00 AM3/19/98
to

>How can I display tooltips for disabled controls (for example CEdit)??
>I have my own CEdit derived class and handle the
>"ON_NOTIFY_EX(TTN_NEEDTEXT......)-message" inside my class.
>Everything works well as long as the control is enabled. What can I do
>to get the above mentioned message passed to my disabled control?

Georg,

I wrestled with this same problem several weeks ago. For an MFC dialog
I found the following works for me:

The CWnd class has its own tooltip control built in. Therefore all I
do is:

BEGIN_MESSAGE_MAP(CMfcDlgttDlg, CDialog)
//{{AFX_MSG_MAP(CMfcDlgttDlg)
...
//}}AFX_MSG_MAP
ON_NOTIFY_EX( TTN_NEEDTEXT, 0, HandleNeedText )
END_MESSAGE_MAP()

BOOL CMfcDlgttDlg::HandleNeedText( UINT id, NMHDR * pNMHDR, LRESULT *
pResult )
{
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
UINT nID =pNMHDR->idFrom;
if (pTTT->uFlags & TTF_IDISHWND)
{
// idFrom is actually the HWND of the tool
nID = ::GetDlgCtrlID((HWND)nID);
if(nID)
{
/* Assumes you have a string resource with the
same ID as the dialog control ID for the tooltip text */
pTTT->lpszText = MAKEINTRESOURCE(nID);
pTTT->hinst = AfxGetResourceHandle();
return(TRUE);
}
}
return(FALSE);
}

And in OnInitDialog I call EnableToolTips().

There's no tooltip control to add/create, no AddTool calls, and no
PreTranslateMessage needed. It seems to work fine for me. Let me know
if it works for you (if you try it of course).

Dave
----
Address is altered to discourage junk mail.
Remove ".---" for the real address.

Georg Deisinger

unread,
Mar 20, 1998, 3:00:00 AM3/20/98
to

Dave,

my implementation code for the "ON_NOTIFY_EX" - message is similar to your
sample code.
I also override the "virtual int CWnd::OnToolHitTest" method to provide
different information than the default provides (for example I set the hwnd
and uId of the TOOLINFO structure to the handle of my own CEdit derived
class ("this>m_hWnd")
and "lpszText = LPSTR_TEXTCALLBACK" etc.).
All these things (and "EnableToolTips()") are done within !! my own CEdit
derived class.
So every parent of my control class (View/CDialog etc) can take advantage
of the tooltips( the "GetParent()->EnableToolTips()" is done from my control
too).
As long as my control is enabled it works fine (the parent of my control is
a View).
The framework calls my control "OnToolHitTest" and the
"ON_NOTIFY_EX"-message is passed to my control and activates my method and
the tooltips are displayed.
But when I disable my control it seems to me as if no "WM_NOTIFY" - message
(or no message at all ?) is passed to my control.
So the above mentioned methods are not activated and tooltips are not
displayed.

My problem: What can I do to get messages passed to my disabled control ??

Georg

David Lowndes wrote in message <351f4f66...@msnews.microsoft.com>...

David Lowndes

unread,
Mar 27, 1998, 3:00:00 AM3/27/98
to

>As long as my control is enabled it works fine (the parent of my control is
>a View).
>The framework calls my control "OnToolHitTest" and the
>"ON_NOTIFY_EX"-message is passed to my control and activates my method and
>the tooltips are displayed.
>But when I disable my control it seems to me as if no "WM_NOTIFY" - message
>(or no message at all ?) is passed to my control.
>So the above mentioned methods are not activated and tooltips are not
>displayed.

Georg,

I'm afraid the more I find about tooltips the less I understand them.
If I get time I'll try to do something like you have to see if I get
the same problem.

One of the biggest issues seems to be quite what MFC does with the
tooltip - I've looked at the code several times, but not having an
in-depth understanding of how the native tooltip control works I find
it's difficult to really know if there are problems in how MFC handles
things or not. VC5 sp2 apparently introduced some problems with
tooltips but I believe they were remedied in sp3.

Ray Auchterlounie

unread,
Apr 3, 1998, 3:00:00 AM4/3/98
to


David Lowndes <dav...@mvps.org.---> wrote in article
<352e0645...@msnews.microsoft.com>...


> >As long as my control is enabled it works fine (the parent of my control
is
> >a View).

[...]

> One of the biggest issues seems to be quite what MFC does with the
> tooltip - I've looked at the code several times, but not having an

There lies possible answers. Look at RelayToolTipMessage() in MFC
(TOOLTIP.CPP)
- it changes the window handle of the message (calling the tooltip itself
to find the right window).
Looks like disabled windows don't actually get messages sent to them and
the tooltip will
therefore not match the window handle.

I have made tooltips work for disabled controls on a dialog by using the
DevStudio Tooltips component and modifying the code it adds to
PreTranslateMessage() to do the same translation
as MFC does in RelayToolTipMessage().

Unfortunately all the MFC tooltip stuff appears to rely on
PreTranslateMessage which never happens in an ActiveX control... does
anyone know how to do tooltips in an MFC activeX control ?

[ yes I know there are examples in the docs, but they are all
one-tooltip-over-one-window, I want
tooltips over lots of different child windows, on dialogs, toolbars etc.
- within an ActiveX control ].

> in-depth understanding of how the native tooltip control works I find
> it's difficult to really know if there are problems in how MFC handles
> things or not. VC5 sp2 apparently introduced some problems with
> tooltips but I believe they were remedied in sp3.

Not all of them, at least from my point of view. eg:

Try using CWnd::EnableToolTips() in an activex control as described in the
1997 MSJ article titled
"Tiptoe Through the ToolTips With Our All-Encompassing ToolTip Programmer's
Guide"
(also in MSDN). Then put said control in an MFC container, and watch the
asserts fly (in debug versions) or the spectacular lack of any tooltips (in
release).

MFC uses one common tooltip and tries to pass it CWnd pointers to it across
modules. CWnd handle map is per thread/module... bang.

Ray Auchterlounie
<r...@apso.com>

0 new messages