Solved

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

Posted on 2004-09-15
8
1,209 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
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem updating Access table using VB code 8 58
Vb.Net Loading Word 11 107
Dir function fails on mapped drives 28 148
VS2015 Redefinition errors 4 87
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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