隐藏窗口小程序源码 (DELPHI 7)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, CheckLst,shellAPI;
const
  WM_NID=WM_USER+1000;
type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    CheckListBox1: TCheckListBox;
    CheckBox1: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure CheckListBox1ClickCheck(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
     procedure WMSysCommand(var Message:Tmessage); message WM_SYSCOMMAND;
     procedure WMNID(var Message:TMessage); message WM_NID;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  g_hwnd:array[1..100] of DWORD;
  x:integer;
  NotifyIcon:TNotifyIconData;  //定义一个全局变量
implementation

{$R *.dfm}
///
//    EnumWindows 回调函数
///
function g_EnumWindowsProc(hwnd:HWND;lParam:LPARAM):Boolean;stdcall;
var
  buf:array[Byte] of Char;
begin
  GetWindowText(hwnd,buf,sizeof(buf));
  if (IsWindowVisible(hwnd)) and (buf <> '') then
  begin
    if hwnd <>Form1.Handle then    //排除自己的窗口,防止把自己的窗口隐藏了
    begin
      Form1.CheckListBox1.Items.Add(inttostr(hwnd)+ ':     ' +buf );
      g_hwnd[x]:=hwnd;             //数组下标从1开始.
      x:=x+1;
    end;
  end;
  Result:=True;
end;


//
//    CheckListBox 复选框被选中时隐藏窗口
//

procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
begin
  if CheckListBox1.ItemIndex = -1  then exit;
  if CheckListBox1.checked[checklistbox1.itemindex]=true then
  begin
    ShowWindow(g_hwnd[checklistbox1.ItemIndex+1],SW_HIDE);
  end
  else if checklistbox1.checked[checklistbox1.ItemIndex]=false then
  begin
    showwindow(g_hwnd[checklistbox1.ItemIndex+1],SW_RESTORE);
  end;
end;

///
//    创建应用程序窗口事件
///
procedure TForm1.FormCreate(Sender: TObject);
begin
  //遍历窗口,加入CheckListBox 中
  x:=1;
  EnumWindows(@g_EnumWindowsProc,0);
  checkbox1.Checked:=True;
  //-------------------------------------------------------加入系统托盘图标
  with NotifyIcon do begin
       cbSize:=Sizeof(TNotifyIconData);
       Wnd:=Form1.Handle;
       uID:=1;
       uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
       uCallbackMessage:=WM_NID;
       hIcon:=application.Icon.Handle;
       szTip:='HideWindow V0.1';
  end;
  Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
  //---------------------------------------------------
end;


//
//    复选框 OnTop 点击事件
/
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if Checkbox1.Checked =True then
  begin
    //窗口总在最前
    SetWindowPos(form1.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
  end
  else if Checkbox1.Checked=False then
  begin
    SetWindowPos(form1.Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
  end;
end;


///
//  消息处理过程
procedure TForm1.WMSysCommand(var Message:TMessage);
begin
    //处理最小化消息,隐藏窗口
    if Message.WParam =SC_MINIMIZE then
    begin
      Form1.Visible:=FALSE;
      //ShowWindow(Form1.Handle,SW_HIDE);   //隐藏窗口
    end
    else
    begin
      DefWindowProc(Form1.Handle,Message.Msg,Message.WParam ,Message.LParam );
    end;
end;

//----------------------------------------------------------------------------
//    处理系统托盘消息
procedure Tform1.WMNID(var message:TMessage);
begin
    case Message.LParam of
            WM_LBUTTONUP: Form1.visible:=True;
    end;
end;


procedure TForm1.FormDestroy(Sender: TObject);
begin
    Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
end;

end.

 

程序在下面图片中,点击图片,选择另存为,用压缩包软件打开刚才保存的图片,解压就看到小程序了.


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值