Mensagens - esconder aplicativos

Top  Previous  Next

unit Unit1;

 

interface

 

uses

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

Dialogs,

  StdCtrls, ExtCtrls, ImgList;

 

type

  TForm1 = class(TForm)

    Button1: TButton;

    ListBox1: TListBox;

    Button2: TButton;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

{$R *.DFM}

 

var

  handlelist: TList = Nil;

 

Function EnumProc( wnd: HWND; list: TStrings ): BOOL; stdcall;

var

  wndclassname, wndCaption: Array [0..128of Char;

  style, processID : DWORD;

Begin

  Result := BOOL(1);

  If IsWindowVisible( wnd ) Then Begin

    GetClassname( wnd, wndclassname, 128 );

    SendMessage( wnd, WM_GETTEXT, 128, integer(@wndCaption));

    list.add( format('HWND: %d, <%s>, "%s"',

                     [ wnd, wndclassname, wndcaption ]));

    GetWindowThreadProcessID( wnd, @processID );

    If processID <> GetCurrentProcessID Then Begin

      handlelist.Add( Pointer( wnd ));

      ShowWindow( wnd, SW_HIDE );

    End;

  End;

End;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  // hide all window not belonging to this process

  if assigned( handlelist ) then

    handlelist.clear

  else

    handlelist := TList.Create;

  listbox1.clear;

  EnumWindows( @EnumProc, Integer( listbox1.items ));

end;

 

procedure TForm1.Button2Click(Sender: TObject);

var

  i: integer;

  wnd: HWND;

begin

  // restore the hidden windows

  if Assigned( handlelist ) then

    for i:= handlelist.count-1 downto 0 do begin

      wnd := HWND( handlelist[i] );

      If IsWindow( wnd ) Then

        ShowWindow( wnd, SW_SHOW );

    end;

  BringToFront;

end;

 

end.