unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,commctrl,ShellAPI, CheckLst;
type
TForm1 = class(TForm)
Button1: TButton;
CheckListBox1: TCheckListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
id:array[0..30] of integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
v_hShellTray: THandle;
v_hTrayNotify: THandle;
v_hToolBar: THandle;
i,j,k:integer;
Info: _TBBUTTON;
buffer
char;
PID: THandle;
PRC: THandle;
R: Cardinal;
S:array[0..1024] of char;
MaxWidth: integer;
begin
k:=0;
CheckListBox1.Items.Clear;
v_hShellTray := FindWindow('Shell_TrayWnd', nil);
v_hTrayNotify := FindWindowEx(v_hShellTray, 0, 'TrayNotifyWnd', nil);
v_hToolBar := FindWindowEx(v_hTrayNotify, 0, 'ToolbarWindow32', nil);
GetWindowThreadProcessId(v_hToolBar, @PID);
PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID);
Buffer := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
j:=SendMessage(v_hToolBar,TB_BUTTONCOUNT,0,0);
for i:=0 to j-1 do
begin
FillChar(Info, SizeOf(Info), 0);
WriteProcessMemory(PRC, Buffer, @Info, SizeOf(Info), R);
SendMessage(v_hToolBar, TB_GETBUTTON, i, integer(Buffer));
ReadProcessMemory(PRC, Buffer, @Info, SizeOf(Info), R);
if Info.iString<>-1 then
begin
k:=k+1;
if not Boolean(SendMessage(v_hToolBar, TB_ISBUTTONHIDDEN, Info.idCommand, 0)) then
begin
SendMessage(v_hToolBar, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buffer[0]) + SizeOf(Info)));
ReadProcessMemory(PRC, Pointer(integer(@Buffer[0]) + SizeOf(Info)), @S[0], SizeOf(S), R);
id[k-1]:= Info.idCommand;
CheckListBox1.Items.Add(S);
CheckListBox1.Checked[k-1]:=false;
end
else
begin
SendMessage(v_hToolBar, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buffer[0]) + SizeOf(Info)));
ReadProcessMemory(PRC, Pointer(integer(@Buffer[0]) + SizeOf(Info)), @S[0], SizeOf(S), R);
id[k-1]:= Info.idCommand;
CheckListBox1.Items.Add(S);
CheckListBox1.Checked[k-1]:=true;
end;
end;
end;
VirtualFreeEx(PRC, Buffer, 0, MEM_RELEASE);
CloseHandle(PRC);
MaxWidth := 0;
for i := 0 to CheckListBox1.Items.Count - 1 do
if MaxWidth < CheckListBox1.Canvas.TextWidth(CheckListBox1.Items.Strings
) then
MaxWidth := CheckListBox1.Canvas.TextWidth(CheckListBox1.Items.Strings);
SendMessage(CheckListBox1.Handle, LB_SETHORIZONTALEXTENT, MaxWidth+40, 0);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
v_hShellTray: THandle;
v_hTrayNotify: THandle;
v_hToolBar: THandle;
lpDataNotifyIconData;
begin
v_hShellTray := FindWindow('Shell_TrayWnd', nil);
v_hTrayNotify := FindWindowEx(v_hShellTray, 0, 'TrayNotifyWnd', nil);
v_hToolBar := FindWindowEx(v_hTrayNotify, 0, 'ToolbarWindow32', nil);
for i:=0 to CheckListBox1.Items.Count-1 do
begin
if CheckListBox1.Checked=true then
begin
SendMessage(v_hToolBar, TB_HIDEBUTTON, id, integer(true));
end
else
begin
SendMessage(v_hToolBar, TB_HIDEBUTTON, id, integer(false));
end;
end;
//向任务栏添加一个图标后马上删除,使任务栏刷新。
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;
lpData.Wnd := Form1.Handle;
lpData.hIcon := Form1.Icon.Handle;
lpData.uCallbackMessage := 0;
lpData.uID :=0;
lpData.szTip := 'Samples';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,lpData);
Shell_NotifyIcon(NIM_DELETE,lpData);
dispose(lpData);
end;
end.
自己写的程序,可以实现隐藏任务图标。
但还是我还想获得任务栏上的图标,不知道那位大虾能帮忙解决这个问题?