Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Adding hint windows to applications


How can I pop up a hint window?   

    You can either programmatically move the mouse pointer over the control with the hint, or you can display a hint window of your own;

    Example # - programmatically moving the mouse.

    procedure TForm .Button Click(Sender: TObject); var pt : TPoint; begin {Let the button repaint} Application.ProcessMessages; {Get the screen coordinates of the center of the button} pt := ClientToScreen(Point(Button .Left + Button .Width div 2, Button .Top + Button .Height div 2)); {Position the cursor at the center of the button} SetCursorPos(Pt.x, Pt.y); end; Example #2 - Creating you own hint window. For this example, you will need a TPanel and a TTimer component. The Panel will be used as the hint window, and will be invisible untill called. The timer will hide the panel after a specified duration. procedure TForm .FormCreate(Sender: TObject); begin Timer .Enabled := false; Panel .Visible := false; Panel .BevelInner := bvNone; Panel .BevelOuter := bvNone; Panel .BorderStyle := bsSingle; Panel .Color := clWhite; Button .Hint := 'Hint test'; end;

    procedure TForm .ShowAHint(x : integer; y : integer; Caption : string; Duration : LongInt); var dc : hdc; OldFont : hFont; pt : TSize; p : pChar; begin if Timer .Enabled <> false then Timer .Enabled := false; Timer .Enabled := false; if Panel .Visible <> false then Panel .Visible := false; if Caption = '' then exit; Panel .Caption := caption; {Get the width of the caption string} GetMem(p, Length(Panel .Caption) + ); StrPCopy(p, Panel .Caption); dc := GetDc(Panel .Handle); OldFont := SelectObject(dc, Panel .Font.Handle); GetTextExtentPoint32(dc, p, Length(Panel .Caption), pt); SelectObject(dc, OldFont); ReleaseDc(Panel .Handle, Dc); FreeMem(p, Length(Panel .Caption) + ); {Position and show the panel} Panel .Left := x; Panel .Top := y; Panel .Width := pt.cx + 6; Panel .Height := pt.cy + 2; Panel .Visible := true; {Fire off the timer to hide the panel} Timer .Interval := Duration; Timer .Enabled := true; end;

    procedure TForm .Timer Timer(Sender: TObject); begin if Panel .Visible <> false then Panel .Visible := false; Timer .Enabled := false; end;

    procedure TForm .Button Click(Sender: TObject); begin {Let the button repaint} Application.ProcessMessages; ShowAHint(Button .Left, Button .Top + Button .Height + 6, Button .Hint, 2000); end;

    7/ 6/98 4:3 :28 PM

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use