Recent

Author Topic: Application.HookMainWindow(AppWindowHook)  (Read 4433 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Application.HookMainWindow(AppWindowHook)
« on: December 08, 2015, 05:59:46 pm »
This question was asked 3 years ago on this forum, without an answer. Perhaps there is one today. I'm converting from Delphi to Lazarus. In one unit, on a mouse up event, I have:
Code: Pascal  [Select][+][-]
  1. const
  2.   WM_Selected = WM_App + 100;
  3. begin
  4.      SendMessage(Application.Handle, WM_Selected, 0, 0);
  5.  

in another unit I have:
Code: Pascal  [Select][+][-]
  1. function TMyApp.AppWindowHook(var Message: TMessage): Boolean;
  2. begin
  3.   if  message.msg = WM_Selected then
  4.     DoSomething;
  5. end;
  6.  
  7. procedure TMyApp.FormShow(Sender: TObject);
  8. begin
  9.   Application.HookMainWindow(AppWindowHook);
  10. end;
  11.  
  12. procedure TMyApp.FormDestroy(Sender: TObject);
  13. begin
  14.   Application.UnhookMainWindow(AppWindowHook);
  15. end;
  16.  

Lazaraus can not compile MyApp  - Error: identifier idents no member "HookMainWindow", etc.

How can I do this is Lazarus. Is there another unit I need in Uses?
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

balazsszekely

  • Guest
Re: Application.HookMainWindow(AppWindowHook)
« Reply #1 on: December 08, 2015, 06:31:18 pm »
For custom messages you don't need hooks. Just add windows to the uses clauses.(I know you' re under windows ;) ). For a cross platform solution, replace WM_ with the appropriate message from unit LMessages.pp.
Code: Pascal  [Select][+][-]
  1. const
  2.   WM_Selected = WM_APP + 100;
  3.  
  4. type
  5.   { TForm1 }
  6.  
  7.   TForm1 = class(TForm)
  8.     Button1: TButton;
  9.     procedure Button1Click(Sender: TObject);
  10.   private
  11.     { private declarations }
  12.     procedure OnMyMessage(var Msg: TMessage); message WM_Selected;
  13.   public
  14.     { public declarations }
  15.   end;
  16.  
  17. var
  18.   Form1: TForm1;
  19.  
  20. implementation
  21.  
  22. {$R *.lfm}
  23.  
  24. { TForm1 }
  25.  
  26. procedure TForm1.Button1Click(Sender: TObject);
  27. begin
  28.   SendMessage(Form1.Handle, WM_Selected, Integer(555), 0);
  29. end;
  30.  
  31. procedure TForm1.OnMyMessage(var Msg: TMessage);
  32. begin
  33.   ShowMessage(IntToStr(Msg.wParam));
  34. end;                              
  35.  

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
[Solved] Application.HookMainWindow(AppWindowHook)
« Reply #2 on: December 08, 2015, 11:50:03 pm »
Thanks for your perfect solution GetMem. It helps when you don't make typos like I did initially :(
« Last Edit: December 09, 2015, 12:06:06 am by bobonwhidbey »
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018