首页  编辑  

获取任务上面的按钮的RECT

Tags: /超级猛料/OS.操作系统/任务栏/   Date Created:

大家运行这个看看?

{ By Kingron }

它的功能是获取任务上面的按钮的RECT,当然,你要Text也可以,:),很有意思的,研究一个晚上没有明白,今天早上忽然明白了,原来跨进程必须用WriteProcessMemory~~~~~:)

///For Win2003,如果是winxp/2k/9x,自己稍微修改,我没有那些OS,不好做了。:)

procedure TForm1.btn5Click(Sender: TObject);

var

 h: HWND;

 C, i: integer;

 Info: _TBBUTTON;

 Buff: PChar;

 S: array[0..255] of char;

 Rct: TRect;

 PID: THandle;

 PRC: THandle;

 R: Cardinal;

begin

 h := FindWindow('Shell_TrayWnd', nil);

 H := FindWindowEx(H, 0, 'ReBarWindow32', nil);

 H := FindWindowEx(H, 0, 'MSTaskSwWClass', nil);

 H := FindWindowEx(H, 0, 'ToolbarWindow32', nil);

 if H = 0 then Exit;

 C := SendMessage(H, TB_BUTTONCOUNT, 0, 0);

 PID := 0;

 GetWindowThreadProcessId(H, @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);

 for i := 0 to C - 1 do

 begin

   FillChar(Info, SizeOf(Info), 0);

   WriteProcessMemory(PRC, Buff, @Info, SizeOf(Info), R);

   SendMessage(H, TB_GETBUTTON, i, integer(Buff));

   ReadProcessMemory(PRC, Buff, @Info, SizeOf(Info), R);

   SendMessage(H, TB_GETRECT, Info.idCommand, integer(integer(@Buff[0]) + SizeOf(Info)));

   ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) + SizeOf(Info)), @Rct, SizeOf(Rct), R);

   Windows.ClientToScreen(H, Rct.TopLeft);

   Windows.ClientToScreen(H, Rct.BottomRight);

   DrawAnimatedRects(Handle, IDANI_CAPTION, BoundsRect, Rct);

   //    SendMessage(H, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buff[0]) + SizeOf(Info)));

   //    ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) + SizeOf(Info)), @S[0], SizeOf(S), R);

   mmo1.Lines.Add(S);

 end;

 VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE);

 CloseHandle(PRC);

end;