Solved

hooks on windows title change...

Posted on 2004-03-25
6
281 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
Comment Utility
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
Comment Utility
it is system hook on other forms (windowses)... it is not so simple...
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Oh, you want it for a window outside our app....

Shane
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 33

Expert Comment

by:Slick812
Comment Utility
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
Comment Utility
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
Comment Utility

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now