开发者

Delphi: How make my own Hint Window?

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 m开发者_运维百科ust close on "task change", "form change". How to do it?

THanks for your help: dd


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜