I think this way it's easier.... but it looks like there is a bug when running on "Windows 7 x64 Sp1" in combination with the START-Button.
Normally this works very fine for me, but when I click on START and keep the menu open and then click on the Taskbar-Button from the Firefox-Browser, then Label1.Caption = FOCUS and that's wrong, because Firefox has got the Focus. When I switch to AkelPadTextEditor then Label1.Caption still shows "FOCUS".
It looks like this happens only in combination with the START-Button.
Switching between normal programs looks very good...
Unit Unit1;
{$MODE OBJFPC}{$H+}
Interface
USES
Classes, Forms, StdCtrls;
TYPE
TForm1 = Class(TForm)
Label1: TLabel;
Procedure FormCreate (Sender: TObject);
Procedure FormActivate (Sender: TObject);
Procedure FormDeactivate (Sender: TObject);
End;
VAR
Form1: TForm1;
Implementation
{$R *.LFM}
Procedure TForm1.FormCreate(Sender: TObject);
Begin
Height := 300;
Width := 500;
Position:= poDesktopCenter;
Application.OnActivate := @FormActivate;
Application.OnDeactivate:= @FormDeactivate;
End;
Procedure TForm1.FormActivate(Sender: TObject);
Begin
Label1.Caption:= 'FOCUS';
End;
Procedure TForm1.FormDeactivate(Sender: TObject);
Begin
Label1.Caption:= 'NO FOCUS';
End;
End.