15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CToolTipCtrl question

Roger M. -- RUNDEWOOD@cerner.com
Monday, September 16, 1996

Environment: VC++ 4.0, Win 95

I have derived a class from CWnd and would like for it to display
tooltips.  However, I want it to display different tooltips based upon
which part of the window the cursor is over.  Currently, the
CToolTipCtrl only works for an entire HWND, not parts of it.  Any idea
how I can get this to happen?



Mike Lainhart -- lainhart@kaitain.sp.trw.com
Tuesday, September 17, 1996

[Mini-digest: 6 responses]

At 10:24 AM 09/16/96 -0500, you wrote:
>Environment: VC++ 4.0, Win 95
>
>I have derived a class from CWnd and would like for it to display
>tooltips.  However, I want it to display different tooltips based upon
>which part of the window the cursor is over.  Currently, the
>CToolTipCtrl only works for an entire HWND, not parts of it.  Any idea
>how I can get this to happen?
>

If you haven't discovered Jeff Prosise's book "Programming Windows 95 with
MFC", do yourself a favor and run to the store and get it.  
Yesterday I was reading about CToolTipCtrl in that book and it mentioned
that there is an overload for AddTool that allows you to specify a
rectangular region in the window.  (I just looked to see what version of MFC
the book was written to it says VC++ 4.0 or better, so you should be able to
find that version of AddTool.)

-----From: "Eric Kenslow" 


No problem at all.  To make a tooltip respond differently to different
rectangles within a window, use code similar to the following within your
CWnd-derived class:

m_ctrlTip.AddTool( this, "The Tip", CRect( left, right, top, bottom ),
iTool );

This IS well documented (I figured it out all by myself, so it must be ;]).

A sudden flash of thought hit me- you're looking at the EnableToolTip()
(not sure if that's the exact name) member of CWnd, aren't you?  I believe
that using that function only allows for a 1-to-1 mapping of tips to
windows.  But, as the code above demonstrates, if you simply add a
CToolTipCtrl member to your window you gain a great deal of flexibility.

/* Eric Kenslow - Digital Lighthouse Inc.
 * webmaster@digilight.com
 * http://www.digilight.com
 */

-----From: "Manos D. Anastasiadis" 

If you look the docs for CToolTipCtrl::AddTool(),
you'll see that you can specify a rectangle of a tool. You
may add as many tools as you like, provided you specify
different rectangles and tool ids. I have used this and it 
works for non-window rectangles (but you better *not*
specify overlapping rects.)
However, I cant't think of a way to use CToolTipCtrl
in conjuction with non-rectangular regions...

/*==================================*
 * Manos D. Anastasiadis            *
 * Computer Engineer                *
 * Technical University of Crete    *
 * Mu.S.I.C.                        *
 * manos@ced.tuc.gr                 *
 *==================================*/

-----From: Stuart Downing 

Since CToolTipCtrl is informed about mouse activity in your window via
RelayEvent, in your window's PreTranslateMessage, you could screen for
WM_MOUSEMOVE events, and call UpdateTipText depending on
the coordinates to WM_MOUSEMOVE.  I haven't tried this, but I think
it should work.

-----From: Doug Persons 

Mark Conway has explained this in detail at:
http://ourworld.compuserve.com/homepages/mrconway/tooltip.htm

-- 
Doug Persons                206-822-6800    persons@esca.com
Cegelec ESCA Corporation    Bellevue, WA    http://www.esca.com
-----From: Niels Ull Jacobsen 

If you add a tool tip to the window, try=20
adding "tools" *without* the TTF_IDISHWND flag. In this way, uId will=20
simply be an application-defined value. If you window has three different
"hot spots",
add 3 "tools" with uId's 1, 2 and 3.

In your OnToolHitTest, set the appropriate number in the pTI->uId if a ho=
t
spot is hit (and remember to clear TTF_IDISHWND from pTI->uFlags). Return=
 1.
If no hotspot is hit, return -1.

If you use callback tooltip text, you can inspect the
pNMHDR->idFrom to get the id of the hotspot you should provide text for.

  =20

Niels Ull Jacobsen [MVP], Kr=FCger A/S (nuj@kruger.dk)
Everything stated herein is THE OFFICIAL POLICY of the entire Kruger=20
group and should be taken as legally binding in every respect.=20
Pigs will grow wings and fly.









| Вернуться в корень Архива |