procedure TForm1.Timer1Timer(Sender: TObject);
var
topWindow: THandle;
wRect: TRect;
begin
topWindow := GetForegroundWindow;
GetWindowRect(topWindow, wRect);
if (wRect.Bottom = Screen.Height) and (wRect.Right = Screen.Width) then begin
Memo1.Lines.Add('有全屏程序运行');
//做你爱做的事……
end else begin
Memo1.Lines.Add('无全屏程序运行');
//做你爱做的事……
end;
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,
ShellAPI; // 要引用此单元
const
WM_APPBAR_MESSAGE = WM_USER + 1;
type
TForm1 = class(TForm)
Timer1: TTimer;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
IsFullScreenAppRun: Boolean; //放个全局变量用于记录
procedure WMAppBarMessage(var Msg: TMessage); message WM_APPBAR_MESSAGE;
end;
var
Form1: TForm1;
AppBar_Data: APPBARDATA;
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SHAppBarMessage(ABM_REMOVE, AppBar_Data); //窗口关闭时移除此消息
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FillChar(AppBar_Data, SizeOf(AppBar_Data), #0);
AppBar_Data.cbSize := SizeOf(AppBar_Data);
AppBar_Data.hWnd := Handle;
AppBar_Data.uCallbackMessage := WM_APPBAR_MESSAGE; //指定回调消息
SHAppBarMessage(ABM_NEW, AppBar_Data); //建立监听
end;
procedure TForm1.WMAppBarMessage(var Msg: TMessage);
var
retCode: Cardinal ;
begin
if Msg.Msg = WM_APPBAR_MESSAGE then begin
if msg.WParam = ABN_FULLSCREENAPP then begin
if msg.LParam = 1 then begin
Memo1.Lines.Add('有全屏程序运行');
IsFullScreenAppRun := True;
end else if Msg.LParam = 0 then begin
Memo1.Lines.Add('无全屏程序运行');
IsFullScreenAppRun := False;
end;
end;
end;
end;
end.