Recent

Author Topic: Getting access to the WindowProc function  (Read 4842 times)

tpglemur

  • New Member
  • *
  • Posts: 13
Getting access to the WindowProc function
« on: September 04, 2008, 11:42:21 am »
Hi is there any way to get WindowProc messages in lazarus? I'm trying to do a wrapper for RichEdit but don't know how to catch the events.

Thanks

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: Getting access to the WindowProc function
« Reply #1 on: September 04, 2008, 04:06:22 pm »
Quote from: "tpglemur"
Hi is there any way to get WindowProc messages in lazarus? I'm trying to do a wrapper for RichEdit but don't know how to catch the events.

Thanks


Felipe came up with a way of doing this on Windows. I don't recall where it's documented, but you might want to search the wiki.

I used his approach in the ported Orpheus o32vlop1.pas validation unit. You can look at what's involved there and see if that's what you have in mind.

http://wiki.lazarus.freepascal.org/OrphPort

Thanks.

-Phil

tpglemur

  • New Member
  • *
  • Posts: 13
Getting access to the WindowProc function
« Reply #2 on: September 05, 2008, 02:45:11 am »
Thanks for the reply.

I tried overriding the TWinControl's WinProc procedure, it seems to work.

I'm not sure it'll work, but I'm planning to put the RichEdit on the TWinControl via CreateWindowEx, and I'm hoping that the WinProc will pick up the RichEdit's messages.

tpglemur

  • New Member
  • *
  • Posts: 13
Getting access to the WindowProc function
« Reply #3 on: September 10, 2008, 04:29:59 am »
I think the solution is here: http://www.spotlight.de/zforen/dlp/m/dlp-1204925621-1167.html

The code is reproduced here for reference

Type
  TWndProc = Windows.WNDPROC;


Var
  OldWnd: TWndProc = nil;

function StandByNotify(Hnd: HWnd; Msg: UInt; WParam: Windows.WParam; LParam: Windows.LParam): LResult; stdcall;
begin
  showmessage('StandByNotify');
  result := Windows.CallWindowProc(OldWnd,Hnd,Msg,WParam,LParam);
end;

constructor TPlayer.Create(AOwner: TWinControl);
begin
  ...
  if not assigned(OldWnd) then begin
    OldWnd := TWndProc(Windows.GetWindowLong(Application.MainForm.Handle,GWL_WNDPROC));
    Windows.SetWindowLong(Application.MainForm.Handle,GWL_WNDPROC,LongInt(@StandByNotify)); // hier entsteht der Fehler
  end;
  ...
end;

destructor TPlayer.Destroy;
begin
  if Assigned(OldWnd) then
    Windows.SetWindowLong(Application.MainForm.Handle,GWL_WNDPROC,LongInt(OldWnd));
  OldWnd := nil;
  ...
end;

Das verursacht eien Fehler ('External: SIGSEGV') in

function TWinControl.HandleAllocated : Boolean;
begin
  HandleAllocated := (FHandle <> 0);
end;



Thanks to the author