andrezzz
asked on
hooks on windows title change...
how to create hook on windows titile change
for example where runngin word or iexplorer we have titles, on opening other apges or documents this title change... how create hook on this change ???
thx...
for example where runngin word or iexplorer we have titles, on opening other apges or documents this title change... how create hook on this change ???
thx...
ASKER
it is system hook on other forms (windowses)... it is not so simple...
Oh, you want it for a window outside our app....
Shane
Shane
hello andrezzz, , I'm not sure there is a windows system hook that will directly get the "Title change" you describe, , here is some code that uses the API EnumWindows( ) function to find the Main windows and get their text (Title), then it will check these same windows several times a second to see if the text (Title) has changed, this is for Two buttons (one starts the timer, and one stops the timer) a List Box (to get the windows that title change) and a TTimer.
type
TTitleRec = record
Handle: Integer;
Title: String;
end;
TForm1 = class(TForm)
ListBox1: TListBox;
sbut_StartTitleMonitor: TSpeedButton;
Timer4: TTimer;
sbut_StopTitleMon: TSpeedButton;
private
{ Private declarations }
aryTitleRec: Array of TTitleRec; // array to store title info
OnFour: Integer;
procedure CheckTitles;
procedure TForm1.CheckTitles;
var
i: Integer;
TextBuf: Array[0..1023] of Char;
begin
for i := 0 to High(aryTitleRec) do
begin
if not IsWindow(aryTitleRec[i].Ha ndle) then Continue;
TextBuf[0] := #0;
GetWindowText(aryTitleRec[ i].Handle, TextBuf, 1024);
if aryTitleRec[i].Title <> TextBuf then
begin // if the TextBuf is not equal then change
ListBox1.Items.Add('Change d - '+TextBuf+' '+IntToStr(aryTitleRec[i]. Handle));
aryTitleRec[i].Title := TextBuf;
end;
end;
end;
function EnumFunc(hWnd, lParam: Integer): Bool; stdcall;
var
TextBuf: Array[0..1023] of Char;
begin
Result := True;
SetLength(Form1.aryTitleRe c, Length(Form1.aryTitleRec)+ 1);
Form1.aryTitleRec[High(For m1.aryTitl eRec)].Han dle := hWnd;
if GetWindowText(hWnd, TextBuf, 1024) > 0 then
Form1.aryTitleRec[High(For m1.aryTitl eRec)].Tit le := TextBuf;
end;
procedure TForm1.Timer4Timer(Sender: TObject);
begin
CheckTitles;
if onFour = 4 then
begin // no need to reset the aryTitleRec but every second or less
SetLength(aryTitleRec, 0);
EnumWindows(@EnumFunc, 0);
OnFour := 0;
end;
Inc(OnFour);
end;
procedure TForm1.sbut_StartTitleMoni torClick(S ender: TObject);
begin
// button click to start title monitor
SetLength(aryTitleRec, 0);
EnumWindows(@EnumFunc, 0);
OnFour := 0;
Timer4.Interval := 165;
Timer4.Enabled := True;
end;
procedure TForm1.sbut_StopTitleMonCl ick(Sender : TObject);
begin
// button click to stop monitor
Timer4.Enabled := False;
end;
- - - - - - - - - - - - - - - - - - - - - - - - - - -
you might try this, , ask questions if you need more information
type
TTitleRec = record
Handle: Integer;
Title: String;
end;
TForm1 = class(TForm)
ListBox1: TListBox;
sbut_StartTitleMonitor: TSpeedButton;
Timer4: TTimer;
sbut_StopTitleMon: TSpeedButton;
private
{ Private declarations }
aryTitleRec: Array of TTitleRec; // array to store title info
OnFour: Integer;
procedure CheckTitles;
procedure TForm1.CheckTitles;
var
i: Integer;
TextBuf: Array[0..1023] of Char;
begin
for i := 0 to High(aryTitleRec) do
begin
if not IsWindow(aryTitleRec[i].Ha
TextBuf[0] := #0;
GetWindowText(aryTitleRec[
if aryTitleRec[i].Title <> TextBuf then
begin // if the TextBuf is not equal then change
ListBox1.Items.Add('Change
aryTitleRec[i].Title := TextBuf;
end;
end;
end;
function EnumFunc(hWnd, lParam: Integer): Bool; stdcall;
var
TextBuf: Array[0..1023] of Char;
begin
Result := True;
SetLength(Form1.aryTitleRe
Form1.aryTitleRec[High(For
if GetWindowText(hWnd, TextBuf, 1024) > 0 then
Form1.aryTitleRec[High(For
end;
procedure TForm1.Timer4Timer(Sender:
begin
CheckTitles;
if onFour = 4 then
begin // no need to reset the aryTitleRec but every second or less
SetLength(aryTitleRec, 0);
EnumWindows(@EnumFunc, 0);
OnFour := 0;
end;
Inc(OnFour);
end;
procedure TForm1.sbut_StartTitleMoni
begin
// button click to start title monitor
SetLength(aryTitleRec, 0);
EnumWindows(@EnumFunc, 0);
OnFour := 0;
Timer4.Interval := 165;
Timer4.Enabled := True;
end;
procedure TForm1.sbut_StopTitleMonCl
begin
// button click to stop monitor
Timer4.Enabled := False;
end;
- - - - - - - - - - - - - - - - - - - - - - - - - - -
you might try this, , ask questions if you need more information
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Wat u ave to do is to check WM_SetText message and if the messages params point to a window then
it means u get the caption change of a window
form.Caption:= form.Caption + ' - ' + Your other forms caption here
Shane