void __fastcall ShowBalloonTip(TWinControl *Control, int Icon,
char *Title, char *Text)
{
HWND hBalloonTip;
HWND hPareWnd;
TOOLINFO ti;
int w = 0;
int h =0;
int Left = 0;
int Top = 0;
hPareWnd = Control->Handle;
hBalloonTip = CreateWindow(TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_BALLOON | TTS_ALWAYSTIP ,
0, 0, 0, 0,
hPareWnd, 0, HInstance, NULL);
if( hBalloonTip )
{
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_TRACK ;
ti.hwnd = hPareWnd;
ti.lpszText = Text;
SetWindowPos(hBalloonTip, HWND_TOPMOST,
0,0,0,0,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
//set color
// SendMessage(hWndTip, TTM_SETTIPBKCOLOR, BackCL, 0);
// SendMessage(hWndTip, TTM_SETTIPTEXTCOLOR, TextCL, 0);
SendMessage(hBalloonTip, TTM_ADDTOOL, WPARAM(1), LPARAM(&ti));
SendMessage(hBalloonTip, TTM_SETTITLE, WPARAM(Icon), LPARAM(Title));
// 定义气泡位置,粘附在指定控件旁边
GetWindowRect(hPareWnd, &ti.rect);
Left = ti.rect.left;
Top = ti.rect.top;
w = ti.rect.right - ti.rect.left;
h = ti.rect.bottom - ti.rect.top;
SendMessage(hBalloonTip,
TTM_TRACKPOSITION, WPARAM(0),
MAKELONG(w + Left,h + Top));
//显示气泡
SendMessage(hBalloonTip,
TTM_TRACKACTIVATE,
WPARAM(True), LPARAM(&ti));
//注意销毁窗口
}
}
ShowBalloonTip(edt1, TTI_INFO, "标题","我是一个气泡");