两个问题:一、如何计算两时间差?二、怎样把应用程序的图标缩到任务栏(最右角,和系统时间放在一块)?(200分)

M

mj_hc

Unregistered / Unconfirmed
GUEST, unregistred user!
一、计算时间差应该用什么函数(精确到ms,或s)?
二、在运行应用程序时,怎样使应用程序最小话后图表缩到最右下脚处?
 
1、date 和time类型支持减法时间差你只要把两个时间类型相减就能得到。
2、第二个问题论坛中已经有了很多的回答,你用trayicon检索一下就有了。
 
两时间相减我试过,时间比较接近还可以,但当时间相差比较大时经常会出现非法操作。
 
差不多 !
 
1.GetTickCount试试
2.http://www.delphibbs.com/delphibbs/dispQ.asp?lid=465783
 
'时间相差比较大'
多大?我试试。
 
GetTickCount返回从你windows启动到当前的微秒数
t1,t2:DWord;
t1:=GetTickCount
//do your work
t2:=GetTickCount
//so the time you do the work above is t2-t1
 
我也想知道!
 
日期在delphi中其实是一个real型的数据,小数点前的数相减的值是天数差,小数点后数
应该是把分秒小时转化成天的数
 
同意godzhou的解释1
 
看下面代码:
PROCEDURE TForm1.btnTimeClick(Sender:TObject);
VAR
LStart,LEnd:Integer;
BEGIN
LStart:=GetTickCount
//GetTickCount为取得当前时间函数
....
dosomething;
....
LEnd:=GetTickCount;
edtTime.Text:=FloatToStr((LEnd-LStart)/1000.0)+秒;
//edtTime 是Tedit控件,用来显示间隔时间,除以1000是转化为s,不除就是ms
END;
 
问题1:上面的回答应该可以满足,GetTickCount是个有趣而且好用的函数。如果你的机器
是server,可以用它来检测系统长期运行的时间。
问题2:如果只是最小化图标回到托盘区,已经有很多解答,这里提供一段代码实现图标在
托盘区时程序最大化及最小化时的动态过程(即不是瞬间最大最小化,有普通窗口的动画过
程)

unit TestForm


interface

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


type

TZoomAction = (zaMinimize, zaMaximize)


TfrmTest = class(TForm)
procedure FormClose(Sender: TObject
var Action: TCloseAction)

procedure FormShow(Sender: TObject)

private
{ Private declarations }
public
{ Public declarations }
end


var
frmTest: TfrmTest


implementation

{$R *.DFM}

procedure ZoomEffect(theForm: TForm
theOperation: TZoomAction)

var
rcStart: TRect

rcEnd: TRect

rcTray: TRect

hwndTray : hWnd

hwndChild: hWnd

begin
{ Find the system tray area bounding rectangle }
hwndTray := FindWindow('Shell_TrayWnd', nil)

hwndChild := FindWindowEx(hwndTray, 0, 'TrayNotifyWnd', nil)

GetWindowRect(hwndChild, rcTray)


{ Check for minimize/maximize and swap start/end}
if theOperation = zaMinimize then
begin
rcStart := theForm.BoundsRect

rcEnd := rcTray

end
else
begin
rcEnd := theForm.BoundsRect

rcStart := rcTray

end


{ Here the magic happens... }
DrawAnimatedRects(theForm.Handle, IDANI_CAPTION, rcStart, rcEnd)
end


procedure TfrmTest.FormClose(Sender: TObject
var Action: TCloseAction)

begin
ZoomEffect(Self, zaMinimize)

end


procedure TfrmTest.FormShow(Sender: TObject)

begin
ZoomEffect(Self, zaMaximize)

end


end.
 
谢谢你们!这是我在大富翁的第一贴,你们的回答很详细,很满意!
第一个问题已解决,第二个问题还在调试中,好像还有些问题.
我会记着给你们分的!再次表示谢谢!
 
GetTickCount 我记得它受外界的影响是比较大的,精确计时不可以用它,比方说精确到

ms,最好用mmsystem单元里的计时函数。
 
1)
QueryperformanceCounter (得到系统启动以来CPU 的脉冲个数)
Queryperformancefrequency (得到系统得到的CPU脉冲频率)

得到时间就不用说了吧! 精确到纳秒级
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部