views:

184

answers:

1

Hi!

D6 Prof.

We have a special application with a special grid. It have a HintWindow what can show other informations that cannot place in cells. For example long memos. When you move the mouse to a cell, it is waiting for 2 sec, and show the informations.

The problem of this theme that HintWindow is not working properly, or in same way that normal "Hints" do.

Normal hints are appearing, and they are disappearing in these cases: - the hint showing time ellapsed - the the active form is deactivated - a new form shown - application replaced by another task (ALT + TAB)

But our HintWindow is cannot detect that new form showing, or application changed - it is remaining on the top, while until disapp. time... :-(

Another problem that we used "MouseMove" to detect the mouse changing - to start the Hint.

This event is happens also if the HintWindow disappears. So I need to protect against cyclic show with this code:

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
    Caption := INtTOStr(X) + ' ' + IntToStr(Y) + ' ' + IntToStr(GetTickCount);
    // If same coordinate I don't show it again
    if (LX <> X) or (LY <> Y) then begin
        miHint.DoActivateHint(Self, 'Anytext', 2000, 2000);
        LX := X; LY := Y;
    end;
end;

Without this LX, LY the HintWindow cyclically appears and dissappears.

So: we need to know how we make a HintWindow that is working in same method like application "Hint", but limited into this grid. It must close on "task change", "form change". How to do it?

THanks for your help: dd

+1  A: 

You'd better use the provided mechanism that show hints throughout the application, by replacing the HintWindowClass of the HintInfo parameter passed to the Application's OnShowHint event whenever you need to show a customized hint. Maybe you might find some useful implementation details below.

Old Answer:
In one older application I had a different hint class for list boxes and grids. The behavior is a bit scattered but basically it boiled down to;

All DBGrids in the Application is assigned some identifying hint, like: 'MyDBGridHint'. Application's OnShowHint event tests if passed 'HintInfo's 'HintControl' is a 'TCustomDBGrid', and if so calls a procedure passing the 'HintInfo'.

This procedure finds the cell the hint should be on by using Grid's MouseCoord method with HintInfo.CursorPos, gets the display text of the cell by temporarily changing Grid's DataLink. The procedure then creates a TCanvas and assigns its Handle a DC retrieved for the Grid, assigns the font of the grid to the Canvas and tests to see if the grid cell's boundary is sufficient to display the text. If it decides that the hint will be shown, assigns the cell text to HintInfo.HintStr and a derived hint window class to HintInfo.HintWindowClass, calculates the position, boundary, sets the font etc.. and returns.

Then OnShowHint event tests to see if HintStr is still the grid hint identifier (I have a comment in the code with "Owned controls by grids produce this."), and if so cancels the hint.

I'm not sure if trying to describe it like this can be of any help, but here is trying...

Sertac Akyuz
Ahhh... I forget to say that this control is a virtual grid, not based on VCL grid - it is based on customcontrol.So hints are coming from this class.But: I want to use not a "normal" hint that visible when you go to any control. I want to make that give info from the cells. So I need to catch the cursor moving.
durumdara
@durumdara - > "need to catch the cursor moving" - The `HintInfo` passed to the 'OnShowHint' event already has the cursor position, the implementation I described uses it to locate which cell the 'hint' would be on. I've also provided some links to the documentation now. Read them a bit...
Sertac Akyuz

related questions