调用API的WPF应用程序,需要一个消息泵 [英] WPF application which calls an API, which needs a message pump

查看:169
本文介绍了调用API的WPF应用程序,需要一个消息泵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,该应用程序调用API来操作设备(扫描仪).该API基于COM,并且在内部具有一个隐藏的窗口,扫描程序也可以发送消息. API的目的是将这些Windows消息转换为COM事件.问题在于WPF应用程序没有消息泵,因此没有任何消息被传递到隐藏窗口.因此,没有任何事件被触发,并且扫描仪似乎没有响应.

I have a WPF application that calls an API to operate a device (a scanner). This API is COM based, and internally has a hidden window that the scanner sends messsages too. The intent of the API is to turn those windows messages into COM events. The problem is that the WPF application doesn't have a message pump, and therefore none of the messages are being delivered to the hidden window. Therefore none of the events are fired and it looks like the scanner is not responding.

我应该如何在WPF应用程序中创建一个消息循环,以便将消息分派到不可见的窗口?

How should I create a message loop in the WPF application that will be able to dispatch messages to the invisible window?

推荐答案

如果您还没有此方法,则该方法可以启动消息泵:

This method can start a message pump if you don't have one already: http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.run.aspx

请注意,每个线程拥有一个单独的消息泵,该泵为该线程创建的所有窗口泵送消息.您需要找到创建隐藏窗口的线程.

Note that each thread owns a separate message pump, which pumps messages for all windows created by that thread. You need to find the thread that created the hidden window.

这篇关于调用API的WPF应用程序,需要一个消息泵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆