Hmm nasao sam neki primer kako se ovo radi, postovacu i ceo kod, medjutim mislim da sam stigao do neresivog problema. Naime na nekom forumu sam procitao sledece:
Citat:
I have also found out that GWL_WNDPROC in Windows NT/2000: You cannot change
this attribute if the window does not belong to the same process as the calling
thread.
Znaci pod XP-om je nemoguce presretati poruke zbog security-ja
Ili mozda neko ipak zna nacin?
Evo koda koji sam nasao. Uzima handle od nekog prozora i instalira novu hook funkciju za taj prozor. Onda ti mozes obraditi koje god poruke zelis:
Code:
unit WinProc1;
interface
uses
{$IFDEF WIN32}
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBTables;
{$ELSE}
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics,
Controls, Forms, Dialogs, DB, DBTables, Grids, DBGrids;
{$ENDIF}
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
Table1: TTable;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
{$IFDEF WIN32}
WParameter = LongInt;
{$ELSE}
WParameter = Word;
{$ENDIF}
LParameter = LongInt;
{Declare a variable to hold the window procedure we are replacing}
var
OldWindowProc : Pointer;
function NewWindowProc(WindowHandle : hWnd;
TheMessage : WParameter;
ParamW : WParameter;
ParamL : LParameter) : LongInt
{$IFDEF WIN32} stdcall; {$ELSE} ; export; {$ENDIF}
begin
{ Process the message of your choice here }
if TheMessage = WM_VSCROLL then begin
ShowMessage('The vertical scrollbar is scrolling!');
end;
{ Exit here and return zero if you want }
{ to stop further processing of the message }
{ Call the old Window procedure to }
{ allow processing of the message. }
NewWindowProc := CallWindowProc(OldWindowProc,
WindowHandle,
TheMessage,
ParamW,
ParamL);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{ Set the new window procedure for the control }
{ and remember the old window procedure. }
OldWindowProc := Pointer(SetWindowLong(OtherHandle,
GWL_WNDPROC,
LongInt(
NewWindowProc)));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{ Set the window procedure back }
{ to the old window procedure. }
SetWindowLong(OtherHandle,
GWL_WNDPROC,
LongInt(OldWindowProc));
end;
end.
(*
{ The program's main source file }
program WinProc;
uses
Forms,
WinProc1 in 'WinProc1.pas' {Form1};
{$R *.RES}
begin
{$IFDEF WIN32}
Application.Initialize;
{$ENDIF}
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
*)
{ end of ti }