Win32 messages intercepted in winfrom

Source: Internet
Author: User

In the unmanaged world, it was quite common to intercept Win32 messages as they were plucked off the message queue. in that rare case in which you wish to do so from a managed Windows Forms Application, your first step is to build a helper class which implements the imessagefilter interface. the sole method, prefiltermessage (), allows you to get at the underlying message id, as well as the raw wparam and lparam data. by way of a simple example:

 
Public class mymessagefilter: imessagefilter {public bool prefiltermessage (ref message m) {// intercept the left mouse button down message. if (M. MSG = 513) {MessageBox. show ("wm_lbuttondown is:" + M. MSG); Return true;} return false ;}}

At this point you must register your helper class with the application type:

Public class mainform: system. windows. forms. FORM {private mymessagefilter msgfliter = new mymessagefilter (); Public mainform () {// register message filter. application. addmessagefilter (msgfliter );}...}

At this point, your custom filter will be automatically consulted before the message makes its way to the registered event hander. removing the filter can be accomplished using the (aptly named) static application. removemessagefilter () method.

 

Related Article

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.