Learning message (4): responds to messages through application. onmessage or tapplicationevents

Source: Internet
Author: User
Use application. onmessage to respond to a message:
 
Unit unit1; interfaceuses windows, messages, extensions, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) memo1: tmemo; Procedure formcreate (Sender: tobject); {This custom process must be integrated with the application. onmessage parameter format} procedure mymessage (var msg: tagmsg; var handled: Boolean); end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.formcreate (Sender: tobject); begin memo1.clear; application. onmessage: = mymessage; {make application. onmessage execution custom process} end; {response to all messages other than wm_mousemove} procedure tform1.mymessage (var msg: tagmsg; var handled: Boolean); begin if MSG. message wm_mousemove then memo1.lines. add ('$' + inttohex (MSG. message, 4); end.

  

To respond to a message through tapplicationevents, you must add the tapplicationevents component during design and add onmessage events to it:

 unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, appevets; type tform1 = Class (tform) memo1: tmemo; applicationevents1: tapplicationevents; Procedure formcreate (Sender: tobject); Procedure applicationevents1message (var msg: tagmsg; var handled: Boolean); end; vaR form1: tform1; implementation {$ R *. DFM} procedure tform1.formcreate (Sender: tobject); begin memo1.clear; end; {response to all messages other than wm_mousemove} procedure tform1.applicationevents1message (var msg: tagmsg; var handled: Boolean ); begin if MSG. message wm_mousemove then memo1.lines. add ('$' + inttohex (MSG. message, 4); 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.