views:

70

answers:

1

Hello, I am trying to give my ComboBox an in place tooltip for long strings. However when I call SetWindowPos on the tooltip, the position is never changed. Called when TTN_SHOW is received:

::SetWindowPos(textTooltip, NULL, TipRect.left, TipRect.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);

If I remove the SWP_NOSIZE flag and pop in some values into the width/height, then the combo box changes size to these values but the position remains the same. SetWindowPos always returns TRUE.

The tip is initialised like so:

        textTooltip = CreateWindowEx(WS_EX_TRANSPARENT, TOOLTIPS_CLASS, NULL, TTS_NOPREFIX, 0, 0, 0, 0, this->GetSafeHwnd(), NULL, NULL, NULL);
        if(!textTooltip)
            return;

        ZeroMemory(&ToolInfo, sizeof(TOOLINFO));
        ToolInfo.cbSize = sizeof(TOOLINFO);
        ToolInfo.uFlags = TTF_TRANSPARENT | TTF_SUBCLASS; 
        ToolInfo.hwnd = this->GetSafeHwnd();
        ToolInfo.lpszText = "place holder"; //set in OnSelectChangeOk
        ToolInfo.uId = 0;   
        ToolInfo.rect = TipRect; //rect is re-set in OnSelectChangeOk

        ::SendMessage(textTooltip, TTM_ADDTOOL, 0, (LPARAM)&ToolInfo);

Am I missing something?

+1  A: 

Hi, you gotta do ::SendMessage(hToolWnd, TTM_TRACKPOSITION, 0, MAKELPARAM(x, y)); and set the TTF_ABSOLUTE flag in the ToolInfo.uFlags member!

Fore more information, refer to: http://msdn.microsoft.com/en-us/library/bb760422(VS.85).aspx

humbagumba
Won't this require me to manually show/hide the tooltip though? TTF_ABSOLUTE requires TTF_TRACK also be set, which means that I have to use TTM_TRACKACTIVE and TTM_TRACKPOSITION. I have considered this approach, maybe checking for WM_MOVE messages, then showing up the tip but it is a little dirtier than I would hoped. I was basing my implementation from http://blogs.msdn.com/b/oldnewthing/archive/2006/06/26/647365.aspx?PageIndex=2 and http://msdn.microsoft.com/en-us/library/bb760252(VS.85).aspx#tooltip_sample_inplace
YoungPony
ok.. the code from me was used for a balloon tool tip which always should pop up at a specified position. Do you also send TTM_ADJUSTRECT and return TRUE after receiving the TTN_SHOW notification, like in the article you mentioned? The comment after the return TRUE says "suppress default positioning" so perhaps you forgot this?
humbagumba
Yea, The return TRUE prevents the standard routine being called for the message. I have taken a slightly different route now and I am calling TrackMouseEvent to get ON_WM_MOUSEHOVER messages, then on the hover I manually move and display the tooltip. Not as clean but it seems to do the job.
YoungPony