Solved

hooks on windows title change...

Posted on 2004-03-25
6
284 Views
Last Modified: 2010-09-16
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...
0
Comment
Question by:andrezzz
6 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10678085
I believe they just add the following code after each open, or load

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

Shane
0
 

Author Comment

by:andrezzz
ID: 10678111
it is system hook on other forms (windowses)... it is not so simple...
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10678138
Oh, you want it for a window outside our app....

Shane
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 34

Expert Comment

by:Slick812
ID: 10699246
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
0
 
LVL 19

Accepted Solution

by:
Melih SARICA earned 250 total points
ID: 10739976
Here is the System hook of the system messages ..
   


library Messagehook;
uses
  Windows,classes,
  Messages;

procedure SetHook; export; forward;
procedure UnSetHook; export; forward;
procedure SetMainHandle(Handle: HWND); export; forward;

exports
 SetHook ,
 UnSetHook ,
 SetMainHandle ;
const
   mGet_message = WM_user+6666;
type
 PHookRec = ^THookRec;
 THookRec = record
   MainWindow: HWND;
   HookID: HHOOK;
 end;

var
 rHookRec: PHookRec = nil;
 hMapObject: THandle = 0;

procedure SetMainHandle(Handle: HWND);
begin
 rHookRec^.MainWindow := Handle;
end;

function WNDPROCRET_HookProc(nCode: Integer; iWPARAM: cardinal; iLPARAM: Cardinal): integer; stdcall;
begin
  result := 0;
  if (nCode >= 0) And (nCode=HC_ACTION) and (pmsg(ilparam).message = wm_settext )then
       SendMessage(rHookRec^.MainWindow, mGet_message, iWPARAM,iLPARAM);
   Result:=CallNextHookEx(rfocHookRec^.HookID, nCode, iWPARAM,iLPARAM);
end;



procedure SetHook;
begin
 rHookRec^.HookID := SetWindowsHookEx(WH_GETMESSAGE, @WNDPROCRET_HookProc, hInstance, 0);
end;

procedure UnSetHook;
begin
 UnHookWindowsHookEx(rHookRec^.HookID);

end;

procedure EntryPointProc(Reason: Integer);
begin

 case reason of
   DLL_PROCESS_ATTACH:
     begin
     hMapObject := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(rHookRec^), 'mHook');
      rHookRec := MapViewOfFile(hMapObject, FILE_MAP_WRITE, 0, 0, sizeof (rHookRec^));
     sethook;
     end;

   DLL_PROCESS_DETACH:
     begin
       try
         unsethook;
         UnMapViewOfFile(rHookRec);
         CloseHandle(hMapObject);
       except
       end;
     end;

   DLL_THREAD_ATTACH:
     begin
     end;
   DLL_THREAD_DETACH:
     begin
     end;
 end;
end;

begin
 DllProc := @EntryPointProc;
 EntryPointProc(DLL_PROCESS_ATTACH);
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10739985

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

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question