Hello, I want to implement tooltips feature into my software however I have
some questions about some code I found. Do I need to delete the window
created by CreateWindowEx using DeleteWindow and also do I need to send a
TTM_DELTOOL message when my program terminates? Also how would I turn this
feature on and off? I already made a property of type boolean for this, I'm
just not sure how to implement it. I'm still a newb with windows
programming, but I do know what's going on here.
Here's the code
const
TTS_BALLOON = $40;
TTM_SETTITLE = (WM_USER + 32);
var
count: longint;
hTooltip: Cardinal;
ti: TToolInfo;
buffer : array[0..255] of char;
procedure CreateToolTips(hWnd: Cardinal);
procedure AddToolTip(hwnd: dword; lpti: PToolInfo; IconType: Integer; Text,
Title: PChar);
Implementation
procedure CreateToolTips(hWnd: Cardinal);
begin
hToolTip := CreateWindowEx(0, 'Tooltips_Class32', nil, TTS_ALWAYSTIP or
TTS_BALLOON,
Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT), hWnd, 0, hInstance, nil);
if hToolTip <> 0 then
begin
SetWindowPos(hToolTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or
SWP_NOSIZE or SWP_NOACTIVATE);
ti.cbSize := SizeOf(TToolInfo);
ti.uFlags := TTF_SUBCLASS;
ti.hInst := hInstance;
end;
end;
procedure AddToolTip(hwnd: dword; lpti: PToolInfo; IconType: Integer; Text,
Title: PChar);
var
Item: THandle;
Rect: TRect;
begin
Item := hWnd;
if (Item <> 0) AND (GetClientRect(Item, Rect)) then
begin
lpti.hwnd := Item;
lpti.Rect := Rect;
lpti.lpszText := Text;
SendMessage(hToolTip, TTM_ADDTOOL, 0, Integer(lpti));
FillChar(buffer, sizeof(buffer), #0);
lstrcpy(buffer, Title);
if (IconType > 3) or (IconType < 0) then IconType := 0;
SendMessage(hToolTip, TTM_SETTITLE, IconType, Integer(@buffer));
end;
end;
procedure TForm.FormCreate(Sender: TObject)
begin
CreateToolTips(Handle);
AddToolTip(ListBox1.Handle, @ti, 1, 'Tooltip text', 'Title');
end;
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk