PDA

Просмотр полной версии : [Delphi] GetText из msctls_statusbar32


ex3me
20.08.2009, 00:16
Нашел в инете замечательную функцию для получения текста из msctls_statusbar32 :


function GetStatusText(wndWindow: THandle;
StatusBarClassName: string;
PanelIndex: Byte): string;
var
WndStatusBar: THandle;
StatusBarText: array[0..$FFF] of Char;
begin
Result := '';
WndStatusBar := FindWindowEx(wndWindow, 0, PChar(StatusBarClassName), nil);
if WndStatusBar <> 0 then
begin
if PanelIndex = 0 then
SendMessage(WndStatusBar, WM_GETTEXT, $FFF, Longint(@StatusBarText))
else
SendMessage(WndStatusBar, SB_GETTEXT, PanelIndex, Longint(@StatusBarText));
Result := StrPas(StatusBarText);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
// Read statustext from Internet Explorer
label1.Caption := GetStatusText(FindWindow('IEFrame', nil), 'msctls_statusbar32', 0);
end;


Да вот одна проблема: при GetStatusText(FindWindow('IEFrame', nil), 'msctls_statusbar32', 0);, где второй параметр равен нулю (указывает на номер области статус бара, нумеруются они с нуля), все работает отлично - текст грабится.
Но если указать вторым параметром этой функции 1 или 2 (всего в статусбаре чужого приложения 3 области) - текст не грабится.

Комметарии вроде: там стоит WM_GETTEXT, а там - SB_GETTEXT - не уместны... Пробовал по-разному, подставляя различные значения.

Установка длины текста с помощью SB_GETTEXTLENGTH так же не помогает =\

Может кто-то осилит довести до ума эту функцию, ибо уже 6й час бьюсь и все бестолку :mad: :mad: :mad:

add: uses CommCtrl

flacs
20.08.2009, 12:05
Переписал функцию, проверил работает.

function GetStatusTextEx(PanelIndex: cardinal): string;
function GetWindowTextEx(Wnd: THandle): string;
var
__Text: array [0..$FFF] of Char;
s: string;
begin
Result:='';
if Wnd <> 0 then begin
SendMessage(Wnd, WM_GETTEXT, $FFF, Longint(@__Text));
Result := StrPas(__Text);
end;
end;
const PANEL_CLASS = 'TabWindowClass';
var wnd, nWnd, status: cardinal;
buf: array [0..MAX_PATH-1] of char;
num: cardinal;
begin
Result:='';
wnd:=FindWindow('IEFrame', nil);
nWnd:=GetWindow(Wnd, GW_CHILD); num:=0;
{Перечисляем детей...}
while (nWnd<>0) do begin
nWnd:=GetNextWindow(nWnd, GW_HWNDNEXT);
if (nWnd=0) then break;
GetClassName(nWnd, buf, SizeOf(buf));
if buf = PANEL_CLASS then begin
status:=FindWindowEx(nWnd, 0, 'msctls_statusbar32', nil);
if num = PanelIndex then Result:=GetWindowTextEx(status);
inc(num);
end;
end;
end;



изпользовать
Label1.Caption:=GetStatusTextEx(1);