Solved

hooks on windows title change...

Posted on 2004-03-25
6
282 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 33

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 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