程序关闭按按钮无效怎么回事?
delphi吧
全部回复
仅看楼主
level 3
hiso_li 楼主
一个模拟鼠标连点的小程序,功能是按alt+f8后鼠标左键单击(2秒一次)点击按钮标签会计数,程序开始后鼠标自动点击,点击最小化,和最大化按钮都没问题,关闭按钮无效怎么回事。下面是代码:
unit rejianzhuce;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
HotKeyId: Integer;
i:Integer=1;
implementation
{$R *.dfm}
procedure Delay(MSecs: Longint);
//延时函数,MSecs单位为毫秒(千分之1秒)
var
FirstTickCount, Now: Longint;
begin
FirstTickCount := GetTickCount();
repeat
Application.ProcessMessages;
Now := GetTickCount();
until (Now - FirstTickCount >= MSecs) or (Now < FirstTickCount);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HotKeyId:= GlobalAddAtom('MyHotKey') - $C000;
RegisterHotKey(Handle, hotkeyid, MOD_ALT, VK_F8);
end;
procedure TForm1.HotKeyDown(var Msg: Tmessage);
begin
if (Msg.LparamLo = MOD_ALT) AND (Msg.LParamHi = VK_F8) then // 假设热键为ALT+F8
begin
while(true)do
begin
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); //左键按下
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); //左键弹起
delay(2000);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
i:=i+1;
label1.caption:=IntToStr(i);
end;
end.
2014年05月02日 14点05分 1
level 12
你把鼠标事件放在while true do的循环里,线程假死,怎么可能响应其它事件
2014年05月02日 23点05分 2
线程好像没假死!有delay函数
2014年05月03日 00点05分
可以响应其他事件,就是没法关闭程序。
2014年05月03日 01点05分
1