procedure FormShow(Sender: TObject); procedure BitBtn1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure bsSkinListView1Click(Sender: TObject); private { Private declarations } function GetSysTrayIconRect(Text: string): TRect; function GetSysTrayWnd: HWND; procedure GetAllTipText; public { Public declarations } end;var tuo: Ttuo; IconId:Integer; mHandle:THandle; xxx:Boolean; mstr:TStringList; implementation {$R *.dfm} function GetToolBarButtonRect(hWnd: HWND; Title: string): TRect; { 返回指定工具栏对应的按钮指定文本的矩形区域 hWnd:工具栏句柄,Title:需要返回矩形区域的按钮文字 返回值:指定按钮的边界矩形,屏幕坐标 } var C, i: integer; Info: _TBBUTTON; Item: tagTCITEM; Buff: PChar; S: array[0..1024] of char; PID: THandle; PRC: THandle; R: Cardinal; begin IconId:=-1; FillChar(Result, SizeOf(Result), 0); if hWnd = 0 then Exit; GetWindowThreadProcessId(hWnd, @PID); PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID); Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE); if Format('%d.%d', [Win32MajorVersion, Win32MinorVersion]) >= '5.1' then {// Is Windows XP or Higher} begin C := SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0); for i := 0 to C - 1 do begin FillChar(Info, SizeOf(Info), 0); WriteProcessMemory(PRC, Buff, @Info, SizeOf(Info), R); SendMessage(hWnd, TB_GETBUTTON, i, integer(Buff)); ReadProcessMemory(PRC, Buff, @Info, SizeOf(Info), R); SendMessage(hWnd, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buff[0]) + SizeOf(Info))); ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) + SizeOf(Info)), @S[0], SizeOf(S), R); if SameText(StrPas(S), Title) then //and not Boolean(SendMessage(hWnd, TB_ISBUTTONHIDDEN, Info.idCommand, 0)) then begin xxx:=True; IconId:=(C-1)-i; SendMessage(hWnd, TB_GETRECT, Info.idCommand, integer(integer(@Buff[0]) + SizeOf(Info))); ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) + SizeOf(Info)), @Result, SizeOf(Result), R); Windows.ClientToScreen(hWnd, Result.TopLeft); Windows.ClientToScreen(hWnd, Result.BottomRight); mHandle:=hWnd; Break; end; end; end else begin C := SendMessage(hWnd, TCM_GETITEMCOUNT, 0, 0); for i := 0 to C - 1 do begin with Item do begin mask := TCIF_TEXT; dwState := 0; dwStateMask := 0; cchTextMax := 2048; pszText := PChar(integer(Buff) + SizeOf(Item) * 4); iImage := 0; lParam := 0; end; WriteProcessMemory(PRC, Buff, @Item, SizeOf(Item), R); SendMessage(hWnd, TCM_GETITEM, i, Integer(Buff)); ReadProcessMemory(PRC, Buff, @Item, SizeOf(Item), R); ReadProcessMemory(PRC, PChar(integer(Buff) + SizeOf(Item) * 4), @S[0], SizeOf(S), R); if SameText(S, Title) then begin xxx:=True; IconId:=(C-1)-i; SendMessage(hWnd, TCM_GETITEMRECT, i, integer(Buff)); ReadProcessMemory(PRC, Buff, @Result, SizeOf(Result), R); Windows.ClientToScreen(hWnd, Result.TopLeft); Windows.ClientToScreen(hWnd, Result.BottomRight); Break; end; end; end; VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE); CloseHandle(PRC); end;{* 得到所有托盘文字信息处理之~~~ *} procedure Ttuo.GetAllTipText; var C, i: integer; Info: _TBBUTTON; Item: tagTCITEM; Buff: PChar; S: array[0..1024] of char; PID: THandle; PRC: THandle; R: Cardinal; hWnd:THandle;
begin hWnd:=GetSysTrayWnd; if hWnd = 0 then Exit; GetWindowThreadProcessId(hWnd, @PID); PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID); Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE); if Format('%d.%d', [Win32MajorVersion, Win32MinorVersion]) >= '5.1' then {// Is Windows XP or Higher} begin C := SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0); for i := 0 to C - 1 do begin FillChar(Info, SizeOf(Info), 0); WriteProcessMemory(PRC, Buff, @Info, SizeOf(Info), R); SendMessage(hWnd, TB_GETBUTTON, i, integer(Buff)); ReadProcessMemory(PRC, Buff, @Info, SizeOf(Info), R); //x:=SendMessage(hWnd, TB_GETIMAGELIST, i, integer(Buff));// IMAGELIST SendMessage(hWnd, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buff[0]) + SizeOf(Info))); ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) + SizeOf(Info)), @S[0], SizeOf(S), R); mstr.Add(StrPas(s)); end; end else begin C := SendMessage(hWnd, TCM_GETITEMCOUNT, 0, 0); for i := 0 to C - 1 do begin with Item do begin mask := TCIF_TEXT; dwState := 0; dwStateMask := 0; cchTextMax := 2048; pszText := PChar(integer(Buff) + SizeOf(Item) * 4); iImage := 0; lParam := 0; end; WriteProcessMemory(PRC, Buff, @Item, SizeOf(Item), R); SendMessage(hWnd, TCM_GETITEM, i, Integer(Buff)); ReadProcessMemory(PRC, Buff, @Item, SizeOf(Item), R); ReadProcessMemory(PRC, PChar(integer(Buff) + SizeOf(Item) * 4), @S[0], SizeOf(S), R); mstr.Add(StrPas(s)); end; end; VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE); CloseHandle(PRC); end; function Ttuo.GetSysTrayWnd: HWND; { 返回系统托盘的句柄,适合于WinXP以上版本 } begin Result := FindWindow('Shell_TrayWnd', nil); Result := FindWindowEx(Result, 0, 'TrayNotifyWnd', nil); Result := FindWindowEx(Result, 0, 'SysPager', nil); Result := FindWindowEx(Result, 0, 'ToolbarWindow32', nil); end; function Ttuo.GetSysTrayIconRect(Text: string): TRect; { 返回系统托盘中指定文字的图标的矩形区域。 例如返回音量控制图标的矩形区域: GetSysTrayIconRect('音量'); } begin Result := GetToolBarButtonRect(GetSysTrayWnd,Text); end;//procedure Ttuo.bsskinListView1Change(Sender: TObject; Item: TListItem; // Change: TItemChange); //begin//end;procedure Ttuo.FormShow(Sender: TObject); begin mstr:=TStringList.Create; BitBtn1.Click; end;procedure Ttuo.BitBtn1Click(Sender: TObject); var i,j:Integer; begin //得到全部文字提示后,删除重复的,空的 mstr.Clear; bsskinListView1.Clear; GetAllTipText; for i:=0 to mstr.Count-1 do for j:=mstr.Count-1 downto i+1 do if (mstr.Strings[i]=mstr.Strings[j]) or (mstr.Strings[j]='') then mstr.Delete(j);//加入listview1 for i:=0 to mstr.Count-1 do with bsskinListView1.Items.Add do begin Caption:=mstr.Strings[i]; SubItems.Add('999'); end; //加入索引值 for i:=0 to bsskinListView1.Items.Count-1 do begin GetSysTrayIconRect(bsskinListView1.Items[i].Caption); bsskinListView1.Items[i].SubItems[0]:=IntToStr(IconId); end; end;procedure Ttuo.BitBtn2Click(Sender: TObject); var AID: _NOTIFYICONDATA; begin AID.cbSize := SizeOf(AID); AID.Wnd := Handle; AID.uID := 0; AID.uFlags := NIF_ICON; AID.uCallbackMessage := 0; AID.hIcon := Icon.Handle; AID.szTip := ''; Shell_NotifyIcon(NIM_ADD, @AID); AID.cbSize := SizeOf(AID); AID.Wnd := Handle; AID.uID := 0; Shell_NotifyIcon(NIM_DELETE, @AID); end;procedure Ttuo.FormCreate(Sender: TObject); beginLeft:=Screen.Width-Self.Width; //Top:=Screen.Top-Self.Top; Top:=Screen.Height-2*Height+ClientHeight+10; end;procedure Ttuo.bsSkinListView1Click(Sender:TObject); begin if bsskinListView1.Focused then begin //if Item.Checked then if bsskinlistView1.SelCount>0 then //if bsskinListView1.Selected.Checked then begin SendMessage(GetSysTrayWnd,TB_HIDEBUTTON,StrToInt(bsskinListView1.Selected.SubItems[0]),1); end else begin SendMessage(GetSysTrayWnd,TB_HIDEBUTTON,StrToInt(bsskinListView1.Selected.SubItems[0]),0); end; Bitbtn2.Click; end; end;end.
想麻烦的话也可以自己来写 赫赫
unit tuoz;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,CommCtrl, ExtCtrls, Buttons, ComCtrls, ImgList,ShellAPI,
Menus, bsSkinData, BusinessSkinForm, bsSkinCtrls;type
Ttuo = class(TForm)
Panel1: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
bsBusinessSkinForm1: TbsBusinessSkinForm;
bsSkinData1: TbsSkinData;
bsCompressedStoredSkin1: TbsCompressedStoredSkin;
bsSkinListView1: TbsSkinListView;
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure bsSkinListView1Click(Sender: TObject);
private
{ Private declarations }
function GetSysTrayIconRect(Text: string): TRect;
function GetSysTrayWnd: HWND;
procedure GetAllTipText;
public
{ Public declarations }
end;var
tuo: Ttuo;
IconId:Integer;
mHandle:THandle;
xxx:Boolean;
mstr:TStringList;
implementation
{$R *.dfm}
function GetToolBarButtonRect(hWnd: HWND; Title: string): TRect;
{
返回指定工具栏对应的按钮指定文本的矩形区域
hWnd:工具栏句柄,Title:需要返回矩形区域的按钮文字
返回值:指定按钮的边界矩形,屏幕坐标
}
var
C, i: integer;
Info: _TBBUTTON;
Item: tagTCITEM;
Buff: PChar;
S: array[0..1024] of char;
PID: THandle;
PRC: THandle;
R: Cardinal;
begin
IconId:=-1;
FillChar(Result, SizeOf(Result), 0);
if hWnd = 0 then Exit;
GetWindowThreadProcessId(hWnd, @PID);
PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID);
Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE); if Format('%d.%d', [Win32MajorVersion, Win32MinorVersion]) >= '5.1' then {// Is Windows XP or Higher}
begin
C := SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0);
for i := 0 to C - 1 do
begin
FillChar(Info, SizeOf(Info), 0);
WriteProcessMemory(PRC, Buff, @Info, SizeOf(Info), R); SendMessage(hWnd, TB_GETBUTTON, i, integer(Buff));
ReadProcessMemory(PRC, Buff, @Info, SizeOf(Info), R); SendMessage(hWnd, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buff[0]) + SizeOf(Info)));
ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) + SizeOf(Info)), @S[0], SizeOf(S), R); if SameText(StrPas(S), Title) then //and not Boolean(SendMessage(hWnd, TB_ISBUTTONHIDDEN, Info.idCommand, 0)) then
begin
xxx:=True;
IconId:=(C-1)-i;
SendMessage(hWnd, TB_GETRECT, Info.idCommand, integer(integer(@Buff[0]) + SizeOf(Info)));
ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) + SizeOf(Info)), @Result, SizeOf(Result), R); Windows.ClientToScreen(hWnd, Result.TopLeft);
Windows.ClientToScreen(hWnd, Result.BottomRight);
mHandle:=hWnd; Break;
end;
end;
end
else
begin
C := SendMessage(hWnd, TCM_GETITEMCOUNT, 0, 0);
for i := 0 to C - 1 do
begin
with Item do
begin
mask := TCIF_TEXT;
dwState := 0;
dwStateMask := 0;
cchTextMax := 2048;
pszText := PChar(integer(Buff) + SizeOf(Item) * 4);
iImage := 0;
lParam := 0;
end;
WriteProcessMemory(PRC, Buff, @Item, SizeOf(Item), R);
SendMessage(hWnd, TCM_GETITEM, i, Integer(Buff)); ReadProcessMemory(PRC, Buff, @Item, SizeOf(Item), R);
ReadProcessMemory(PRC, PChar(integer(Buff) + SizeOf(Item) * 4), @S[0], SizeOf(S), R); if SameText(S, Title) then
begin
xxx:=True;
IconId:=(C-1)-i;
SendMessage(hWnd, TCM_GETITEMRECT, i, integer(Buff));
ReadProcessMemory(PRC, Buff, @Result, SizeOf(Result), R); Windows.ClientToScreen(hWnd, Result.TopLeft);
Windows.ClientToScreen(hWnd, Result.BottomRight);
Break;
end;
end;
end; VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE);
CloseHandle(PRC);
end;{*
得到所有托盘文字信息处理之~~~
*}
procedure Ttuo.GetAllTipText;
var
C, i: integer;
Info: _TBBUTTON;
Item: tagTCITEM;
Buff: PChar;
S: array[0..1024] of char;
PID: THandle;
PRC: THandle;
R: Cardinal;
hWnd:THandle;
hWnd:=GetSysTrayWnd;
if hWnd = 0 then Exit;
GetWindowThreadProcessId(hWnd, @PID);
PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID);
Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE); if Format('%d.%d', [Win32MajorVersion, Win32MinorVersion]) >= '5.1' then {// Is Windows XP or Higher}
begin
C := SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0);
for i := 0 to C - 1 do
begin
FillChar(Info, SizeOf(Info), 0);
WriteProcessMemory(PRC, Buff, @Info, SizeOf(Info), R); SendMessage(hWnd, TB_GETBUTTON, i, integer(Buff));
ReadProcessMemory(PRC, Buff, @Info, SizeOf(Info), R);
//x:=SendMessage(hWnd, TB_GETIMAGELIST, i, integer(Buff));// IMAGELIST SendMessage(hWnd, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buff[0]) + SizeOf(Info)));
ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) + SizeOf(Info)), @S[0], SizeOf(S), R);
mstr.Add(StrPas(s));
end;
end
else
begin
C := SendMessage(hWnd, TCM_GETITEMCOUNT, 0, 0);
for i := 0 to C - 1 do
begin
with Item do
begin
mask := TCIF_TEXT;
dwState := 0;
dwStateMask := 0;
cchTextMax := 2048;
pszText := PChar(integer(Buff) + SizeOf(Item) * 4);
iImage := 0;
lParam := 0;
end;
WriteProcessMemory(PRC, Buff, @Item, SizeOf(Item), R);
SendMessage(hWnd, TCM_GETITEM, i, Integer(Buff)); ReadProcessMemory(PRC, Buff, @Item, SizeOf(Item), R);
ReadProcessMemory(PRC, PChar(integer(Buff) + SizeOf(Item) * 4), @S[0], SizeOf(S), R);
mstr.Add(StrPas(s));
end;
end; VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE);
CloseHandle(PRC);
end;
function Ttuo.GetSysTrayWnd: HWND;
{
返回系统托盘的句柄,适合于WinXP以上版本
}
begin
Result := FindWindow('Shell_TrayWnd', nil);
Result := FindWindowEx(Result, 0, 'TrayNotifyWnd', nil);
Result := FindWindowEx(Result, 0, 'SysPager', nil);
Result := FindWindowEx(Result, 0, 'ToolbarWindow32', nil);
end;
function Ttuo.GetSysTrayIconRect(Text: string): TRect;
{
返回系统托盘中指定文字的图标的矩形区域。
例如返回音量控制图标的矩形区域:
GetSysTrayIconRect('音量');
}
begin
Result := GetToolBarButtonRect(GetSysTrayWnd,Text);
end;//procedure Ttuo.bsskinListView1Change(Sender: TObject; Item: TListItem;
// Change: TItemChange);
//begin//end;procedure Ttuo.FormShow(Sender: TObject);
begin
mstr:=TStringList.Create;
BitBtn1.Click;
end;procedure Ttuo.BitBtn1Click(Sender: TObject);
var
i,j:Integer;
begin
//得到全部文字提示后,删除重复的,空的
mstr.Clear;
bsskinListView1.Clear;
GetAllTipText;
for i:=0 to mstr.Count-1 do
for j:=mstr.Count-1 downto i+1 do
if (mstr.Strings[i]=mstr.Strings[j]) or (mstr.Strings[j]='') then mstr.Delete(j);//加入listview1
for i:=0 to mstr.Count-1 do
with bsskinListView1.Items.Add do
begin
Caption:=mstr.Strings[i];
SubItems.Add('999');
end;
//加入索引值
for i:=0 to bsskinListView1.Items.Count-1 do
begin
GetSysTrayIconRect(bsskinListView1.Items[i].Caption);
bsskinListView1.Items[i].SubItems[0]:=IntToStr(IconId);
end;
end;procedure Ttuo.BitBtn2Click(Sender: TObject);
var
AID: _NOTIFYICONDATA;
begin
AID.cbSize := SizeOf(AID);
AID.Wnd := Handle;
AID.uID := 0;
AID.uFlags := NIF_ICON;
AID.uCallbackMessage := 0;
AID.hIcon := Icon.Handle;
AID.szTip := '';
Shell_NotifyIcon(NIM_ADD, @AID);
AID.cbSize := SizeOf(AID);
AID.Wnd := Handle;
AID.uID := 0;
Shell_NotifyIcon(NIM_DELETE, @AID);
end;procedure Ttuo.FormCreate(Sender: TObject);
beginLeft:=Screen.Width-Self.Width;
//Top:=Screen.Top-Self.Top;
Top:=Screen.Height-2*Height+ClientHeight+10;
end;procedure Ttuo.bsSkinListView1Click(Sender:TObject);
begin
if bsskinListView1.Focused then
begin
//if Item.Checked then
if bsskinlistView1.SelCount>0 then
//if bsskinListView1.Selected.Checked then
begin
SendMessage(GetSysTrayWnd,TB_HIDEBUTTON,StrToInt(bsskinListView1.Selected.SubItems[0]),1);
end
else
begin
SendMessage(GetSysTrayWnd,TB_HIDEBUTTON,StrToInt(bsskinListView1.Selected.SubItems[0]),0);
end;
Bitbtn2.Click;
end;
end;end.
有高手解答吗