unit1.pas

来自「精彩编程百例26~50 其中有 控制任务栏 windows底层任务控制 屏保预览」· PAS 代码 · 共 118 行

PAS
118
字号
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    btnExit: TBitBtn;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure btnExitClick(Sender: TObject);

  private
  procedure WMGetMinMaxInfo( var Message:TWMGetMinMaxInfo );
  message WM_GETMINMAXINFO;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.WMGetMinMaxInfo( var Message :TWMGetMinMaxInfo );
begin
  with Message.MinMaxInfo^ do
  begin
    ptMaxSize.X := 400; {最大化时宽度}
    ptMaxSize.Y := 400; {最大化时高度}
    ptMaxPosition.X := 199; {最大化时左上角横坐标}
    ptMaxPosition.Y := 199; {最大化时左上角纵坐标}
  end;
  Message.Result := 0; {告诉Windows你改变了 minmaxinfo}
  inherited;
end;

procedure TForm1.Button1Click(Sender: TObject); //隐藏Windows任务栏
var
  wndHandle : THandle;
  wndClass : array[0..50] of Char;
begin
  StrPCopy(@wndClass[0], 'Shell_TrayWnd');
  wndHandle := FindWindow(@wndClass[0], nil);
  ShowWindow(wndHandle, SW_HIDE);
End;

procedure TForm1.Button2Click(Sender: TObject); //显示Windows任务栏
var
  wndHandle : THandle;
  wndClass : array[0..50] of Char;
begin
  StrPCopy(@wndClass[0], 'Shell_TrayWnd');
  wndHandle := FindWindow(@wndClass[0], nil);
  ShowWindow(wndHandle, SW_RESTORE);
end;

procedure TForm1.Button3Click(Sender: TObject); //隐藏鼠标
var
  temp:boolean;
begin
  temp:=false;
  ShowCursor(temp);
end;

procedure TForm1.Button4Click(Sender: TObject); //显示鼠标
var
  temp:boolean;
begin
  temp:=true;
  ShowCursor(temp);
end;

procedure TForm1.Button5Click(Sender: TObject); //最小化全部窗体
var
  h:HWnd;
begin
  h:=handle;
  while h > 0 do   //当程序在运行
  begin
  if isWindowVisible(h) then  //如果窗体可见(即没有最小化)
  postmessage(h,WM_SYSCOMMAND,SC_MINIMIZE,0);
  h:=getnextwindow(h,GW_HWNDNEXT);
  end;
end;

procedure TForm1.Button6Click(Sender: TObject); //显示桌面,隐藏桌面图标
var
  hDesktop : THandle;
begin
  hDesktop := FindWindow('Progman', nil);
  ShowWindow(hDesktop, SW_HIDE);
end;


procedure TForm1.btnExitClick(Sender: TObject);
begin
close
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?