首页  编辑  

显示一个不获取焦点的窗体

Tags: /超级猛料/VCL/Form,窗体/疑难杂症/   Date Created:

show a form without focusing?  

Autor: hadi forghani  

http://www.swissdelphicenter.ch/en/showcode.php?id=2394

//in TCustomForm class,in protected section add

   procedure ShowParam(var param : integer);dynamic;

   {

   this procedure call when form should be show,

   now you should override this method and write your option for

   ShowWindow API. see the example

   }

   function InShowFocus : boolean ;dynamic;

   //this function determine that after show the Form , focus on it or no.

//and it's code is

procedure TCustomForm.ShowParam(var param: Integer);

const

 ShowCommands: array[TWindowState] of Integer =

   (SW_SHOWNORMAL, SW_SHOWMINNOACTIVE, SW_SHOWMAXIMIZED);

begin

 param := ShowCommands[FWindowState];

end;

function TCustomForm.InShowFocus: Boolean;

begin

 Result := True;

end;

//-------------------------------------------------------

//now in your class you can use from themunit Unit2;

interface

uses

 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

 Dialogs, StdCtrls, Buttons, ExtCtrls;

type

 TForm2 = class(TForm)

 private

   { Private declarations }

 protected

   procedure ShowParam(var param: Integer); override;

   function InShowFocus: Boolean; override;

 public

   { Public declarations }

 end;

var

 Form2: TForm2;

implementation

{$R *.dfm}

{ TForm2 }

function TForm2.InShowFocus: Boolean;

begin

 Result := False;

end;

procedure TForm2.ShowParam(var param: Integer);

begin

 inherited;

 param := SW_SHOWNOACTIVATE;

end;

end.