Send messages between processes (send and receive system messages)

Source: Internet
Author: User
{
2002.07.22
About how to send and receive system messages
Author: Wang Zhenyi
Nickname: largewang (Lao Wang)
QQ: 33728007
Welcome to pengye software www.pengesoft.com.cn

Run the following code Delphi7.0. After compiling, start two processes and click button1 in a window.
}

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls;

Type
Tform1 = Class (tform)
Button1: tbutton;
Procedure formcreate (Sender: tobject );
Procedure button1click (Sender: tobject );
Private
MSG: longint;
{Private Declarations}
Protected
Procedure wndproc (VAR message: tmessage); override;
Public

{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

Procedure tform1.formcreate (Sender: tobject );
Begin
MSG: = registerwindowmessage ('wm _ mymessage ');
Self. bringtofront;
End;

Procedure tform1.wndproc (VAR message: tmessage );
Begin
If message. MSG = MSG then begin
Caption: = '';
Showmessage ('Received message ');
End
Else begin
Inherited;
End;
End;

Procedure tform1.button1click (Sender: tobject );
VaR
M: tmessage;
B: DWORD;
Begin
M. MSG: = MSG;
B: = bsm_allcomponents;
Broadcastsystemmessage (bsf_postmessage, @ B, M. MSG, M. wparam, M. lparam );
End;

End.

//// Window file
Object form1: tform1
Left = 1, 192
Maximum = 107
Width = 696
Height = 480
Caption = 'form1'
Color = clbtnface
Font. charset = default_charset
Font. Color = clwindowtext
Font. Height =-11
Font. Name = 'Ms sans serif'
Font. Style = []
Oldcreateorder = false
Oncreate = formcreate
Pixelsperinch = 96
Textheight = 13
Object button1: tbutton
Left = 1, 204
Top = 84
Width = 75
Height = 25
Caption = 'button1'
Taborder = 0
Onclick = button1click
End
End
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.