Solved

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

Posted on 2004-09-15
8
1,186 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Template syntax for variable length arrays 9 75
Best way to accomplish this task? 3 87
Dialogbox API leak? 18 94
What .NET URL re-routing tool did I use? 2 56
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…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

770 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