?
Solved

Hint Boxes

Posted on 2005-05-13
12
Medium Priority
?
414 Views
Last Modified: 2010-08-05
Greetings Experts,

I was wondering how easy it was to create personalised hint boxes, which contain images. This is something i have been thinking about, since installing Trillian (instant messenger). In Trillian, if you hover over any of your contacts, the hint box displays several piece of information, nicely formatted, aswell as a small image of the persons display picture.

I have taken a screenshot so you can see an example of what i mean, without having to install trillian first. You can see this here....    http://www.habbar.co.uk/EE/hints.PNG

It would be great if anyone knew of a component which made this extremely easy to do.

Regards
- Jay
0
Comment
Question by:Greenandroid
  • 7
  • 4
12 Comments
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 14000883
You can create a simple form and use it as a hint.
0
 
LVL 11

Accepted Solution

by:
ZhaawZ earned 2000 total points
ID: 14000987
Well, I made some example for you that shows how to customize default hint windows. This is first time I try it ;) It's not difficult.


To make custom hint windows, you'll have to make your own class from THintWindow and assign it's name to HintWindowClass variable (look at the bottom of example). There's a little problem - as far as I know, this customized hint window will be used for *all* controls in application. I solved this problem by adding some identifier to hint message (to be able to use both customized hint message with image, label and other controls on it AND to be able to use a simple hint messages at the same time). This identificator is '+' symbol in an example.

To put some images or other custom controls on hint window, you'll have to override constructor and destructor. Create all the controls you need in constructor and don't forget to destroy all of them in destructor.

There's also a constant HintInfo that holds information for hints (a hint identificator, filename to image and some text info). You may make it as a constant (if information will not change at runtime) or as a variable (if you'll need to change info at runtime).

The main part of example is overriding ActivateHint procedure. I tried to explain everything I wrote there. If you have some questions like 'why is it so' - just ask ;)

To use new hint window:
* assign it's name (type) to variable HintWindowClass (I did this in onCreate event)
* set Form1.ShowHint to true
* fill HintInfo array with some information (if you're using example that's below - don't forget to change filenames. I used 128x128px images)
* put some control on form
* assign some hint to it

For example - if Button1.Hint is '+first', then hint window will be customized (with custom size, image, label etc) and it will take information from HintInfo array where id = 'first', but if Button1.Hint = '+asf', then the simple hint message will be shown because there's not id 'asf' in HintInfo array. Also if Button1.Hint = 'first', then the simple hint message will be shown because hint doesn't start with '+' symbol.



unit Unit1;

interface

uses
  Windows, Classes, Forms, StdCtrls, ExtCtrls, jpeg, Controls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure FormCreate(Sender: TObject);
  end;
  TMyHintWnd = class(THintWindow)
    private
      img : TImage;
      lbl : TLabel;
    public
      constructor Create(AOwner : TComponent); override;
      destructor  Destroy; override;
      procedure   ActivateHint(Rect: TRect; const AHint: string); override;
  end;

var
  Form1: TForm1;

const
  HintInfo : array [0..1] of record
    id   : string;
    pic  : string;
    info : string;
  end = (
    (id: 'first' ; pic: 'D:\`serwer\pukjiite.jpg'; info: 'some unuseful info'),
    (id: 'second'; pic: 'D:\`serwer\tbr.jpg'     ; info: 'blahybla'          )
  );

implementation

{$R *.dfm}

constructor TMyHintWnd.Create(AOwner : TComponent);
begin
inherited;
img := TImage.Create(self);
with img do begin
  Parent := self;
  Left   := 10;
  Top    := 10;
  Width  := 128;
  Height := 128;
end;
lbl := TLabel.Create(self);
with lbl do begin
  Parent := self;
  Left := 150;
  top := 20;
end;
end;

destructor TMyHintWnd.Destroy;
begin
img.Destroy;
lbl.Destroy;
inherited;
end;

procedure TMyHintWnd.ActivateHint(Rect: TRect; const AHint: string);
var
  hint : string;
  n : integer;
begin
hint := ahint;
img.Visible := false; // hide 'extra' components, because it's not needed to show
lbl.Visible := false; //   them in common hints
if hint[1] = '+' then begin // check if this is 'special' hint
  delete(hint, 1, 1);
  for n := 0 to high(HintInfo) do begin // search for information
    if HintInfo[n].id = hint then begin // found info, show it
      img.Picture.LoadFromFile(HintInfo[n].pic); // load image
      lbl.Caption := HintInfo[n].info; // show some info
      rect.Right := rect.Left + 350; // set width  of hint window
      rect.Bottom := rect.Top + 148; // set height of hint window
      img.Visible := true; // show image
      lbl.Visible := true; // show label
      hint := ''; // delete hint message
      break; // stop searching for information
    end;
  end;
end;
inherited ActivateHint(rect, hint);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
HintWindowClass := TMyHintWnd;
end;

end.
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 14001021
Forgot to say - if you want to change background color of hint, just assign desired color to Application.HintColor in TForm().onCreate event
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Greenandroid
ID: 14002588
Your example compiles fine for me, but your customised hints do not show (instead i get the normal style hints).
I am also dubious whether your code would be the most efficient method for producing the hint boxes (as shown in the link i gave above). Perhaps you could send me a working example, my details you can find in my profile.
0
 
LVL 16

Expert Comment

by:CodedK
ID: 14002633
As ZhaawZ mentioned why dont u create a form ?
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 14002678
Check your e-mail.
0
 
LVL 2

Author Comment

by:Greenandroid
ID: 14002722
i think you forgot to attach the file. could you resend please
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 14002725
You wrote that you're dubious whether my code would be the most efficient method. I used Delphi help to customize hint window, so I think this way should be good enough.

As I already said - you may create some form that would be used like hint window where you show information, but it will not be real delphi hint window then. However, it can be much easier to create and use such window for somebody.

Btw, if you want the most efficient solutions, stop using Delphi Forms, SysUtils and other huge units with lots of unnecessary crap ;)
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 14002728
Check it again. Now it should be with attachment.
0
 
LVL 2

Author Comment

by:Greenandroid
ID: 14002795
Absolutely perfect!

Many thanks
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 14002798
Does it work now? If yes, what was the problem before (why didn't it work for you)?
0
 
LVL 2

Author Comment

by:Greenandroid
ID: 14003134
Yes it works fine now. I think the problem was i misread how to notify when a customised hint was needed, and hence i did not include '+' in the hint text.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question