使用Windows95/NT/98操作系统的用户知道:Windows正常启动后,在电脑屏幕下方出现一块 任务栏。从系统功能角度而言,整个任务栏包括几个不同的子区域,从左至右依次是:开始 按钮、应用程序切换区(Application Switch Bar)、任务栏通知区(Notification Area)以 及任务栏时钟。与其它Windows应用程序相同,任务栏程序(systray.exe)由几个不同的窗体 组成,这些窗体是具有各自的窗口类名、显示方式等信息。因此,只要得到有关窗口信息, 即可通过编程全面控制Windows任务栏的不同区域。
1. 编程思想
(1)任务栏窗体的窗口信息为:
①任务栏的窗口类名是:ShellTrayWnd。
②开始按钮的窗口类名是:Button。
③应用程序切换区的窗口类名是:ReBarWindow32。
④任务栏通知区的窗口类名是:TrayNotifyWnd。
⑤任务栏时钟的窗口类名是:TrayClockWClass。
(2)调用FindWindow函数得到任务栏的窗口句柄。
(3)调用FindWindowEx函数得到任务栏各子区域的窗口句柄。
(4)根据窗口句柄,调用ShowWindow函数控制任务栏各区域显示或隐藏 (show/hide);调用En ableWindow函数控制任务栏各区域有效或无效(enabled/disabled)。
2. 编程方法
(1)在Delphi3.0 IDE中新建工程Project1, Project1中包含Form1, 窗体如下图所示:
(2)定义窗口句柄数组:Wnd:array[0..4] of THandle;
(3)GetHandles过程代码如下:
procedure TForm1.GetHandles;
begin
  //得到Tray Bar的窗口句柄;
  Wnd[0]:=FindWindow(′ShellTrayWnd′,nil);
  //得到开始按钮的窗口句柄;
  Wnd[1]:=FindWindow(′ShellTrayWnd′,nil);
  Wnd[1]:=FindWindowEx(Wnd[1],HWND(0),′Button′,nil); //得到应用程序切换区的窗口句柄;
  Wnd[2]:=FindWindow(′ShellTrayWnd′,nil);
  Wnd[2]]:=FindWindowEx(Wnd[2],HWND(0),′ReBarWindow32′,nil);
  //得到任务栏通知区的窗口句柄;
  Wnd[3]:=FindWindow(′ShellTrayWnd′,nil);
  Wnd[3]:=FindWindowEx(Wnd[3],HWND(0),′TrayNotifyWnd′,nil);
  //得到任务栏时钟的窗口句柄;
  Wnd[4]:=FindWindow(′ShellTrayWnd′,nil);
  Wnd[4]:=FindWindowEx(Wnd[4],HWND(0),′TrayNotifyWnd′,nil);
  Wnd[4]:=FindWindowEx(Wnd[4],HWND(0),′TrayCLockWClass′,nil);
end;
(4)EnableOrDisable过程代码如下:
procedure TForm1.EnableOrDisable(Sender:TOBject);
begin
  GetHandles;
  if TCheckBox(Sender). Checked then
   case TCheckBox(Sender). Tag of
    0: EnableWindow(Wnd[0], False);
    1: EnableWindow(Wnd[1], False);
    2: EnableWindow(Wnd[2], False);
    3: EnableWindow(Wnd[3], False);
    4: EnableWindow(Wnd[4], False);
    end
  else
   case TCheckBox(Sender). Tag of
    0: EnableWindow(Wnd[0], True);
    1: EnableWindow(Wnd[1], True);
    2: EnableWindow(Wnd[2], True);
    3: EnableWindow(Wnd[3], True);
    4: EnableWindow(Wnd[4], True);
    end;
  end;
(5)HideOrShow过程代码如下:
procedure TForm1.HideOrShow(Sender:TObject);
begin
  GetHandles;
  if TCheckBox(Sender). Checked then
   case TCheckBox(Sender). Tag of
    0: ShowWindow(Wnd[0],SWHIDE);
    1: ShowWindow(Wnd[1],SWHIDE);
    2: ShowWindow(Wnd[2],SWHIDE);
    3: ShowWindow(Wnd[3],SWHIDE);
    4: ShowWindow(Wnd[4],SWHIDE);
   end
  else
   case TCheckBox(Sender). Tag of
    0: ShowWindow(Wnd[0],SWShow);
    1: ShowWindow(Wnd[1],SWShow);
    2: ShowWindow(Wnd[2],SWShow);
    3: ShowWindow(Wnd[3],SWShow);
    4: ShowWindow(Wnd[4],SWShow);
   end;
  end;
(6)FormClose事件代码如下://将Windows任务栏恢复到正常状态;
procedure TForm1.FormClose(Sender:TObject; var Action: TCloseAction);
  var i:Integer;
  begin
   for i:=0 to 4 do
   begin
    EnableWindow(Wnd[i],True);
    ShowWindow(Wnd[i],SWShow);
   end;
end;
(7)按F9运行程序。以上程序在Delphi3.0/4.0、Windows95/98简体中文版环境下调试通过。
(8)说明:本文所述方法同样适用于VB、VC、BC、C++Builder等编程工具,但应注意语法、 变量类型等不同要求。

Delphi全面控制Windows任务栏的更多相关文章

  1. Delphi 全面控制Windows任务栏

    核心提示:使用Windows95/NT/98操作系统的用户知道:Windows正常启动后,在电脑屏幕下方出现一块 任务栏. 使用Windows95/NT/98操作系统的用户知道:Windows正常启动 ...

  2. 利用Delphi全面控制Windows任务栏

    使用Windows95/NT/98操作系统的用户知道:Windows正常启动后,在电脑屏幕下方出现一块 任务栏.从系统功能角度而言,整个任务栏包括几个不同的子区域,从左至右依次是:开始 按钮.应用程序 ...

  3. 教程-隐藏/显示任务栏-程序不在任务显示-全面控制Windows

    1.隐藏任务条 var  h:THandle; //变量h:=FindWindow('Shell_TrayWnd',nil);ShowWindow(h,SW_hide); 2.显示任务条h:=Find ...

  4. delphi 获取windows任务栏的高度

    function GetWinTrayWnd: Integer; // 获取windows任务栏高度 var TrayWnd: HWnd; //任务栏句柄 Rec : TRect; begin Tra ...

  5. C#实现控制Windows系统关机、重启和注销的方法:

    shutdown命令的参数: shutdown.exe -s:关机shutdown.exe -r:关机并重启shutdown.exe -l:注销当前用户 shutdown.exe -s -t 时间:设 ...

  6. C#实现控制Windows系统关机、重启和注销的方法

    shutdown命令的参数: shutdown.exe -s:关机shutdown.exe -r:关机并重启shutdown.exe -l:注销当前用户 shutdown.exe -s -t 时间:设 ...

  7. Delphi里的Windows消息(可查MSDN指定位置)

    各种控件的通知消码和控制消息可由MSDN-> Platform SDK-> User Interface Services->Windows User Interface->C ...

  8. 浅议Delphi中的Windows API调用(举的两个例子分别是String和API,都不错,挺具有代表性)

    浅议Delphi中的Windows API调用http://tech.163.com/school • 2005-08-15 10:57:41 • 来源: 天极网为了能在Windows下快速开发应用程 ...

  9. 利用C# Winform做Windows系统任务栏

    最近公司做一个考试系统,需要一个答题栏,要求:占用屏幕上方一部分区域,而且始终置顶,当其他窗口最大化时"答题栏"始终置前并且不遮挡最大化窗口的任何部分!就像windows任务栏一样 ...

随机推荐

  1. leetcode-第14周双周赛-1271-十六进制魔术数字

    自己的提交: class Solution: def toHexspeak(self, num: str) -> str: num = hex(int(num)) num = str(num)[ ...

  2. leetcode-164周赛-1269-停在原地的方案数

    题目描述: 自己的提交: class Solution: def numWays(self, steps: int, arrLen: int) -> int: l = min(steps,arr ...

  3. python网络爬虫学习

    网络爬虫 Requests官方中文教程地址:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html Beautiful So ...

  4. CSScomb.js --- 自定义 CSS 编写风格配置文件

    一.排序分类 1. content overflow position z-index display float ... 表示定位/布局的属性(content比较特殊,作为伪元素不可少的,经常放置于 ...

  5. 【LeetCode 12】整数转罗马数字

    题目链接 [题解] (涨知识了..原来罗马数字是这么回事.. 把{1,4,5,9,10,40,50,90,100,400,500,900,1000}这些东西的罗马数字放在一个数组里面. 每次从大到小减 ...

  6. C#txt文本分割器

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. python爬虫 mac下安装使用Fiddler

    HTTP代理工具Fiddler Fiddler是一款强大Web调试工具,它能记录所有客户端和服务器的HTTP请求. Getting started 在安装之前需要准备Mono环境 If you don ...

  8. js检查判断设备

    js检查判断设备 var navigatorType = {}; var u=navigator.userAgent; navigatorType.IsIE= u.indexOf('Trident') ...

  9. 使用poi实现生成excel文件

    import java.util.ArrayList; import javax.servlet.ServletOutputStream; import org.apache.poi.hssf.use ...

  10. python re.findall 使用

    python re.findall 使用 import re #\w 匹配字母数字及下划线 print(re.findall('\w','hello alan _god !@^&#^$^!*& ...