Windows messages in WPF

Source: Internet
Author: User

1. Windows API hook

WPF forms do not have handle in winform. Therefore, you cannot directly use settings or remove hooks when using APIs. To use setwindowshookex, unhookwindowshookex, and callnexthookex of the API, You can first use javaswinterophelper to get handle.

2. WPF hwndsource

The hwndsource provided by WPF allows you to process Windows messages more quickly. The hwndsource obtained through hwndsource. fromvisual can be used to add (addhook) Remove (remove) Hook. Hwndsource has some limitations. If your WPF application contains the winform control, you may be somewhat disappointed. This method cannot receive such messages.

3. componentdispatcher

In the interoperability solution, the message pump sharing control between Win32 and WPF is enabled, and events such as threadfiltermessage of componentdispatcher can be used to better process Windows messages. This method can avoid hwndsource defects.

Summary: WPF also supports multiple methods to process Windows messages, but each method has its own characteristics: the API method has the strongest function to achieve system-level message processing, followed by componentdispatcher and hwndsource is relatively weak.

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.