Recent

Author Topic: HWND_BROADCAST - doesn't work with PostMessage  (Read 10240 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
HWND_BROADCAST - doesn't work with PostMessage
« on: June 11, 2011, 09:47:44 pm »
Hi,

I am trying to send HWND_BROADCAST message (this is some kind of signal which is sended to all top windows) but this works only with SendMessage but documentation say that is should works with PostMessage too:
http://msdn.microsoft.com/en-us/library/ms644944(v=vs.85).aspx

And this is my code:
Application 1 (sender)
Code: Pascal  [Select][+][-]
  1. uses windows;
  2.  
  3. var
  4.   FMsg: UINT;
  5.  
  6. begin
  7.   FMsg := RegisterWindowMessage('my_test_message');
  8.   // Works
  9.   windows.SendMessage(HWND_BROADCAST, FMsg, 1, 0);
  10.   // Doesn't work
  11.   //windows.PostMessage(HWND_BROADCAST, FMS, 1, 0);
  12. end;
  13.  

Application 2 (Receiver)
Code: Pascal  [Select][+][-]
  1. uses windows;
  2.  
  3.   type
  4.   TForm1 = class(TForm)
  5.     procedure FormCreate(Sender: TObject);
  6.   private
  7.     { private declarations }
  8.     MsgSignals: UINT;
  9.   protected
  10.     procedure WndProc(var TheMessage: TLMessage); override;
  11.   public
  12.     { public declarations }
  13.   end;
  14.  
  15. procedure TForm1.FormCreate(Sender: TObject);
  16. begin
  17.   MsgSignals := RegisterWindowMessage('my_test_message');
  18. end;
  19.  
  20. procedure TForm1.WndProc(var TheMessage: TLMessage);
  21. begin
  22.   if TheMessage.msg=MsgSignals then
  23.     Memo1.Append('WParam: '+IntToStr(TheMessage.wParam));
  24.   inherited WndProc(TheMessage);
  25. end;
  26.  
I could leave SendMessage but it waiting for processing. Any idea? Is this a bug?

Regards

Stable Lazarus 0.9.30, FPC 2.4.2. Windows 7 32bit

 

TinyPortal © 2005-2018