001unit Unit1
002interface
003uses
004 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
005 Dialogs, StdCtrls, ImgList, ComCtrls, ExtCtrls
006type
007 TForm1 = class(TForm)
008Button1: TButton
009Edit1: TEdit
010Button2: TButton
011Button3: TButton
012Button4: TButton
013Timer1: TTimer
014Button6: TButton
015Label1: TLabel
016RadioButton1: TRadioButton
017RadioButton2: TRadioButton
018Button5: TButton
019procedure Button1Click(Sender: TObject)
020procedure Button2Click(Sender: TObject)
021procedure Button3Click(Sender: TObject)
022procedure FormMouseMove(Sender: TObjectShift: TShiftStateX,
023 Y: Integer)
024procedure Button4Click(Sender: TObject)
025procedure Timer1Timer(Sender: TObject)
026procedure Button6Click(Sender: TObject)
027procedure Button5Click(Sender: TObject)
028 private
029{ Private declarations }
030 public
031{ Public declarations }
032 end
033var
034 Form1: TForm1
035implementation
036{$R *.dfm}
037procedure TForm1.Button1Click(Sender: TObject)
038var pt: TPoint
039begin
040 //模拟左键单击
041 If RadioButton1.Checked Then
042 Begin
043pt:= Edit1.ClientToScreen( Point(4,4)) //鼠标定位
044SetCursorPos( pt.x, pt.y )
045mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 )
046mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 )
047 end
048 //模拟右键单击
049 If RadioButton2.Checked Then
050 Begin
051pt:= Edit1.ClientToScreen(Point(4,4)) //鼠标定位
052SetCursorPos( pt.x, pt.y )
053mouse_event( MOUSEEVENTF_RightDOWN, 0, 0, 0, 0 )
054mouse_event( MOUSEEVENTF_RightUP, 0, 0, 0, 0 )
055 end
056 end
057procedure TForm1.Button2Click(Sender: TObject)
058var btn3Rect: TRect
059begin
060 btn3Rect := Button3.BoundsRect
061 MapWindowPoints(handle,0, btn3Rect, 2) // 坐标换算
062 ClipCursor(@btn3Rect) // 限制鼠标移动区域
063end
064procedure TForm1.Button3Click(Sender: TObject)
065var btScreen: TRect
066begin
067 btScreen := Rect(0, 0, Screen.Width, Screen.Height)
068 ClipCursor(@btScreen) //解琐,使鼠标在整个屏幕有效
069end
070
071procedure TForm1.Timer1Timer(Sender: TObject)
072begin
073 cursor:=crNone //2秒钟没有移动鼠标就在当前窗体隐藏鼠标
074end
075
076procedure TForm1.FormMouseMove(Sender: TObjectShift: TShiftStateX,
077 Y: Integer)
078begin
079if Timer1.Enabled=True then //判断定时器是否打开
080begin//如打开,则重新开始计时
081 Timer1.Enabled:=False
082 Timer1.Enabled:=True
083 end
084 cursor:=crDefault //鼠标移动时,改变光标类型为缺省类型
085end
086
087procedure TForm1.Button6Click(Sender: TObject)
088var mouseinfo:string
089begin
090//检测是否安装了鼠标
091 If (GetSystemMetrics(SM_MOUSEPRESENT)<>0) Then
092 mouseinfo:='1.系统检测到鼠标;'
093 Else mouseinfo:='1.系统没有鼠标;'
094 //检测鼠标是否支持滑动
095 If (GetSystemMetrics(SM_MOUSEWHEELPRESENT)<>0) Then
096 mouseinfo:=mouseinfo+'2.系统支持滑动鼠标。'
097 Else mouseinfo:=mouseinfo+'2.系统不支持滑动鼠标。'
098Label1.Caption:=mouseinfo
099end
100procedure TForm1.Button4Click(Sender: TObject)
101begin
102 SwapMouseButton(True) //交换左右键
103end
104procedure TForm1.Button5Click(Sender: TObject)
105begin
106 SwapMouseButton(False)//复原左右键
107end
108end.
用时钟啊,定义一个全局变量,然后再时钟里面将变量递减。unit Unit1
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls
type
TForm1 = class(TForm)
Timer1: TTimer
Label1: TLabel
procedure Timer1Timer(Sender: TObject)
private
{ Private declarations }
public
{ Public declarations }
end
var
Form1: TForm1
Id:integer=10
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject)
begin
if Id >0 then
begin
Id := Id -1
Label1.Caption := IntToStr(Id)
end
else
begin
Timer1.Enabled := False
end
end
end.
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)