这个是根据BCB改的 原帖见<br>http://topic.csdn.net/t/20050301/18/3816203.html<br>这里我只写出列举 不写删除<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, CommCtrl, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Memo1: TMemo;<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> procedure f_ShowTrayIcon();<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.f_ShowTrayIcon();<br>var<br> hTrayWnd: THandle;<br> dwProcessID: DWORD;<br> hSourceHandle: THandle;<br> hTargetHandle: THandle;<br> pStart: Pointer;<br> pBufStart: Pointer;<br><br><br> Result : Integer;<br> dwAllocSize: DWORD;<br><br> ButtonCount: Integer;<br><br> v_Count: Integer;<br><br> v_Info: TBBUTTONINFO;<br> dwWrite,dwRead: DWORD;<br><br> TempBuf: PByte;<br>const<br> TextBufSize = 128;<br>begin<br> hTrayWnd := FindWindow('Shell_TrayWnd', nil);<br> hTrayWnd := FindWindowEx(hTrayWnd,0,'TrayNotifyWnd',nil);<br> hTrayWnd := FindWindowEx(hTrayWnd,0,'SysPager',nil); //<--2000不要这个<br> hTrayWnd := FindWindowEx(hTrayWnd,0,'ToolbarWindow32',nil);<br><br> GetWindowThreadProcessId(hTrayWnd, @dwProcessID);<br><br> hSourceHandle := OpenProcess(PROCESS_ALL_ACCESS,false,dwProcessID);<br> if hSourceHandle = 1 then<br> begin<br> Memo1.Lines.Add('Error Open Process. Err=' + SysErrorMessage(GetLastError()));<br> end;<br><br> Result := Integer(DuplicateHandle(GetCurrentProcess(),hSourceHandle,GetCurrentProcess(),<br> @hTargetHandle,PROCESS_ALL_ACCESS,false,0));<br><br> if Result = 0 THEN<br> begin<br> Memo1.Lines.Add('Error Open Process. Err=' + SysErrorMessage(GetLastError()));<br> end;<br><br> dwAllocSize := sizeof(TBBUTTONINFO);<br><br> pStart := VirtualAllocEx(hTargetHandle,nil,dwAllocSize,MEM_COMMIT,PAGE_READWRITE);<br> pBufStart := VirtualAllocEx(hTargetHandle,nil,TextBufSize,MEM_COMMIT,PAGE_READWRITE);<br><br> if (pStart = nil) and (pBufStart = nil) then<br> begin<br> Memo1.Lines.Add('Error Open Process. Err=' + SysErrorMessage(GetLastError()));<br> end;<br><br> ButtonCount := SendMessage(hTrayWnd,TB_BUTTONCOUNT,0,0);<br><br> Memo1.Lines.Add('Count = ' + IntToStr(ButtonCount));<br><br><br> for v_Count := 0 to ButtonCount - 1 do<br> begin<br> v_Info.cbSize := dwAllocSize;<br> v_Info.dwMask := TBIF_TEXT;<br> v_Info.pszText := LPTSTR(pBufStart);<br> WriteProcessMemory(hTargetHandle,pStart,Pointer(@v_Info),dwAllocSize, dwWrite);<br><br> New(TempBuf);<br> TempBuf := AllocMem(TextBufSize);<br> ZeroMemory(TempBuf,TextBufSize);<br> WriteProcessMemory(hTargetHandle,pBufStart,Pointer(TempBuf),TextBufSize,dwWrite);<br><br> SendMessage(hTrayWnd,TB_GETBUTTONINFO,v_Count, iNTEGER(PTBBUTTONINFO(pStart)));// Button);<br><br> ReadProcessMemory(hTargetHandle,Pointer(pBufStart),Pointer(TempBuf),TextBufSize,dwRead);<br><br> Memo1.Lines.Add(STRING(TempBuf));<br><br> Dispose(TempBuf);<br> end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> f_ShowTrayIcon;<br>end;<br><br>end.