| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3299 人关注过本帖
标题:ShowWindow(hwnd,SW_HIDE) 隐藏窗口,应用程序窗口仍然显示在任务栏,为什么 ...
只看楼主 加入收藏
ktr
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-11-1
结帖率:0
收藏
 问题点数:0 回复次数:1 
ShowWindow(hwnd,SW_HIDE) 隐藏窗口,应用程序窗口仍然显示在任务栏,为什么?
程序代码:
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(buf + ':   ' +inttostr(hwnd));
      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.
请看消息处理过程中最小化窗口时,隐藏窗口的代码.
使用ShowWindow(hwnd,SW_HIDE)  隐藏应用程序自身窗口,在任务栏中仍然存在.为何??
使用Form1.visible:=FALSE  就不会显示.
希望高手解答一下.万分感谢!

[ 本帖最后由 ktr 于 2012-11-5 15:53 编辑 ]
搜索更多相关主题的帖子: Windows 应用程序 任务栏 
2012-11-05 15:49
mrbonn
Rank: 2
等 级:论坛游民
帖 子:4
专家分:10
注 册:2012-10-19
收藏
得分:0 
回复 楼主 ktr
ShowWindow(Application.Handle,HIDE_WINDOW );
2013-01-14 18:08
快速回复:ShowWindow(hwnd,SW_HIDE) 隐藏窗口,应用程序窗口仍然显示在任务栏,为 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018842 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved