Solved

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

Posted on 2004-09-15
8
1,168 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now