How to format tooltip in win32?

D.D.K-2637 966 Reputation points
2022-08-17T07:53:45.497+00:00

Hi,
After initializing the tooltip, I want to set up few custom formats.
my part1 code as follow:

m_hWndTooltip = ::CreateWindowEx(0, TOOLTIPS_CLASS, 0, dwStyle,  
            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,  
            m_hParent, 0, m_hInstance, 0);  
TOOLINFO ti;  
//...setup ti;  
::SendMessage(m_hWndTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);  
if (SendMessage(m_hWndTooltip, TTM_TRACKACTIVATE, (WPARAM)TRUE, (LPARAM)&ti))  
{  
    NMTTCUSTOMDRAW nmh; //Initialize setting  
    RECT rec;  
    GetWindowRect(m_hWndTooltip, &rec);  
    ::SendMessage(m_hWnd, WM_NOTIFY, idFrom, (LPARAM)&nmh);  
}  

in part2, the NOTIFY called passed to winproc as follows:

case WM_NOTIFY:  
{  
switch (((LPNMHDR)lParam)->code)  
{  
  
    case NM_CUSTOMDRAW:  
        const auto& lpNMCustomDraw = (LPNMTTCUSTOMDRAW)lParam;   
        OnToolTipCustomDraw(lpNMCustomDraw);  
          
    break;  
}  

}
//--------------------------------------------------------------

LRESULT OnToolTipCustomDraw(NMTTCUSTOMDRAW* pcd)  
{  
  
 LRESULT result = CDRF_DODEFAULT;  
 switch (pcd->nmcd.dwDrawStage)  
 {  
 case CDDS_PREPAINT:  
 {  
  
 auto result1 = SetTextColor(pcd->nmcd.hdc, 0x000000FF);  
 if (CLR_INVALID == result1)  
 outputA("\nSet textcolor failded.");  
  
 result = CDRF_NOTIFYPOSTPAINT;  
 break;  
 }  
 }  
 return result;  
}  

however, after showing, the tooltip does not change format.
my question is:
Is the call setup for OnNotify correct or not? (i called it right after showing the tooltip)
Also, does the return value of OnToolTipCustomDraw work with winproc?

Thanks you!

Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Castorix31 91,416 Reputation points
    2022-08-17T09:10:09.71+00:00

    What is in DrawToolTipContent ?
    (CDDS_PREPAINT is not used for the colors with Tooltips)

    A quick test with FillRect and DrawText in CDDS_POSTPAINT :

    231930-tooltip-draw.gif

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.