Solved

ATL Toolbar button, does not receive  TTN_NEEDTEXT notification when I enable WinXP styles

Posted on 2004-09-15
8
1,219 Views
Last Modified: 2013-11-25
ATL Toolbar button, does not receive  TTN_NEEDTEXT notification when I enable WinXP styles


here's my message map


class CMyToolBar : public CWindowImpl<CMyToolBar, CToolBarCtrl>

{

....
BEGIN_MSG_MAP(CMyToolBar)

NOTIFY_CODE_HANDLER(TTN_NEEDTEXT, OnToolTipNotify)

DEFAULT_REFLECTION_HANDLER()

END_MSG_MAP()

.....
LRESULT OnToolTipNotify(int idCtrl, LPNMHDR pNotifyStruct, BOOL& bHandled);  <----function signature
}






to get the toolbar to display with WinXP theme/style, I need to include this in my resource file

2 RT_MANIFEST "res\\MyManifest.manifest"

(manifest file is xml stuff)

When I include this in resource file my tooltips don't work.

When I comment out the line in the resource file, I don't get WinXP style for my toolbar buttons, but my tooltips are restored and do work.

In other words, when using WinXP style-I get no tooltips, when I disable WinXP style by commenting out line, my toolbar button tooltips work

(ie I receive the TTN_NEEDTEXT message, where-as when WinXP style is enabled I don't seem to receive this TTN_NEEDTEXT  message)




(PS It's ATL Toolbar NOT MFC Toolbar)
0
Comment
Question by:esgi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
8 Comments
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12072817
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12073676
Better try to watch with SPY++ who catches that message.
0
 

Author Comment

by:esgi
ID: 12075621
Using message hook would not be good solution, too much overhead.

I originally tried using Spy++, and that didn't help. All I could see were the standard NCHITTEST messages + WM_PAINT, etc...

Let me just back track a second.
Originally I did this...
class CMyToolBar : public CWindowImpl<CMyToolBar, CToolBarCtrl>

{

BEGIN_MSG_MAP(CMyToolBar)

NOTIFY_CODE_HANDLER(TTN_NEEDTEXT, OnToolTipNotify)

DEFAULT_REFLECTION_HANDLER()

END_MSG_MAP()

LRESULT OnToolTipNotify(int idCtrl, LPNMHDR pNotifyStruct, BOOL& bHandled);

}

LRESULT CMyToolBar::OnToolTipNotify(int idCtrl, LPNMHDR pNotifyStruct, BOOL& bHandled)
    {
    const int MAX = 100;
    TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNotifyStruct;
    UINT nID = pNotifyStruct->idFrom;

    if ((nID > 0) && (nID < idUserCommand)) // ID'S OF BUTTONS I'm interested in......
        {
        CString str;
        str.LoadString(nID);
        strcpy(pTTT->szText, (const char*)str);
        pTTT->hinst = _AtlBaseModule.m_hInst;
        return(TRUE);
        }
    return(FALSE);
    }


The tooltips worked perfectly.
When I added the

2 RT_MANIFEST "res\\MyManifest.manifest"    (manifest file is xml stuff)

This enabled the toolbar buttons to display in WinXP style....BUT now my tooltips were blown away. No tooltips showed, not even tooltips with garbage text.

I tried this as one possible solution.....

MESSAGE_HANDLER(WM_NOTIFY, OnToolTipNotify)

LRESULT CMyToolBar::OnToolTipNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
    USES_CONVERSION;
    NMTTDISPINFO *ttdi;
    ttdi = (NMTTDISPINFO *)lParam;

    if(ttdi->hdr.code & TTN_NEEDTEXT)
        {
        NMTTDISPINFO* pNotifyStruct=(NMTTDISPINFO*)lParam;
        UINT nID = pNotifyStruct->hdr.idFrom;
        TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNotifyStruct;
        if ((nID > 0) && (nID < idUserCommand))
            {
            CString str;
            str.LoadString(nID);
            strcpy(pTTT->szText, (const char*)str);
            pTTT->hinst = _AtlBaseModule.m_hInst;
           bHandled = TRUE;
            }
        }
    bHandled = FALSE;
    return 0L;
    }



but for some reason, the code inside the (NOTE: INSIDE BLOCK....since of course their will be other notification I'm not interested in)

  if(ttdi->hdr.code & TTN_NEEDTEXT)
        {...}


does get hit, but still no tool tip, oddly, the notification gets called repeated till the stack is blown,

as if the notification is not removed from message queue.


0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:esgi
ID: 12079478
will close case, I found solution, will post it tomorrow..
0
 

Author Comment

by:esgi
ID: 12162968
admins, please close question
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12167425
0
 

Accepted Solution

by:
esgi earned 0 total points
ID: 12173369
When not using WinXP style, the original post on doing tooltips is sufficient, note especially this line of code

 strcpy(pTTT->szText, (const char*)str);

But when using WinXP style toolbar buttons it must instead be done this way...


    BEGIN_MSG_MAP(CMyToolBar)
        MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
        DEFAULT_REFLECTION_HANDLER()
    END_MSG_MAP()


LRESULT CMyToolBar::OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
    // need to handle both ANSI and UNICODE versions of the message
    NMTTDISPINFO* pNMHDR=(NMTTDISPINFO*)lParam;

    if ((pNMHDR->hdr.code == TTN_NEEDTEXT) || (pNMHDR->hdr.code == TTN_NEEDTEXTA) || (pNMHDR->hdr.code == TTN_NEEDTEXTW))
        {
        UINT nID = 0;
        CString strTipText;

        TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
        TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
        TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;

        nID = pNMHDR->hdr.idFrom;

        if ((nID > 0) && (nID < idUserCommand))
            {
            strTipText.LoadString(nID);
            if (strTipText.GetLength() == 0)
                return FALSE;
            }

        static TCHAR szBuff[200] = { 0 }; //needs to be static
        memset(szBuff, 0, sizeof(szBuff));
        UINT s = sizeof(szBuff);
        pTTTA->lpszText = (LPSTR)szBuff;  <-- NOTE THE MOST IMPORTANT CHANGE. I use lpszText NOT szText field



        if (OSIsNT())// ALSO NEED TO COPY DIFFERENTLY FOR DIFFERENT OS's
            {
            if ((pNMHDR->hdr.code == TTN_NEEDTEXT) || (pNMHDR->hdr.code == TTN_NEEDTEXTA))
                lstrcpyn(szBuff, strTipText, sizeof(szBuff));
            else // if (pNMHDR->hdr.code == TTN_NEEDTEXTW)
                _mbstowcsz((wchar_t*)szBuff, strTipText, sizeof(szBuff));
            }

        return TRUE;    // message was handled
        }

    return FALSE;    // message was NOT handled
    }
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question