Solved

Getting the time of a dblClick (1000 points for quick good answer)

Posted on 2001-07-01
18
158 Views
Last Modified: 2010-08-05
hi need your help !!!


i need get the time of a dblclick with accuracy of
 1 millisecond how i do it ?


Igor.
0
Comment
Question by:igor84
  • 6
  • 6
  • 2
  • +4
18 Comments
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    lasttime: Cardinal;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var thistime: Cardinal;
begin
  thistime := GetTickCount;
  if thistime - lasttime < GetDoubleClickTime then
    Caption := IntToStr(thistime - lasttime)
  else
    Caption := 'to slow';
  lasttime := thistime;
end;

end.
0
 

Author Comment

by:igor84
Comment Utility
this function is to slow it gets upto 5 millisec i need upto 1 millisec  sorry ...
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
Doesn't that depend on the CPU speed...?
Here it is fast enough:


procedure TForm1.Button1Click(Sender: TObject);
begin
  Perform(WM_LBUTTONDOWN, 0, 0);
  Perform(WM_LBUTTONDOWN, 0, 0);
end;


When I press button1, it shows 1 in the caption...
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 100 total points
Comment Utility
Try this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Start : DWord;
  FirstClick, SecClick : Boolean;

implementation

function timeGetTime : DWord; external 'WINMM.DLL';

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  FirstClick := True;
  SecClick := False;
  Label1.Caption := '0';
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if FirstClick = True then
  begin
    Label1.Caption := '0';
    FirstClick := False;
    Start := timeGetTime;
  end
  else
    SecClick := True;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if timeGetTime - Start > GetDoubleClickTime then
  begin
    Label1.Caption := 'To Slow';
    FirstClick := True;
    SecClick := False;
  end
  else
  begin
    if SecClick = True then
    begin
      Label1.Caption := IntToStr(timeGetTime - Start);
      FirstClick := True;
      SecClick := False;
    end;
  end;
end;

end.

Its got a percision of 1 ms because it uses the multimedia timer api timeGetTime in WinMM.dll

Cheers,

Alan
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
Correction: it returns 0 on a 450 MHz CPU...
0
 

Author Comment

by:igor84
Comment Utility
i found an answer by my self
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
then you should post it.  It's considered rather rude to solicit help, then delete the q after it's been given.  

GL
Mike
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
> i found an answer by my self

Who says that you didn't use my code....
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
listening . . .
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:Stuart_Johnson
Comment Utility
Epsylon: Lock the question to prevent it being deleted.
0
 

Expert Comment

by:bullen
Comment Utility
Use the PerformanceCounter insted of Ticks.

QueryPerformanceCounter and
QueryPerformanceFrequnecy and

Bullen
0
 

Author Comment

by:igor84
Comment Utility
i found an answer by myself but because some one posted a right answer he deserves the points, and the right answer is from : alanwhincup.

0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
And what about those promised 1000 points?
0
 

Author Comment

by:igor84
Comment Utility
because this solution is not the best and don't realy works on 1 millisec accuracy.

if you posted me a solution like this i would give you 1000 points. i realy don't understand you all obsession to points you all are so greedy ?!

p.s you first solution was at accuracy of 5 millisec so ...

Igor
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
Why did you delete the question without explanation? Doesn't that mean that you are greedy for answers?
And why didn't you wait for a better solution instead of deleting it?

Look, this point system increases the response time greatly. There is a certain level of competition between experts, and... they are points, not dollars. I and others spent time trying to help you. I don't even see a 'thank you' or something like that.

Promising 1000 points and then deleting the question without explanation, after you received 2 solutions, is really frustrating. It is NOT DONE!

Eps. (really pissed!)
0
 

Author Comment

by:igor84
Comment Utility
i deleted by mistake and like you see after that i accepted alanwhincup answer ! and gave him 100 pts (the question value) but if there were good enghot solution like i asked i would give 1000 pts.

i realy thanks you and all other people that are spending theirs time to help others and i realy thank you for that !

p.s don't be angry.

i asked a day before another question that is very thoght and i promiss you the accepted answer will get 1000 points.

p.s from where are you ?
0
 
LVL 5

Expert Comment

by:alanwhincup
Comment Utility
My solution should give the time to an accuracy of 1ms. It uses a multimedia timer which is implemented using the Win32 multimedia library (winmm.dll). Ive used this instead of any other time because most other timers are limited by the systems resolution.
0
 

Author Comment

by:igor84
Comment Utility
i agree with you in the help file written that give an accurancy of 1 ms but it isn't like that. i checked it and that disappointmented me. sorry ...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now