2008年7月9日星期三

发一个专门操作任务栏的类

忽然在CSDN上看到别人问怎样操作windows任务栏上的元素,如隐藏任务栏、获得任务栏上的所有托盘图标等信息。在闲暇的时候用Spy++捕捉了一下任务栏的相关消息和各控件句柄。于是将各种操作封装到了一个类中。大致代码如下:
(******************************************************)
(* WindowsOperate Unit *)
(* Copyright(c) 2007 不得闲 *)
(* email:appleak46@yahoo.com.cn QQ:75492895 *)
(******************************************************)
unit WindowsOperate;

interface
uses windows,Classes,Messages,SysUtils,forms,ComObj,winsvc, shellapi,CommCtrl,Graphics;
type
{任务栏上的任务按扭}
TSysToolbarBtn = class(TPersistent)
private
FBtnInfo: TTBButton;
FBtnIndex: integer;
FBtnCaption: string;
SysHide: boolean;//是否为系统隐藏图标
EventHandle: THandle; //事件处理句柄
FPicture: TBitmap; //图标
FBtnRect: TRect; //区域
FVisible: boolean;
function GetBtnInfo: TTBButton;
procedure SetVisible(const Value: boolean);
public
Constructor Create;
Destructor Destroy;override;
property BtnInfo: TTBButton read GetBtnInfo;
property BtnIndex: integer read FBtnIndex;
property BtnCaption: string read FBtnCaption;
property BtnRect: TRect read FBtnRect;
procedure AssignBtnInfo(Info: TTBButton);
property isSysHide: boolean read SysHide;
property Picture: TBitmap read FPicture;
property Visible: boolean read FVisible write SetVisible;
procedure Click;
procedure DbClick;
procedure RClick;
end;

TSysTaskBarOperate = Class(TComponent) //任务栏操作类
private
FTrayBtnList,FTaskBtnList: TStringList;
HigherThenXp: boolean; //是否为xp以上的系统版本
FTrayBarHandle: THandle;
FTaskBarHandle: THandle;
FStartBtnHandle: THandle;
FQuitLauchHandle: THandle;
FReBarHandle: THandle;
FProgramToolBarHandle: THandle;
FImeRecHandle: THandle;
FProgramContrainerHandle: THandle; //任务栏容器
FHideTrayBtnHandle: THandle;
FTrayNotifyHandle: THandle;
FClockHandle: THandle;
FShowHideBtn: boolean;
FVisible: boolean;
FquickBarVisible: boolean;
FTaskToolBarVisible: boolean;
FTaskBarVisible: boolean;
FRegBarVisible: boolean;
FStartBtnVisible: boolean;
FImeBarVisible: boolean;
FTrayBarVisible: boolean;
procedure GetIconList;
procedure GetTaskList;
function GetTrayBtnCount: integer;
function IsSysBtnHide(BtnState: Dword): boolean;
procedure SetShowHideBtn(const Value: boolean);
function GetTrayBtns(Index: integer): TSysToolbarBtn;
function GetTaskBtnCount: integer;
function GetTaskBtns(Index: integer): TSysToolbarBtn;
procedure SetVisible(const Value: boolean);
procedure SetquickBarVisible(const Value: boolean);
procedure SetTaskToolBarVisible(const Value: boolean);
procedure SetTaskBarVisible(const Value: boolean);
procedure SetReBaVisible(const Value: boolean);
procedure SetStartBtnVisible(const Value: boolean);
procedure SetImeBarVisible(const Value: boolean);
procedure SetTrayBarVisible(const Value: boolean);
protected
procedure StartBtnWndProc(var Message: TMessage);
public
Constructor Create(AOwner: TComponent);override;
Destructor Destroy;override;
property TrayBarHandle: THandle read FTrayBarHandle;//托盘区句柄
property TaskBarHandle: THandle read FTaskBarHandle;//任务栏句柄
property StartBtnHandle: THandle read FStartBtnHandle;//开始按扭句柄
property QuitLauchHandle: THandle read FQuitLauchHandle;//快速启动栏句柄
property ImeRecHandle: THandle read FImeRecHandle;//输入法选择区域句柄
property ProgramToolBarHandle: THandle read FProgramToolBarHandle;//程序最小化按扭容器
property HideTrayBtnHandle: THandle read FHideTrayBtnHandle;//显示隐藏图标的按扭
property ClockHandle: THandle read FClockHandle;//时钟显示区域句柄
procedure SetTimeDlg; //设置时间对话框
procedure HideTrayBtnClick; //显示隐藏按扭单击
procedure ImeRectBtnClick;//输入法按扭单击
procedure ClearTrayBtnList; //清除托盘区列表
procedure ClearTaskBtnList;
procedure ShowTime;
procedure StartBtnClick;
procedure HideOn;
procedure ShowOn;
property TrayBarVisible: boolean read FTrayBarVisible write SetTrayBarVisible;
property ImeBarVisible: boolean read FImeBarVisible write SetImeBarVisible;
property StartBtnVisible: boolean read FStartBtnVisible write SetStartBtnVisible;
property ReBarVisible: boolean read FRegBarVisible write SetReBaVisible;
property TaskToolBarVisible: boolean read FTaskToolBarVisible write SetTaskToolBarVisible;
property TaskBarVisible: boolean read FTaskBarVisible write SetTaskBarVisible;
property quickBarVisible: boolean read FquickBarVisible write SetquickBarVisible;
property Visible: boolean read FVisible write SetVisible; //是否隐藏任务栏
property ShowHideBtn: boolean read FShowHideBtn Write SetShowHideBtn;//是否显示系统隐藏的托盘按扭
property TrayBtnCount: integer read GetTrayBtnCount;//托盘图标的个数
property TaskBtnCount: integer Read GetTaskBtnCount;
property TrayBtnList: TStringList read FTrayBtnList;
property TaskBtnList: TStringList Read FTaskBtnList;
property TrayBtns[Index: integer]: TSysToolbarBtn read GetTrayBtns; //托盘按扭
Property TaskBtns[Index: integer]: TSysToolbarBtn read GetTaskBtns; //任务栏按扭
end;

implementation
{ TSysTaskbarOperate }

procedure TSysTaskBarOperate.ClearTaskBtnList;
begin
while FTaskBtnList.Count > 0 do
begin
FTaskBtnList.Objects[FTaskBtnList.Count - 1].Free;
FTaskBtnList.Delete(FTaskBtnList.Count - 1);
end;
end;

procedure TSysTaskBarOperate.ClearTrayBtnList;
begin
while FTrayBtnList.Count > 0 do
begin
FTrayBtnList.Objects[FTrayBtnList.Count - 1].Free;
FTrayBtnList.Delete(FTrayBtnList.Count - 1);
end;
end;

constructor TSysTaskbarOperate.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FTrayBtnList := TStringList.Create;
FTaskBtnList := TStringList.Create;
HigherThenXp := (Win32MajorVersion > 5) or ((Win32MajorVersion = 5) and (Win32MinorVersion > 0));
FTaskBarHandle := FindWindow('Shell_TrayWnd',nil);
FStartBtnHandle := FindWindowEx(FTaskBarHandle,0,'Button',nil);
//if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 10) then //98系统
FReBarHandle := FindWindowEx(FTaskBarHandle,0,'ReBarWindow32',nil);
FQuitLauchHandle := FReBarHandle;
FProgramContrainerHandle := FindWindowEx(FQuitLauchHandle,0,'MSTaskSwWClass',nil);
FImeRecHandle := FindWindowEx(FQuitLauchHandle,0,'CiceroUIWndFrame',nil);

if HigherThenXp then
FProgramToolBarHandle := FindWindowEx(FProgramContrainerHandle,0,'ToolbarWindow32',nil)
else FProgramToolBarHandle := FProgramContrainerHandle;
FTrayBarHandle := FindWindowEx(FTaskBarHandle,0,'TrayNotifyWnd',nil);
FTrayNotifyHandle := FTrayBarHandle;
FClockHandle := FindWindowEx(FTrayBarHandle,0,'TrayClockWClass',nil);
FHideTrayBtnHandle := FindWindowEx(FTrayBarHandle,0,'Button',nil);
if HigherThenXp then
FTrayBarHandle := FindWindowEx(FTrayBarHandle,0,'SysPager',nil);
if (Win32MajorVersion = 5) and (Win32MinorVersion >= 0) then
FTrayBarHandle := FindWindowEx(FTrayBarHandle,0,'ToolbarWindow32',nil);

FQuitLauchHandle := FindWindowEx(FQuitLauchHandle,0,'ToolbarWindow32',nil);//快速启动栏
//SetWindowLong(FStartBtnHandle, GWL_WNDPROC, Longint(MakeObjectInstance(StartBtnWndProc)));
GetIconList;
GetTaskList;
Visible := true;
ReBarVisible := true;
TaskBarVisible := true;
quickBarVisible := true;
TaskToolBarVisible := true;
StartBtnVisible := true;
TrayBarVisible := true;
ImeBarVisible := true;
end;

destructor TSysTaskbarOperate.Destroy;
begin
ClearTrayBtnList;
FTrayBtnList.Free;
ClearTaskBtnList;
FTaskBtnList.Free;
inherited;
end;

procedure TSysTaskBarOperate.GetIconList;
var
ThreadID: THandle;
ThreadHandle: THandle; //线程句柄
Buff: pchar;
i,BtnCount: integer;
R: Cardinal;
BtnInfo: TTBButton;
SysHide: boolean;
SysToolBtn: TSysToolbarBtn;
S: array[0..512] of char;
BtnRect: TRect;
begin
GetWindowThreadProcessId(FTrayBarHandle, @ThreadID);//获取托盘窗口的线程 ID
ThreadHandle := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, ThreadID);//得到线程句柄
Buff := VirtualAllocEx(ThreadHandle,nil,4096,MEM_RESERVE or MEM_COMMIT,PAGE_READWRITE);//指定进程的虚拟空间保留或提交内存区域,除非指定MEM_RESET参数,否则将该内存区域置0
BtnCount := SendMessage(FTrayBarHandle,TB_BUTTONCOUNT, 0, 0);//得到托盘按扭个数
//SendMessage(FTrayBarHandle,TB_GETIMAGELIST,0,0);
//SendMessage(FTrayBarHandle,TB_GETBITMAPFLAGS,0,0);
try
for i := 0 to BtnCount - 1 do
begin
WriteProcessMemory(ThreadHandle, Buff, @BtnInfo, SizeOf(BtnInfo), R);
SendMessage(FTrayBarHandle, TB_GETBUTTON, i,integer(Buff));
ReadProcessMemory(ThreadHandle, Buff, @BtnInfo, SizeOf(BtnInfo), R);
SysHide := IsSysBtnHide(BtnInfo.fsState);
if SysHide and (not FShowHideBtn) then
Continue;

SysToolBtn := TSysToolbarBtn.Create;
SysToolBtn.SysHide := SysHide;
SysToolBtn.FVisible := not SysHide;
SysToolBtn.AssignBtnInfo(BtnInfo);

//SysToolBtn.FPicture.Canvas
SysToolBtn.FBtnIndex := BtnInfo.idCommand;
SendMessage(FTrayBarHandle,TB_GETBUTTONTEXT,SysToolBtn.FBtnInfo.idCommand,integer(integer(@Buff[0]) + SizeOf(@SysToolBtn.FBtnInfo)));
ReadProcessMemory(ThreadHandle, Pointer(integer(@Buff[0]) + SizeOf(@SysToolBtn.FBtnInfo)),@S[0],SizeOf(S), R);
//if SysToolBtn.FBtnInfo.fsState = 12 then
SysToolBtn.FBtnCaption := String(s);
SysToolBtn.EventHandle := FTrayBarHandle;
if not SysHide then
begin
SendMessage(FTrayBarHandle,TB_GETRECT,BtnInfo.idCommand,integer(integer(@Buff[0]) + SizeOf(BtnInfo)));
ReadProcessMemory(ThreadHandle,Pointer(integer(@Buff[0]) + SizeOf(BtnInfo)), @BtnRect,SizeOf(BtnRect),R);//得到Rect信息
SysToolBtn.FBtnRect := BtnRect;

SysToolBtn.FPicture.Width := BtnRect.Right - BtnRect.Left;
SysToolBtn.FPicture.Height := BtnRect.Bottom - BtnRect.Top;

BitBlt(SysToolBtn.FPicture.Canvas.Handle,0,0,SysToolBtn.FPicture.Width,SysToolBtn.FPicture.Height,
GetDc(FTrayBarHandle),BtnRect.Left,BtnRect.Top,SRCCOPY); //抓图
end;
FTrayBtnList.AddObject(SysToolBtn.FBtnCaption,SysToolBtn);
{if BtnInfo.fsState <> TBSTATE_HIDDEN then //如果是隐藏的,则不显示出来
begin
//FTrayBtnList.Add(s)
end;}
end;
finally
VirtualFreeEx(ThreadHandle, Buff, 0, MEM_RELEASE);
CloseHandle(ThreadHandle);
end;
end;

function TSysTaskBarOperate.GetTaskBtnCount: integer;
begin
result := FTaskBtnList.Count;
end;

function TSysTaskBarOperate.GetTaskBtns(Index: integer): TSysToolbarBtn;
begin
if (Index > -1 ) and (Index < FTaskBtnList.Count) then
result := TSysToolbarBtn(FTaskBtnList.Objects[Index])
else result := nil;
end;

procedure TSysTaskBarOperate.GetTaskList;
var
i,BtnCount: integer;
ThreadId: LongInt;
ThreadHandle: THandle;
vBuffer: array[0..255] of Char;
SysToolBtn: TSysToolbarBtn;
BtnInfo: TTBButton;
Buff: pointer;
BtnRect: TRect;
WriteNum: Cardinal;
SysHide: boolean;
begin
BtnCount := SendMessage(FProgramToolBarHandle, TB_BUTTONCOUNT,0,0);
GetWindowThreadProcessId(FProgramToolBarHandle,@ThreadId);
ThreadHandle := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, ThreadId);
Buff := VirtualAllocEx(ThreadHandle, nil,4096, MEM_RESERVE or MEM_COMMIT,PAGE_READWRITE);
try
for i := 0 to BtnCount - 1 do
begin
WriteProcessMemory(ThreadHandle,Buff,@BtnInfo,Sizeof(BtnInfo),WriteNum);
SendMessage(FProgramToolBarHandle,TB_GETBUTTON, i,integer(Buff));
ReadProcessMemory(ThreadHandle, Buff, @BtnInfo, SizeOf(BtnInfo), WriteNum);

SendMessage(FProgramToolBarHandle,TB_GETRECT,BtnInfo.idCommand,integer(integer(Buff) + SizeOf(BtnInfo)));
ReadProcessMemory(ThreadHandle,Pointer(integer(Buff) + SizeOf(BtnInfo)), @BtnRect,SizeOf(BtnRect),WriteNum);//得到Rect信息
SysHide := (BtnRect.Right - BtnRect.Left = 0) and (BtnRect.Bottom - BtnRect.Top = 0);
SysHide := IsSysBtnHide(BtnInfo.fsState) or SysHide;
if SysHide and (not FShowHideBtn) then
Continue;

SysToolBtn := TSysToolbarBtn.Create;
SysToolBtn.SysHide := SysHide;
SysToolBtn.FVisible := not SysHide;
SysToolBtn.AssignBtnInfo(BtnInfo);

//SysToolBtn.FPicture.Canvas
SysToolBtn.FBtnIndex := BtnInfo.idCommand;
SendMessage(FProgramToolBarHandle,TB_GETBUTTONTEXT,SysToolBtn.FBtnInfo.idCommand,integer(integer(Buff) + SizeOf(@SysToolBtn.FBtnInfo)));
ReadProcessMemory(ThreadHandle, Pointer(integer(Buff) + SizeOf(@SysToolBtn.FBtnInfo)),@VBuffer,SizeOf(VBuffer), WriteNum);
SysToolBtn.FBtnCaption := String(VBuffer);

SysToolBtn.EventHandle := FProgramToolBarHandle;
SysToolBtn.FBtnRect := BtnRect;
FTaskBtnList.AddObject(SysToolBtn.FBtnCaption,SysToolBtn);
end;
finally
VirtualFreeEx(ThreadHandle, Buff,0, MEM_RELEASE);
CloseHandle(ThreadHandle);
end;
end;

function TSysTaskBarOperate.GetTrayBtnCount: integer;
begin
result := FTrayBtnList.Count;
end;

function TSysTaskBarOperate.GetTrayBtns(Index: integer): TSysToolbarBtn;
begin
if (Index > -1 ) and (Index < FTrayBtnList.Count) then
result := TSysToolbarBtn(FTrayBtnList.Objects[Index])
else result := nil;
end;




procedure TSysTaskBarOperate.HideTrayBtnClick;
begin
PostMessage(FHideTrayBtnHandle,WM_LButtonDown,0,0);
PostMessage(FHideTrayBtnHandle,WM_LButtonUp,0,0);
end;

procedure TSysTaskBarOperate.ImeRectBtnClick;
begin
PostMessage(FImeRecHandle,WM_LButtonDown,0,MakeLParam(4,5));
PostMessage(FImeRecHandle,WM_LButtonUp,0,MakeLParam(4,5));
end;

function TSysTaskBarOperate.IsSysBtnHide(BtnState: Dword): boolean;
begin
result := GetBitNum(4,BtnState) = 1;
end;

procedure TSysTaskBarOperate.SetReBaVisible(const Value: boolean);
begin
if (FRegBarVisible <> Value) and Visible then
begin
FRegBarVisible := Value;
if Value then
ShowWindow(FReBarHandle,SW_Normal)
else
ShowWindow(FReBarHandle,SW_Hide);
end;
end;

procedure TSysTaskBarOperate.SetquickBarVisible(const Value: boolean);
begin
if (FquickBarVisible <> Value) and TaskBarVisible then
begin
FquickBarVisible := Value;
if Value then
ShowWindow(FQuitLauchHandle,SW_Normal)
else
ShowWindow(FQuitLauchHandle,SW_Hide);
end;
end;

procedure TSysTaskBarOperate.SetShowHideBtn(const Value: boolean);
begin
if FShowHideBtn <> Value then
begin
FShowHideBtn := Value;
ClearTrayBtnList;
GetIconList;
ClearTaskBtnList;
GetTaskList;
end;
end;

procedure TSysTaskBarOperate.SetTaskBarVisible(const Value: boolean);
begin
if (FTaskBarVisible <> Value) and FRegBarVisible then
begin
FTaskBarVisible := Value;
if Value then
ShowWindow(FProgramContrainerHandle,SW_Normal)
else
ShowWindow(FProgramContrainerHandle,SW_Hide);
end;
end;

procedure TSysTaskBarOperate.SetTaskToolBarVisible(const Value: boolean);
begin
if (FTaskToolBarVisible <> Value) and (FTaskBarVisible) then
begin
FTaskToolBarVisible := Value;
if Value then
ShowWindow(FProgramToolBarHandle,SW_Normal)
else
ShowWindow(FProgramToolBarHandle,SW_Hide);
end;
end;

procedure TSysTaskBarOperate.SetTimeDlg;
begin
winexec('rundll32.exe shell32.dll,Control_RunDLL timedate.cpl',9);
// SendMessage(FClockHandle, WM_LBUTTONDBLCLK,0,MakeLong(2,2));
// SendMessage(FClockHandle,WM_LBUTTONUP,0,MakeLong(2,2));
end;

procedure TSysTaskBarOperate.SetVisible(const Value: boolean);
begin
if FVisible <> Value then
begin
FVisible := Value;
if FVisible then
ShowWindow(FTaskBarHandle,SW_NORMAL)
else
ShowWindow(FTaskBarHandle,SW_HIDE);
end;
end;

procedure TSysTaskBarOperate.ShowTime;
begin
AddTipTool({FClockHandle}FProgramToolBarHandle,1,pchar('时间显示'), PChar(DateToStr(now)),$00FFBFBF,$00A60053);//添加气泡提示
end;

procedure TSysTaskBarOperate.StartBtnClick;
begin
SendMessage(self.FStartBtnHandle,WM_LBUTTONDOWN,0,0);
SendMessage(self.FStartBtnHandle,WM_LBUTTONUP,0,0);
end;

procedure TSysTaskBarOperate.StartBtnWndProc(var Message: TMessage);
begin
if Message.Msg = WM_LButtonup then
ShowMessage('sdf');
end;

procedure TSysTaskBarOperate.SetStartBtnVisible(const Value: boolean);
begin
if (FStartBtnVisible <> Value) and Visible then
begin
FStartBtnVisible := Value;
if Value then
ShowWindow(FStartBtnHandle,SW_Normal)
else
ShowWindow(FStartBtnHandle,SW_Hide);
end;
end;

procedure TSysTaskBarOperate.SetImeBarVisible(const Value: boolean);
begin
if (FImeBarVisible <> Value) and FRegBarVisible then
begin
FImeBarVisible := Value;
if Value then
ShowWindow(FImeRecHandle,SW_Normal)
else
ShowWindow(FImeRecHandle,SW_Hide);
end;
end;

procedure TSysTaskBarOperate.SetTrayBarVisible(const Value: boolean);
begin
if (FTrayBarVisible <> Value) and FVisible then
begin
FTrayBarVisible := Value;
if Value then
ShowWindow(FTrayNotifyHandle,SW_Normal)
else
ShowWindow(FTrayNotifyHandle,SW_Hide);
end;
end;

procedure TSysTaskBarOperate.HideOn;
begin
ReBarVisible := false;
TrayBarVisible := false;
StartBtnVisible := false;
end;

procedure TSysTaskBarOperate.ShowOn;
begin
ReBarVisible := true;
TaskBarVisible := true;
quickBarVisible := true;
TaskToolBarVisible := true;
StartBtnVisible := true;
TrayBarVisible := true;
ImeBarVisible := true;
end;

{ TSysToolbarBtn }

procedure TSysToolbarBtn.AssignBtnInfo(Info: TTBButton);
begin
FBtnInfo.iBitmap := Info.iBitmap;
FBtnInfo.idCommand := Info.idCommand;
FBtnInfo.fsState := Info.fsState;
FBtnInfo.fsStyle := Info.fsStyle;
FBtnInfo.bReserved := Info.bReserved;
FBtnInfo.dwData := Info.dwData;
FBtnInfo.iString := Info.iString;
end;

procedure TSysToolbarBtn.Click;
begin
SendMessage(EventHandle,WM_LBUTTONDOWN,0,MakeLong(FBtnRect.Left + 2,FBtnRect.Top + 2));
SendMessage(EventHandle,WM_LBUTTONUP,0,MakeLong(FBtnRect.Left + 2,FBtnRect.Top + 2));
end;

constructor TSysToolbarBtn.Create;
begin
Inherited Create;
FillChar(FBtnInfo,SizeOf(FBtnInfo), 0);
FPicture := TBitMap.Create;
end;

procedure TSysToolbarBtn.DbClick;
begin
SendMessage(EventHandle, WM_LBUTTONDBLCLK,0,MakeLong(FBtnRect.Left + 2,FBtnRect.Top + 2));
SendMessage(EventHandle,WM_LBUTTONUP,0,MakeLong(FBtnRect.Left + 2,FBtnRect.Top + 2));
end;

destructor TSysToolbarBtn.Destroy;
begin
FPicture.Free;
if (not isSysHide) and (not FVisible) then
Visible := true
else if IsSysHide and FVisible then
Visible := false;
ZeroMemory(Pointer(@FBtnInfo),Sizeof(FBtnInfo));
inherited;
end;

function TSysToolbarBtn.GetBtnInfo: TTBButton;
begin
result := FBtnInfo;
end;

procedure TSysToolbarBtn.RClick;
begin
SendMessage(EventHandle,WM_RBUTTONDOWN,0,MakeLong(FBtnRect.Left + 2,FBtnRect.Top + 2));
SendMessage(EventHandle,WM_RBUTTONUP,0,MakeLong(FBtnRect.Left + 2,FBtnRect.Top + 2));
end;

procedure TSysToolbarBtn.SetVisible(const Value: boolean);
begin
if FVisible <> Value then
begin
FVisible := Value;
if FVisible then
SendMessage(EventHandle,TB_HIDEBUTTON,BtnInfo.idCommand,0)
else
SendMessage(EventHandle,TB_HIDEBUTTON,BtnInfo.idCommand,1);
end;
end;

end.

使用Demo
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, RzButton, StdCtrls, RzLstBox, ExtCtrls, RzPanel, ToolWin,
ComCtrls,WindowsOperate, RzChkLst, RzRadChk, RzLabel, RzTabs;

type
TForm1 = class(TForm)
RzPageControl1: TRzPageControl;
TabSheet1: TRzTabSheet;
RzCheckList1: TRzCheckList;
RzLabel1: TRzLabel;
RzRadioButton1: TRzRadioButton;
RzRadioButton2: TRzRadioButton;
TabSheet2: TRzTabSheet;
Image2: TImage;
RzLabel2: TRzLabel;
RzCheckList2: TRzCheckList;
RzLabel3: TRzLabel;
RzRadioButton4: TRzRadioButton;
RzRadioButton3: TRzRadioButton;
RzButton1: TRzButton;
procedure FormCreate(Sender: TObject);
procedure RzCheckList1Change(Sender: TObject; Index: Integer;
NewState: TCheckBoxState);
procedure RzRadioButton1Click(Sender: TObject);
procedure RzCheckList1Click(Sender: TObject);
procedure RzButton2Click(Sender: TObject);
procedure RzRadioButton3Click(Sender: TObject);
procedure RzCheckList2Change(Sender: TObject; Index: Integer;
NewState: TCheckBoxState);
procedure RzCheckList2DblClick(Sender: TObject);
procedure RzButton1Click(Sender: TObject);
procedure RzCheckList1DblClick(Sender: TObject);
private
{ Private declarations }
OldProc:FARPROC;
procedure StartBtnWndProc(var Message: TMessage);
procedure ReSetList(ShowHideBtn: boolean=false);
public
{ Public declarations }
nn: TSysTaskBarOperate;
end;

var
Form1: TForm1;

implementation
{$R *.dfm}

uses CommCtrl,ShellApi;

procedure TForm1.FormCreate(Sender: TObject);
begin
nn := TSysTaskBarOperate.Create(self);
RzRadioButton2.Checked := true;
RzRadioButton3.Checked := true;
end;

procedure TForm1.StartBtnWndProc(var Message: TMessage);
begin

end;

procedure TForm1.RzCheckList1Change(Sender: TObject; Index: Integer;
NewState: TCheckBoxState);
begin
if NewState = CbChecked then
TSysToolbarBtn(nn.TrayBtnList.Objects[index]).Visible := true
else
TSysToolbarBtn(nn.TrayBtnList.Objects[index]).Visible := false;
nn.HideTrayBtnClick;
end;

procedure TForm1.RzRadioButton1Click(Sender: TObject);
begin
ReSetList(not RzRadioButton2.Checked);
RzRadioButton3.Checked := RzRadioButton2.Checked;
RzRadioButton4.Checked := RzRadioButton1.Checked;
end;

procedure TForm1.ReSetList(ShowHideBtn: boolean);
var
i: integer;
begin
nn.ShowHideBtn := ShowHideBtn;
self.RzCheckList1.Items := nn.TrayBtnList;
self.RzCheckList2.Items := nn.TaskBtnList;
for i := 0 to RzCheckList1.Items.Count - 1 do
RzCheckList1.ItemChecked := not TSysToolbarBtn(nn.TrayBtnList.Objects).isSysHide;
for i := 0 to RzCheckList2.Items.Count - 1 do
RzCheckList2.ItemChecked := not nn.TaskBtns.isSysHide
end;

procedure TForm1.RzCheckList1Click(Sender: TObject);
begin
if RzCheckList1.ItemIndex <> -1 then
begin
Image2.Width := nn.TrayBtns[RzCheckList1.ItemIndex].Picture.Width;
Image2.Height := nn.TrayBtns[RzCheckList1.ItemIndex].Picture.Height;
Image2.Picture.Assign(nn.TrayBtns[RzCheckList1.ItemIndex].Picture);
end;
end;

procedure TForm1.RzCheckList1DblClick(Sender: TObject);
begin
if RzCheckList1.ItemIndex <> -1 then
nn.TrayBtns[RzCheckList1.ItemIndex].Click;
end;

procedure TForm1.RzButton2Click(Sender: TObject);
begin
nn.TrayBtns[RzCheckList1.ItemIndex].DbClick
end;

procedure TForm1.RzRadioButton3Click(Sender: TObject);
begin
RzRadioButton2.Checked := RzRadioButton3.Checked;
RzRadioButton1.Checked := RzRadioButton4.Checked;
end;

procedure TForm1.RzCheckList2Change(Sender: TObject; Index: Integer;
NewState: TCheckBoxState);
begin
if NewState = CbChecked then
nn.TaskBtns[index].Visible := true
else
nn.TaskBtns[index].Visible := false;
end;

procedure TForm1.RzCheckList2DblClick(Sender: TObject);
begin
if RzCheckList2.ItemIndex <> -1 then
nn.TaskBtns[RzCheckList2.ItemIndex].Click;
end;

procedure TForm1.RzButton1Click(Sender: TObject);
begin
nn.HideOn;
end;

end.

1 条评论:

Unknown 说...

好东西啊,希望改成组件加入CnPack组件包?