怎么使一个窗口2分钟后,在键盘或鼠标没有动作的情况下自动成为当前活动窗口。

解决方案 »

  1.   

    这是函数:
    procedure TMainForm.Detect(var Msg: TMsg; var Handled: boolean);
     begin
      if (Msg.message<>WM_KEYDOWN) or (Msg.message<>WM_MOUSEMOVE) then
       begin
        application.MainForm.Show
       end
    end;调用:
    procedure TMainForm.Timer1Timer(Sender: TObject);
    begin
      Application.OnMessage:=Detect;
    end; 但不能把TMainForm变为当前窗口。
      

  2.   

    function LastInput: DWord;
    var
      LInput: TLastInputInfo;
    begin
      LInput.cbSize := SizeOf(TLastInputInfo);
      GetLastInputInfo(LInput);
      Result := GetTickCount - LInput.dwTime;
    end;
    //Example:
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      Label1.Caption := Format('System Idle since %d ms', [LastInput]);
    end;那就可以判断空闲时间有多长的http://lysoft.7u7.net
      

  3.   

    搜一下SetWindowsHook, UnhookWindowsHook网上有好多例子
      

  4.   

    1、public里加:
    procedure WndProc(var Msg: TMessage); override;2、var
      Form1: TForm1;
      TimeCount:integer;//秒3、procedure TForm1.WndProc(var Msg: TMessage);
    begin
      inherited;
     if (Msg.MSG=WM_MOUSEMOVE)   or
           (Msg.MSG=WM_LBUTTONDOWN) or
           (Msg.MSG=WM_RBUTTONDOWN) or
           (Msg.MSG=WM_KEYDOWN)     Then
           timeCount:=0;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      inc(timeCount);
      if timecount=20 then 
       begin
         //你要执行的语句;
       end;
    end;OK了……
      

  5.   

    to:ly_liuyang(Liu Yang) 
    写的很好,但达不到我的要求
    不过,还是谢谢你!
      

  6.   

    TO: kkgogo(kkgogo) 
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      inc(timeCount);
      if timecount=20 then 
       begin
         //你要执行的语句;????这句关键
       end;
    end;
      

  7.   

    if timecount=20 then 
       begin
         Application.CreateForm(TForm2, Form2);
         Form2.ShowModal;
       end;这种?
      

  8.   

    //你要执行的语句;????这句关键创建你要显示的窗口,显示出来就是了,如下:
    Form:=TForm.Create(self);
    Form.Show;
    如果窗口已经存在,显示就是了
      

  9.   

    不好意思,各位,可能是我没说清楚
     不是Show或ShowModal,而是让那个窗口激活
     比如:我的程序运行着的,同时我在打开网页,过一段时间没有键盘鼠标动作后原先程序主窗口自动成为屏幕窗口。
      

  10.   

    Application.BringToFront;
    你试试;