2009通过上面方式无效,如果qq在托盘显示,则可以在托盘中查找,提供一种思路而已,不一定对你有用。var id: array[0..100] of integer;{$R *.dfm}procedure TFrmTray.FormCreate(Sender: TObject);var v_hShellTray: THandle;
v_hTrayNotify: THandle;
v_hToolBar: THandle;
v_SysPager: THandle;
i, j, k: integer;
Info: _TBBUTTON;
buffer: pchar;
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_SysPager := FindWindowEx(v_hTrayNotify, 0, 'SysPager', nil);
v_hToolBar := FindWindowEx(v_SysPager, 0, 'ToolbarWindow32', nil);
if v_hToolBar=0 then
Exit;
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;