Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

hooks on windows title change...

Posted on 2004-03-25
6
Medium Priority
?
291 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

824 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