如何在程序运行时隐藏鼠标?(50分)

  • 主题发起人 主题发起人 dyfh
  • 开始时间 开始时间
D

dyfh

Unregistered / Unconfirmed
GUEST, unregistred user!
点击或移动后又出现,就象屏保一样?
 
用WINAPI

ShowCursor(False); //在程序开始时隐藏鼠标
ShowCursor(True); //在程序结束时显示鼠标
 
TForm1::onclick(Tobject *sender)
{
ShowCursor(True);
}
TForm1::onmousemove(Tobject *sender)
{
ShowCursor(True);
}
 
放个Timer控件,然后:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
procedure FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
MouseHide: Boolean;

implementation

{$R *.DFM}

procedure DoMouse;
begin
if MouseHide then
begin
Screen.Cursor:=crDefault; { 恢复鼠标 }
MouseHide:=False;
end
else Form1.Timer1.Enabled:=True;
end;

procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DoMouse;
end;

procedure TForm1.FormMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
DoMouse;
end;

procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
DoMouse;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
MouseHide:=True; { 初始化 }
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
MouseHide:=True;
Screen.Cursor:=crNone; { 隐藏鼠标 }
{ 以下这一行可以不要,但会使程序效率降低 }
Timer1.Enabled:=False;
end;

end.
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
829
SUNSTONE的Delphi笔记
S
S
回复
0
查看
780
SUNSTONE的Delphi笔记
S
D
回复
0
查看
839
DelphiTeacher的专栏
D
后退
顶部