W
whyme
Unregistered / Unconfirmed
GUEST, unregistred user!
通过下面这一段可取得托盘中的QQ及其号码,但现在我想得到每一个号码实例的句柄,要怎么取得呢? 目的是为了判断当前电脑是否启动了不应该启动的QQ号,如果发现有,则强行关闭它。这样就可避免 当前电脑上一些不许可的QQ号了。 找高手,给个指导!!! uses CommCtrl,ShellAPI; 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;