Recent

Author Topic: PostMessage example  (Read 1140 times)

Ericktux

  • Full Member
  • ***
  • Posts: 230
PostMessage example
« on: November 30, 2020, 04:42:55 am »
Hello friends, please where can I find an example of how to use "PostMessage" to communicate processes.

Thanks for your time.

dbannon

  • Hero Member
  • *****
  • Posts: 1294
    • tomboy-ng, a rewrite of the classic Tomboy
Re: PostMessage example
« Reply #1 on: November 30, 2020, 08:36:59 am »
PostMessage as in httpclient ?

about line 950
https://github.com/tomboy-notes/tomboy-ng/blob/nextcloud/source/transnextcloud.pas

or maybe using SimpleIPCClient

about line 127
https://github.com/tomboy-notes/tomboy-ng/blob/master/source/cli.pas

Lots of other ways to PostMessage of course, you might need to be a bit more specific ...

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Ericktux

  • Full Member
  • ***
  • Posts: 230
Re: PostMessage example
« Reply #2 on: November 30, 2020, 03:55:43 pm »
hello friend, basically what I need to know is how to communicate two processes (parent, child) with the postmessage command

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 865
    • Lebeau Software
Re: PostMessage example
« Reply #3 on: November 30, 2020, 06:41:35 pm »
hello friend, basically what I need to know is how to communicate two processes (parent, child) with the postmessage command

There are a bazillion online examples of using PostMessage() and SendMessage() for inter-process communications using window messages.  What EXACTLY do you need help with in doing this with FPC?  Can you be more specific?
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

jamie

  • Hero Member
  • *****
  • Posts: 4161
Re: PostMessage example
« Reply #4 on: November 30, 2020, 11:01:07 pm »
of course this will only work on windows. I don't think the window managers on other targets have such control ?

In any case, you need to acquire the window handle of the other process you wish to send messages to.

 I suppose if you use some sort of unique window search like EnumWindows or FindWindow etc, you could comeup with something..


 Simple example

 PostMessage(theRemoteWindowHandle, TheMessageTOSend, Param1, Param2);

The only true wisdom is knowing you know nothing

zoltanleo

  • Sr. Member
  • ****
  • Posts: 293
Re: PostMessage example
« Reply #5 on: December 01, 2020, 04:49:41 pm »
of course this will only work on windows.
I think this is not entirely true  ;)

Hello friends, please where can I find an example of how to use "PostMessage" to communicate processes.
PostMessage function is used in very specific cases like threads. Here is the topic where it was discussed
https://forum.lazarus.freepascal.org/index.php/topic,40163.msg277135.html#msg277135

it can also be used on the main thread, for example to destroy a control or close a form
Code: Pascal  [Select][+][-]
  1. const
  2.   WM_KILLBTN_MSG = LM_USER + $101;  
  3. ...
  4.   public
  5.     procedure WmKillBtn(var Msg: TLMessage) message WM_KILLBTN_MSG;
  6.   end;
  7. ...
  8. procedure TfrmMain.ActKillBtnExecute(Sender: TObject);
  9. begin
  10.   PostMessage(Self.Handle,WM_KILLBTN_MSG,PtrInt(TButton(Sender)),0);
  11. end;
  12. ...
  13. procedure TfrmMain.WmKillBtn(var Msg: TLMessage);
  14. var
  15.   btn: TButton;
  16. begin
  17.   btn:= TButton(Msg.wParam);
  18.   if Assigned(btn) then FreeAndNil(btn);
  19. end;

Win10 LTSC x64/Deb 10 amd64/Darwin Cocoa:
Lazarus x32/x64 2.1(r.64226); FPC 3.3.1 (r.47808), FireBird 3.0.7

Sorry for my bad English, I'm using translator ;)

PascalDragon

  • Hero Member
  • *****
  • Posts: 2746
  • Compiler Developer
Re: PostMessage example
« Reply #6 on: December 02, 2020, 09:17:09 am »
of course this will only work on windows.
I think this is not entirely true  ;)

Yes, it is true. While PostMessage itself is implemented by the LCL for communication inside the same process, it is not implemented for IPC. On Windows it directly uses the WinAPI function thus it's no problem there.

zoltanleo

  • Sr. Member
  • ****
  • Posts: 293
Re: PostMessage example
« Reply #7 on: December 02, 2020, 10:08:55 am »
Hi PascalDragon.

Perhaps we are talking about different things.
I wanted to say that PostMessage can be used not only for Windows. And it works great for Linux. Lazarus is a cool IDE!  ;)
Win10 LTSC x64/Deb 10 amd64/Darwin Cocoa:
Lazarus x32/x64 2.1(r.64226); FPC 3.3.1 (r.47808), FireBird 3.0.7

Sorry for my bad English, I'm using translator ;)

PascalDragon

  • Hero Member
  • *****
  • Posts: 2746
  • Compiler Developer
Re: PostMessage example
« Reply #8 on: December 02, 2020, 02:44:30 pm »
I wanted to say that PostMessage can be used not only for Windows. And it works great for Linux. Lazarus is a cool IDE!  ;)

As I said: PostMessage itself can be used on non-Windows with the LCL, but only within the same process. On Windows you can use PostMessage to send a message to a completely different process, but only there. And since this topic is about Inter Process Communication as Ericktux already said this is an important distinction.

OkobaPatino

  • Full Member
  • ***
  • Posts: 197
Re: PostMessage example
« Reply #9 on: December 02, 2020, 03:39:34 pm »
zoltanleo, that is a nice demo. Thanks for that.

zoltanleo

  • Sr. Member
  • ****
  • Posts: 293
Re: PostMessage example
« Reply #10 on: December 02, 2020, 04:04:10 pm »
And since this topic is about Inter Process Communication as Ericktux already said this is an important distinction.
OK. Now I understand what you and Ericktux meant. I apologize because my English is not very good. Therefore, I do not always immediately understand all the language subtleties.  :-[
Win10 LTSC x64/Deb 10 amd64/Darwin Cocoa:
Lazarus x32/x64 2.1(r.64226); FPC 3.3.1 (r.47808), FireBird 3.0.7

Sorry for my bad English, I'm using translator ;)

 

TinyPortal © 2005-2018