Messages message uses the

Source: Internet
Author: User

Example 1UnitUnit1;Interface usesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls; ConstWm_me=wm_user+ -;//custom messages; typeTForm1=class(Tform) Button1:tbutton;procedureButton1Click (sender:tobject);//The first type of message processing, only constant messages can be processed ;    procedureWmme (var message: Tmessage);messageWm_me;//custom message processing, specialized in handling Wm_me messages; private   {Private Declarations}  Public{Public Declarations}//The second type of message processing, which can handle constant or variable messages;procedureWndProc (var message: Tmessage);Override;//Reload window message procedure//The third method of message processing    procedureWmcommand (varMessage:twmcommand);messageWm_command;//command Message handling procedures    procedureWmsyscommand (varMsg:twmsyscommand);messageWm_syscommand;//processing of systematic messages; End;varForm1:tform1;Implementation{$R *.DFM} procedureTform1.button1click (sender:tobject);beginSendMessage (Handle,wm_me,0,0);//send the message wm_me, the message is first handled by WndProc, and then handed to wmme processing;End; procedureTform1.wmsyscommand (varMsg:twmsyscommand);begin  //the code below is for the user to hide the form if they click the Minimize and Close button on the title bar.   if(msg.cmdtype=sc_minimize)or(Msg.cmdtype=sc_close) Then  beginSelf.hide; End ElseDefaultHandler (MSG);//The purpose of this sentence is to continue to deal with other information;End; procedureTform1.wmcommand (varMessage:twmcommand);begin     //The third method of message processingifMessage.notifycode = bn_clicked ThenifFindControl (message.ctl) = Button1 Thenshowmessage (' Click on Button1 ');inherited;End; procedureTform1.wmme (var message: tmessage);beginShowMessage (IntToStr (Handle)+'Wmme');//The first method of message processingEnd; procedureTform1.wndproc (var message: tmessage);begin   if message. Msg=wm_me Then //The second method of message processingShowMessage (IntToStr (Handle) +'WndProc'); inheritedWndProc (Message);//here inherited will trigger a wmme message;End;End. Example 2/////////////////////////////////////////////////////////////the way messages are broadcast///////////////////////////////////////// ///////////////////////////////////////////message broadcasts can only deliver messages to the main program that receives messages, MDIChild forms cannot receive broadcast messages;/////////UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;typeTForm1=class(tform) Button1:tbutton; procedureButton1Click (Sender:tobject); procedureformcreate (sender:tobject);Private    {Private Declarations}  Public    {Public Declarations}    procedureWndProc (var message: Tmessage);Override; End;varForm1:tform1; Mymessage:dword;Implementation{$R *.DFM}{TForm1}procedureTform1.wndproc (var message: tmessage);begin if message. Msg=mymessage Then //3rd Step: Reload the Windows message processing process, processing the received mymessage message;ShowMessage (Floattostr (Handle) +'Mymessage'); inheritedWndProc (Message);End; procedureTform1.button1click (sender:tobject);beginSendMessage (Hwnd_broadcast,mymessage,0,0);//2nd step: Broadcast Mymessage news;End;/////////Pre-registration of Windows messages; The first method////////////////////proceduretform1.formcreate (sender:tobject);begin //The same string, such as ' Mymessageme ', is returned with the same mymessage result when the RegisterWindowMessage registration message is called in a different program. This provides the possibility of broadcasting messages between different programs. That is, when different programs register messages, you must register the same string of characters. Mymessage:=registerwindowmessage ('Mymessageme');//1th Step: Registering Windows messages, focusing on the value returned MymessageEnd;/////////Pre-registration of Windows messages; the second method////////////////////{initialization mymessage:=registerwindowmessage (' Mymessageme ');}  //Broadcastsystemmessage, you can broadcast messages between processes;procedureTform1.sendsmsmessage;varsmsmessage:cardinal; recipt:cardinal;begin TrySmsmessage:=registerwindowmessage ('Sendsmsmessage'); Recipt:=bsm_alldesktops;//so all desktop programs can receiveBroadcastsystemmessage (Bsf_postmessage, @recipt, Smsmessage,0,0); except End;End; End.

http://blog.csdn.net/delphi1234/article/details/2110083

Messages message uses the

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.