uses CommCtrl;
const
TTS_BALLOON = $40;
TTI_NONE = 0;
TTI_INFO = 1;
TTI_WARNING = 2;
TTI_ERROR = 3;
TTM_SETTITLEA = WM_USER + 32;
procedure SetHint(
Handle: hWnd; dwIconType: DWORD; lpText, lpTitle: PChar; dwFlags: DWORD = TTS_BALLOON);
var
TI: TToolInfo;
trRect: TRect;
hHint: THandle;
begin
if (
Handle <> 0)
and (GetClientRect(
Handle, trRect))
then
begin
hHint := CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS,
nil, TTS_NOPREFIX
or WS_POPUP
or dwFlags,
Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
Handle, 0, hInstance,
nil);
SetWindowPos(hHint, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE
or SWP_NOSIZE
or SWP_NOACTIVATE);
ZeroMemory(@TI, sizeof(TToolInfo));
with TI
do
begin
cbSize := sizeof(TToolInfo);
hwnd :=
Handle;
uId :=
Handle;
hInst := hInstance;
uFlags := TTF_SUBCLASS
or TTF_IDISHWND;
Rect := trRect;
lpszText := lpText;
end;
SendMessage(hHint, TTM_ADDTOOL, 0, LPARAM(@TI));
SendMessage(hHint, TTM_SETTITLEA, dwIconType, LPARAM(PChar(lpTitle)));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetHint(Button1.Handle, TTI_INFO, '
My Text ...', '
Info');
end;