大悟还俗

邮箱 key_ok@qq.com 我的收集 http://pan.baidu.com/share/home?uk=1177427271
posts - 236, comments - 8, trackbacks - 0, articles - 0
  新随笔  :: 联系 :: 订阅 订阅  :: 管理

遍历任务栏上的窗体

Posted on 2013-10-09 13:09 大悟还俗 阅读(...) 评论(...) 编辑 收藏
//-------Delphi-------
uses CommCtrl;
 
procedure TForm1.Button1Click(Sender: TObject);
var
 vHandle: THandle;
 vCount: Integer;
 I: Integer;
 vProcessID: THandle;
 vProcess: THandle;
 vNumberOfBytesRead: DWORD;
 vPointer: Pointer;
 vBuffer: array[0..255] of Char;
begin
 vHandle := FindWindow('Shell_TrayWnd', nil);
 vHandle := FindWindowEx(vHandle,0,'ReBarWindow32', nil);
 vHandle := FindWindowEx(vHandle,0,'MSTaskSwWClass', nil);
 vHandle := FindWindowEx(vHandle,0,'ToolbarWindow32', nil);
 vCount := SendMessage(vHandle, TB_BUTTONCOUNT,0,0);
 GetWindowThreadProcessId(vHandle,@vProcessId);
 vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
    PROCESS_VM_WRITE, False, vProcessId);
 vPointer := VirtualAllocEx(vProcess, nil,$1000, MEM_RESERVE or MEM_COMMIT,
    PAGE_READWRITE);
 try
    for I :=0 to vCount -1 do
    begin
      SendMessage(vHandle, TB_GETBUTTONTEXT, I, Integer(vPointer));
      ReadProcessMemory(vProcess, vPointer,@vBuffer,
        SizeOf(vBuffer), vNumberOfBytesRead);
      OutputDebugString(@vBuffer);
    end;
 finally
    VirtualFreeEx(vProcess, vPointer,0, MEM_RELEASE);
    CloseHandle(vProcess);
 end;
end;