Link to home
Start Free TrialLog in
Avatar of andrezzz
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...
Avatar of shaneholmes
shaneholmes

I believe they just add the following code after each open, or load

 form.Caption:= form.Caption + ' - ' + Your other forms caption here

Shane
Avatar of andrezzz

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
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].Handle) 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('Changed - '+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.aryTitleRec, Length(Form1.aryTitleRec)+1);
Form1.aryTitleRec[High(Form1.aryTitleRec)].Handle := hWnd;
if GetWindowText(hWnd, TextBuf, 1024) > 0 then
  Form1.aryTitleRec[High(Form1.aryTitleRec)].Title := 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_StartTitleMonitorClick(Sender: 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_StopTitleMonClick(Sender: TObject);
begin
// button click to stop monitor
Timer4.Enabled := False;
end;

 - - - - - - - - - - - - - - - - - - - - - - - - - - -

you might try this, , ask questions if you need more information
ASKER CERTIFIED SOLUTION
Avatar of Melih SARICA
Melih SARICA
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

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