想实现鼠标在指定窗体外的屏幕的任何位置点击后就关闭指定窗体的效果,不知道如何实现?

解决方案 »

  1.   

    Mouse Hook用WindowFromPoint(MOUSEHOOKSTRUCT.pt)与窗体句柄对比,不一样就PostMessage(Form1.Hanldw, WM_CLOSE, 0, 0);
      

  2.   

    拦截窗体的消息,如果 (Message.Msg = WM_NCACTIVATE) and (Message.WParam = 0)就Close。可惜这帖子发在非技术区了,郁闷。
      

  3.   

    ccrun(老妖)(www.ccrun.com) 抢分心切啊人家问的是鼠标点击窗体外任何位置才close嘛您那个好像随便按个ALT+TAB也能close吧?呵呵。1楼的方法可行。
      

  4.   

    阿日。。出来。。转帖子了。。推荐LZ使用Mouse Hook。
      

  5.   

    interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        procedure UP_Locus(var Message:TMessage); message WM_ACTIVATEAPP;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;{$R *.dfm}
    procedure TForm1.UP_Locus(var Message:TMessage);
    begin
      if (message.WParam=0) and  (message.Msg=WM_ACTIVATEAPP)  then
      begin
        self.Caption:='lost';
      end
      else
      begin
        self.Caption:='get';
      end;
    end;
    //刚学会的
    end.
      

  6.   

    if ActiveForm.name <> sbform then sbform.close;
      

  7.   

    同意 fim(阿初) 的观点。记得有个api可以获得窗体的句柄。