I have 2 regions in a window, each with their own tooltip.
these tooltips are custom drawn by handling the WM_PAINT message (to prevent flicker).
This is the creation of the tooltips:
tooltips[MAIN_GRAPH_TT].tthWnd = CreateWindowEx(WS_EX_TOPMOST,TOOLTIPS_CLASS,0,WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_NOFADE,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,g_hInst,0);
tooltips[SECONDARY_GRAPH_TT].tthWnd = CreateWindowEx(WS_EX_TOPMOST,TOOLTIPS_CLASS,0,WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_NOFADE,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,g_hInst,0);
This is initialisation of the tooltips:
if (tooltips[MAIN_GRAPH_TT].tthWnd)
{
lpfnOldTTProc = (WNDPROC)SetWindowLong(tooltips[MAIN_GRAPH_TT].tthWnd,
GWL_WNDPROC, (DWORD) TooltipProc);
SetWindowLong(tooltips[MAIN_GRAPH_TT].tthWnd, GWL_EXSTYLE, WS_EX_LAYERED|WS_EX_TOOLWINDOW);
SetLayeredWindowAttributes(tooltips[MAIN_GRAPH_TT].tthWnd,RGB(255,0,0),0,ULW_COLORKEY);
SendMessage(tooltips[MAIN_GRAPH_TT].tthWnd,CWM_SETWNDPROC,0,(LPARAM)new WNDPROC(lpfnOldTTProc));
}
if (tooltips[SECONDARY_GRAPH_TT].tthWnd)
{
lpfnOldTTProc = (WNDPROC)SetWindowLong(tooltips[SECONDARY_GRAPH_TT].tthWnd, GWL_WNDPROC, (DWORD) TooltipProc);
SetWindowLong(tooltips[SECONDARY_GRAPH_TT].tthWnd, GWL_EXSTYLE, WS_EX_LAYERED|WS_EX_TOOLWINDOW);
SetLayeredWindowAttributes(tooltips[SECONDARY_GRAPH_TT].tthWnd,RGB(255,0,0),0,ULW_COLORKEY);
SendMessage(tooltips[SECONDARY_GRAPH_TT].tthWnd,CWM_SETWNDPROC,0,(LPARAM)new WNDPROC(lpfnOldTTProc));
}
And this is the WM_PAINT of the custom tooltip WNDPROC:
case WM_PAINT:
{
const int FRAME_WIDTH = 1;
const int CORNER_DIAMETER = 10;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd,&ps);
HDC hMemDC;
RECT cr;
GetClientRect(hWnd,&cr);
hMemDC = CreateCompatibleDC(hdc);
HBITMAP memBM = CreateCompatibleBitmap(hdc, cr.right-cr.left, cr.bottom-cr.top);
HBITMAP hOldBM = (HBITMAP) SelectObject(hMemDC,memBM);
//drawing start [draw to hMemDC]
{
FillSolidRect(hMemDC,0,0,cr.right-cr.left,cr.bottom-cr.top,RGB(255,0,0));
HPEN hFramePen = CreatePen(PS_SOLID,FRAME_WIDTH,BLACK);
HBRUSH hBGBrush = GetSysColorBrush(COLOR_INFOBK);
SetTextColor(hMemDC,GetSysColor(COLOR_INFOTEXT));
SetBkColor(hMemDC,WHITENESS);
SetBkMode(hMemDC,TRANSPARENT);
HBRUSH hOldBrush = (HBRUSH) SelectObject(hMemDC,hBGBrush);
HPEN hOldPen = (HPEN) SelectObject(hMemDC,hFramePen);
HFONT hOldFont = SelectFont(hMemDC,g_hFonts[FONT_TOOLTIP]);
RoundRect(hMemDC,cr.left,cr.top,cr.right,cr.bottom,CORNER_DIAMETER,CORNER_DIAMETER);
RECT textRec = cr;
textRec.left += FRAME_WIDTH*2;
textRec.right -= FRAME_WIDTH*2;
textRec.top += FRAME_WIDTH*2;
textRec.bottom -= FRAME_WIDTH*2;
if(hWnd == tooltips[MAIN_GRAPH_TT].tthWnd)
DrawText(hMemDC,tttBuffer[MAIN_GRAPH_TT],sizeof(tttBuffer),&textRec,DT_LEFT|DT_TOP);
else if(hWnd == tooltips[SECONDARY_GRAPH_TT].tthWnd)
DrawText(hMemDC,tttBuffer[SECONDARY_GRAPH_TT],sizeof(tttBuffer),&textRec,DT_LEFT|DT_TOP);
SelectObject(hMemDC,hOldBrush);
SelectObject(hMemDC,hOldPen);
SelectObject(hMemDC,hOldFont);
DeleteObject(hFramePen);
DeleteObject(hBGBrush);
}
//drawing end
BitBlt(hdc,
cr.left,
cr.top,
cr.right-cr.left, cr.bottom-cr.top,
hMemDC,
0,
0,
SRCCOPY);
SelectObject(hdc,hOldBM);
DeleteObject(memBM);
DeleteDC(hMemDC);
EndPaint(hWnd,&ps);
}
break;
The problem with these tooltips is, the corners (outside of the round rect) are supposed to be transparent, but i cant seem to get them to dissapear.
I have tried (naívely) to use HOLLOW_BRUSH to paint the background rect, but didnt work, and as you can see from the example i’ve tried using the layered window approach, again to no avail.
Can anyone help me get transparency for the background of my tooltips?
Here is a picture of the tooltip without transparency
[the corners have been recoloured white for visibility — these are the parts that need to be transparent]
(Text blanked out)

You can use
SetWindowRgnto make parts of a window transparent (create a region usingCreateRoundRectRgn).Alternatively, you can use
SetLayeredWindowAttributesto use true alpha blending to make parts of the window transparent.