可以用截获窗口消息来得知道窗口失去焦点了。
procedure WndProc(var Msg: TMessage);override;
procedure TForm1.WndProc(var Msg: TMessage);
begin
 if (Msg.Msg=WM_KILLFOCUS) then
 begin
     showmessage('失去焦点!'+inttostr(i));   
     inherited;
 end;end;但如何当失去焦点时,使窗口获得焦点。请大家帮忙,我经理又在叫呢,
不行呀,最近问题很多呀,看来奖金又要没有了。晕

解决方案 »

  1.   

    我将程序改了一下,
    procedure TForm1.WndProc(var Msg: TMessage);
    begin
     if (Msg.Msg=WM_KILLFOCUS) then
     begin
         showmessage('失去焦点!'+inttostr(i));   
         SysFocus(Form1.Handle);  //我加了让本窗口获取焦点
         inherited;
     end;end;会报错,整个程序都不能运行了。
    提示系统找不到某个运行库,也没有说什么运行库。
    不知道我这样做会不会对。
      

  2.   

    对不起,我搞错了,
    procedure TForm1.WndProc(var Msg: TMessage);
    begin
     if (Msg.Msg=WM_KILLFOCUS) then
     begin
         showmessage('失去焦点!'+inttostr(i));   
         inherited;
     end
     else inherited;end;这样才不会错。
      

  3.   

    procedure TForm1.WndProc(var Msg: TMessage);
    begin
      if(Msg.Msg=WM_KILLFOCUS) then Application.BringToFront;
      inherited;
    end;
      

  4.   

    楼上fim(镇江DJ)(DJ=DelphiJava) 你这样不行的。