Thanks for your suggestions. For a note, I didnt originally write the tool 
tip code, I pulled it off some web site. I've been going through it myself 
and noticed how sloppy it was lol. I have used the hint system but this 
tooltips looks better with the bubble style window. You're suggestions are 
helpful, but in my own code, sometimes a global variable is the only 
solution at the time. I have a few such as flags for preventing other code 
from being ignited such as call backs and a count variable for a recursive 
function that I cant seem to make it work without the variable being global. 
Perhaps I'll shoot another mail on that.

----- Original Message ----- 
From: "Rob Kennedy" <[EMAIL PROTECTED]>
To: "Delphi-Talk Discussion List" <[email protected]>
Sent: Wednesday, December 14, 2005 5:51 PM
Subject: Re: tooltips question


> Richard R wrote:
>> 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
>
> That which you create, you should delete.
>
>> and also do I need to send a
>> TTM_DELTOOL message when my program terminates?
>
> That's not strictly neccessary since the tooltip is being destroyed
> anyway. I would expect the tooltip window to free any of its internal data
> structures automatically when it's destroyed. On the other hand, refer to
> my response to the previous sentence.
>
>> Also how would I turn this
>> feature on and off?
>
> If you have a tooltip defined, but you want to disable it temporarily,
> then send it a ttm_Activate message. While a tooltip is deactivated, it
> will not appear on the screen, even if the mouse pauses over the tool
> area. Re-enable a tooltip by sending it another ttm_Activate message.
>
>> 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);
>
> The hWnd parameter should be declared with the HWnd type, not Cardinal.
> HWnd is declared for you in the Windows unit. (Yes, you are allowed to
> have a parameter with the same name as its type.)
>
>> 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);
>
> Please refrain from using global variables. If CreateTooltips creates a
> new window, have it return a handle to that window as its function result.
>
>>  if hToolTip <> 0 then
>>  begin
>>    SetWindowPos(hToolTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or
>>      SWP_NOSIZE or SWP_NOACTIVATE);
>
> I'm not sure you need to do that. The tooltip window should already create
> itself with the top-most style if that's what tooltips are supposed to
> have.
>
>>    ti.cbSize := SizeOf(TToolInfo);
>
> The ti variable should definitely be a local variable.
>
>>    ti.uFlags := TTF_SUBCLASS;
>>    ti.hInst := hInstance;
>
> You don't do anything with the values you set here.
>
>>  end;
>> end;
>>
>> procedure AddToolTip(hwnd: dword; lpti: PToolInfo; IconType: Integer;
>> Text, Title: PChar);
>
> This time, you declared your hwnd parameter as a DWord. It should be HWnd,
> just like the previous function.
>
>> var
>>  Item: THandle;
>>  Rect: TRect;
>> begin
>>  Item := hWnd;
>>  if (Item <> 0) AND (GetClientRect(Item, Rect)) then
>>  begin
>>    lpti.hwnd := Item;
>
> What is lpti? Not another global variable, I hope.
>
>>    lpti.Rect := Rect;
>>    lpti.lpszText := Text;
>>    SendMessage(hToolTip, TTM_ADDTOOL, 0, Integer(lpti));
>>    FillChar(buffer, sizeof(buffer), #0);
>
> Another global variable? Splendid.
>
>>    lstrcpy(buffer, Title);
>
> The previous call to FillChar isn't necessary since you're just copying
> the new string over what you just cleared. Lstrcpy will always put a null
> character on the end. On the other hand, lstrcpy might write beyond the
> end of the buffer. Use Delphi's SysUtils.StrLCopy function instead. It
> only copies up to a specified maximum length.
>
>>    if (IconType > 3) or (IconType < 0) then IconType := 0;
>>    SendMessage(hToolTip, TTM_SETTITLE, IconType, Integer(@buffer));
>
> Since you're just passing a pointer to the buffer, you really don't need
> to copy the Title PChar anywhere at all. Just pass Title directly to
> SendMessage:
>
> SendMessage(hTooltip, ttm_SetTitle, IconType, LParam(Title));
>
>>  end;
>> end;
>>
>> procedure TForm.FormCreate(Sender: TObject)
>> begin
>>   CreateToolTips(Handle);
>
> A form's Handle property can change sometimes, especially while the object
> is being created. You should override the CreateWindowHandle method
> instead. That function is called each time the form creates a window for
> itself. You should also override DestroyWindowHandle, which is called just
> before a form destroys its window handle. Update your tooltip control
> accordingly, since its parent window (and thus any tool regions defined)
> will have to change.
>
>>   AddToolTip(ListBox1.Handle, @ti, 1, 'Tooltip text', 'Title');
>
> What's wrong with simply setting the list box's Hint property? Make sure
> you set its ShowHint property to True, or set the parent's ShowHint
> property to True and set the list box's ParentShowHint property to True.
> To temporarily disable hints for a control or for an entire form, use the
> ShowHint property again.
>
> -- 
> Rob
>
>
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk
> 
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to