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

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


TTN_NEEDTEXT Notification from ToolTip Control

Alan J. Livingston -- livingst@villagenet.com
Tuesday, September 24, 1996

Environment: VC++ 4.0, NT 3.51
------------------------------

Hi!,

I'm having a problem with tool tip controls.  I've added a tool to a ToolTip
Control using  LPSTR_TEXTCALLBACK for the text of the control.

According to the docs this is supposed to generate TTN_NEEDTEXT
notifications to the parent window.  Instead I get TTN_NEEDTEXTW (Wide
character version) even though I don't have _UNICODE defined.  What have I
done wrong?

- Alan




IK 23 -- Cunningham@tgd.swissptt.ch
Thursday, September 26, 1996

[Mini-digest: 6 responses]

nothing its just that the common controls are unicode compiled on winNT.
If you want to use your code on NT and 95 you have to take account of
this and catch both.
Graham Cunningham
00 41 31 338 0633

>----------
>From: 	Alan J. Livingston[SMTP:livingst@villagenet.com]
>Sent: 	Dienstag, 24. September 1996 22:58
>To: 	mfc-l@netcom.com
>Subject: 	TTN_NEEDTEXT Notification from ToolTip Control
>
>Environment: VC++ 4.0, NT 3.51
>------------------------------
>
>Hi!,
>
>I'm having a problem with tool tip controls.  I've added a tool to a
>ToolTip
>Control using  LPSTR_TEXTCALLBACK for the text of the control.
>
>According to the docs this is supposed to generate TTN_NEEDTEXT
>notifications to the parent window.  Instead I get TTN_NEEDTEXTW (Wide
>character version) even though I don't have _UNICODE defined.  What
>have I
>done wrong?
>
>- Alan
>
>
-----From: Mario Contestabile

>According to the docs this is supposed to generate TTN_NEEDTEXT
>notifications to the parent window.  Instead I get TTN_NEEDTEXTW (Wide
>character version) even though I don't have _UNICODE defined.  What have I
>done wrong?

Nothing. Both TTN_NEEDTEXTW and TTN_NEEDTEXTA get sent.
Just check for either one.
NMHDR* pNMHDR       = (NMHDR*)lParam;
LPTOOLTIPTEXTA TTextA = (LPTOOLTIPTEXTA)lParam;
LPTOOLTIPTEXTW TTextW = (LPTOOLTIPTEXTW)lParam;
if(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW){
   #ifndef _UNICODE
      if (pNMHDR->code == TTN_NEEDTEXTA)
         lstrcpyn(TTextA->szText, Tip, 78);
      else
         _mbstowcsz(TTextW->szText, Tip, 78);
   #else
      if (pNMHDR->code == TTN_NEEDTEXTA)
         _wcstombsz(TTextA->szText, Tip, 78);
      else
         lstrcpyn(TTextW->szText, Tip, 78);
   #endif
}

mcontest@universal.com

-----From: "Matthias Bohlen" 

Hello Alan,

you have not done anything wrong, it is simply Windows NT that wants to have 
the tooltip text as wide characters, regardlesse of whether you have a 
Unicode-enabled application or not.

I have had the same problem and used the following code (sorry for the lack 
of Hungarian notation :-))

BOOL CLCToolBar::on_tooltip_notify (UINT, NMHDR *pNMHDR, LRESULT *)
{
    TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
    UINT        nID   = pNMHDR->idFrom;

    UINT     nCode    = pNMHDR->code;
    CString  csz      = get_tooltip_text (nID);

    if (csz.GetLength() > 78)
        csz = csz.Left (78);

    // Windows 95 calls us with TTN_NEEDTEXTA, the "A" stands for ANSI.
    // Give it the ANSI string directly.
    if (nCode == TTN_NEEDTEXTA)
        strcpy (pTTT->szText, csz);
    else
        // Windows NT calls us with TTN_NEEDTEXTW, the "W" stands for wide
        // characters. 
        // Convert from ANSI to wide characters, first. 
        
        VERIFY(
                MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, csz, csz.GetLength()+1,
                                     (LPWSTR) pTTT->szText,
                                     sizeof(pTTT->szText)
                                    )
                != 0 
              );

    pTTT->lpszText = pTTT->szText;
    pTTT->hinst    = NULL;
    return(TRUE);
}

Hope this helps!
Matthias

o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o

The ZEN master: "If you have a stick, I'll give you a
stick. If you have not, I'll take that stick away from
you".

The banker: "If you have money, I'll give you money.
If you have not, I'll take that money away from you".

----------------------------+--------------------------
Matthias Bohlen             |  Logotec Software GmbH
Phone: +49 228 64 80 520    |  Chateauneufstr. 10 
FAX:   +49 228 64 80 525    |  D-53347 Alfter, Germany
                            |  http://www.logotec.com/
E-mail: mattes@logotec.com  |  CAD systems development
----------------------------+--------------------------
-----From: Pradeep Tapadiya 

We have had this problem too. Whether or not one defines UNICODE,
one always seems to get TTN_NEEDTEXTW. I guess this means either
(a) you are not doing anything wrong or (b) both of us are doing
something wrong :). 

Anyways, we just ended up using TTN_NNEDTEXTW.

Pradeep
pradeep@nuview.com

-----From: Bill Berry 

Examples of using dynamic and static tool tips:

Since you want to use LPSTR_TEXTCALLBACK you need to add the ON_NOTIFY macro to your project. 
To do this just add the following code (see TN061:ON_NOTIFY and WM_NOTIFY Messages):

Sorry I don't have time for more explanation, but I believe the following will get you
started.

Steps Involved:
---------------

1. Create your own tool tip class; see my notes below why you should 
do this.
/////////////////////////////////////////////////////////////////////////////


// CMyToolTipCtrl

//Note: Windows sends mouse messages to the window underneath; for a tool tip
//      to work correctly it must receive the mouse messages that would
//      normally go to the window below.  The CToolTipCtrl has no 
//      implementation at this time as far as I can tell that automatically
//      takes care of relaying mouse messages for you;  What CToolTipCtrl
//      can do for you is do its own subclassing.  Thus the new member 
//      functions listed below.
//
//

class CMyToolTipCtrl : public CToolTipCtrl
{
// Implementation
public:
    BOOL AddToolTip(CWnd*, LPCSTR);
};

BOOL CMyToolTipCtrl::AddToolTip(CWnd* pWnd, LPCSTR lpszText)
{
    TOOLINFO ti;

    // typedef struct {  // ti  
    //	 UINT       cbSize; 
    //	 UINT       uFlags; 
    //	 HWND       hwnd; 
    //	 UINT       uId; 
    //	 RECT       rect; 
    // 	 HINSTANCE  hinst; 
    //	 LPTSTR     lpszText; 
    // } TOOLINFO, NEAR *PTOOLINFO, FAR *LPTOOLINFO; 
 
    ti.cbSize = sizeof(TOOLINFO);
    ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS | TTF_CENTERTIP;
    ti.hwnd =  pWnd->GetParent()->GetSafeHwnd();
    ti.uId = (UINT)pWnd->GetSafeHwnd();
    ti.hinst = AfxGetInstanceHandle();
    ti.lpszText = (LPTSTR)lpszText;
    
    return (BOOL)SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ti);

}


2. Add ON_NOTIFY( TTN_NEEDTXT, NULL, YourGetToolTipTextFunction ) to your message map.

3. void YourClass::YourGetToolTipTextFunction( NMHDR* p_nmhdrNotify, LRESULT* plResult )
   {
	    static INT nTest;

	    LPTOOLTIPTEXT pToolTipInfo = (LPTOOLTIPTEXT)p_nmhdrNotify;

            CString csz;
	    csz.Format( "Dynamic Test %d.", nTest++ );
	    ::lstrcpy( pToolTipInfo->szText, (LPCTSTR)csz );
	
   }

    example useage:

    void COptionsDlg::InitToolTips()
    {
        m_crtlToolTips.Create(this);

    // Add a Static Tool Tip
        m_ctrlToolTips.AddToolTip( GetDlgItem( IDC_CHK_AUTO_UPDATE ), MAKEINTRESOURCE( IDS_AUTO_UPDATE ) );

    // Add a Dynamic Tool Tip
       m_ctrlToolTips.AddToolTip( GetDlgItem( IDC_CHK_DYNAMIC ),  LPSTR_TEXTCALLBACK );

    }



							-Bill Berry

/////////////////////////////////////////////////////////////////////////////
// CMyToolTipCtrl message handlers
-----From: Kostya Sebov 

There's NO TTN_NEEDTEXT code -- is's a macro, which is TTN_NEEDTEXTA or TTN_NEEDTEXTW
depending on the _UNICODE #define.

You are NOT doing anything wrong. It depends on the system with what type
(Ansi or Unicode) of code it WM_NOTIFY'es you _by default_. However, you may tell
the system to send you a particular type. As far as I remember you should handle
some message (or WM_NOTIFY code) and set the LPARAM-pointer variable to the
corresponding value. Sorry, I cannot provide you with more concrete info --
search the docs.

Alternatively, you can handle both types as MFC does. See WINFRM.CPP for their
implementation of the TTN_NEEDTEXTx.

Hope this'll help!

--- 
Kostya Sebov. 
----------------------------------------------------------------------------
Tel: (38 044) 266-6387 | Fax: (38 044) 266-6195 | E-mail: sebov@is.kiev.ua




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