OnKeyDown并与托管代码集成 [英] OnKeyDown and integration with managed code

查看:61
本文介绍了OnKeyDown并与托管代码集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个遗留的MFC应用程序,它有很多编辑器功能

与扩展CFrameWnd的类相关联。此编辑器通过使用消息映射中的OnKeyDown处理程序来监视关键事件
down事件。在我的遗产

MFC应用程序中,我的OnKeyDown处理程序总是被调用,正如我所料。


我正在调用遗留应用程序的编辑器窗口来自C#

应用程序。我编写了一个小的C ++ / CLI应用程序,它连接了

托管代码,并为via via p / invoke公开了一个C#友好方法。

这允许我的编辑器显示和(通常)工作,我希望。


问题是基于CFrameWnd的对话框中的OnKeyDown处理程序确实没有
从我的托管代码调用窗口时调用。当我使用A或1这样的简单键时,会调用
但是如果我按下Esc

键,我的处理程序就不会被调用。


当按下

Esc键时,任何人都可以提供任何线索,说明为什么我的处理程序没有被调用?我使用Spy ++来查看发送到

基于CFrameWnd的对话框的消息,它正在接收带有

VK_ESCAPE虚拟键的WM_KEYDOWN消息。此外,如果它很重要,在我的遗留应用程序中,启动基于CFrameWnd的对话框的窗口是无模式的,而在我的

C#应用程序中,窗口从基于CFrameWnd的对话框启动

是模态的。


谢谢!

Notre

Hello,

I have a legacy MFC application that has a lot of editor functionality
associated with a class that extends CFrameWnd. This editor watches for key
down events by using the OnKeyDown handler in the message map. In my legacy
MFC application, my OnKeyDown handler is always called, as I would expect.

I''m calling the legacy application''s editor window from within a C#
application. I''ve written a little C++/CLI application that bridges the
managed code, and exposes a C# friendly method for via explicit p/invoke.
This allows my editor to show up and (generally) work as I''d hope.

The problem is that the OnKeyDown handler in the CFrameWnd based dialog does
not always get called when the window is invoked from my managed code. It
gets called when I use simple keys like ''A'' or ''1'' but if I press the Esc
key, my handler is not called.

Can anyone give any clues as to why my handler is not being called when the
Esc key is pressed? I used Spy++ to look at the messages being sent to the
CFrameWnd based dialog and it is receiving the WM_KEYDOWN message with the
VK_ESCAPE virtual key. Also, in case it matters, in my legacy application,
the window that launches the CFrameWnd based dialog is modeless, while in my
C# application, the window from which the CFrameWnd based dialog is launched
is modal.

Thanks!
Notre

推荐答案



" Notre Poubelle" < no ************ @ online.nospamwrote in message

新闻:EF ****************** **************** @ microsof t.com ...

"Notre Poubelle" <no************@online.nospamwrote in message
news:EF**********************************@microsof t.com...

您好,


我有一个遗留的MFC应用程序,它有很多编辑器功能

与扩展CFrameWnd的类相关联。这个编辑器通过在消息映射中使用OnKeyDown处理程序来监视

key

down事件。在我的

遗产

MFC应用程序中,我的OnKeyDown处理程序总是被调用,正如我所料。


我是从C#

应用程序中调用遗留应用程序的编辑器窗口。我编写了一个小的C ++ / CLI应用程序,它连接了

托管代码,并为via via p / invoke公开了一个C#友好方法。

这允许我的编辑器显示和(通常)工作,我希望。


问题是基于CFrameWnd的对话框中的OnKeyDown处理程序

确实。当我使用A或1这样的简单键时,会调用
但是如果我按下Esc

键,我的处理程序就不会被调用。


任何人都可以提供任何线索,说明为什么我的处理程序没有被调用



按Esc键?我使用Spy ++来查看发送到

基于CFrameWnd的对话框的消息,它正在接收带有

VK_ESCAPE虚拟的WM_KEYDOWN消息键。另外,如果重要的话,在我的遗产

应用程序中,

启动基于CFrameWnd的对话框的窗口是无模式的,而在

我的

C#应用程序,基于CFrameWnd的对话框的窗口是

已启动

是模态的。
Hello,

I have a legacy MFC application that has a lot of editor functionality
associated with a class that extends CFrameWnd. This editor watches for
key
down events by using the OnKeyDown handler in the message map. In my
legacy
MFC application, my OnKeyDown handler is always called, as I would expect.

I''m calling the legacy application''s editor window from within a C#
application. I''ve written a little C++/CLI application that bridges the
managed code, and exposes a C# friendly method for via explicit p/invoke.
This allows my editor to show up and (generally) work as I''d hope.

The problem is that the OnKeyDown handler in the CFrameWnd based dialog
does
not always get called when the window is invoked from my managed code. It
gets called when I use simple keys like ''A'' or ''1'' but if I press the Esc
key, my handler is not called.

Can anyone give any clues as to why my handler is not being called when
the
Esc key is pressed? I used Spy++ to look at the messages being sent to
the
CFrameWnd based dialog and it is receiving the WM_KEYDOWN message with the
VK_ESCAPE virtual key. Also, in case it matters, in my legacy
application,
the window that launches the CFrameWnd based dialog is modeless, while in
my
C# application, the window from which the CFrameWnd based dialog is
launched
is modal.



.NET本地消息调度循环,用于模态窗口,可能调用

IsDialogMessage然后不通过它发送消息你的窗口

程序。尝试使用Application.AddMessageFilter进行解决方法(捕获

WM_KEYDOWN,调用TranslateMessage + DispatchMessage,然后终止

消息,让所有其他消息默认处理)。

The .NET local message dispatch loop, used for modal windows, probably calls
IsDialogMessage and then doesn''t dispatch the message through your window
procedure. Try Application.AddMessageFilter for a workaround (catch
WM_KEYDOWN, call TranslateMessage+DispatchMessage, and then kill the
message, let all other messages be default processed).


>

谢谢!

Notre
>
Thanks!
Notre



你好Notre,


是的,就像Ben指出的那样,.Net Winform封装了GUI消息

循环在.Net BCL代码。另外,为了支持

..Net Winform中的一些特殊键功能,.Net Winform代码的WndProc可以在发送到你的消息之前对消息实施某种类型的
预处理。 OnKeyDown处理程序。

您可以使用Reflector查看源代码

System.Windows.Forms.Application.ThreadContext.Pre TranslateMessage方法

看看预处理。


所以我怀疑.Net Winform预处理代码可以识别ESC键

作为特殊键并且没有发送正确地使用MFC处理程序。


您是否有可能创建一个小样本C ++ / CLI MFC项目来支持
帮我重现这个问题?一旦我可以给它本地重现,我将会对它进行一些调试并给你一些建议。


谢谢。


祝你好运,

Jeffrey Tan

Microsoft在线社区支持

========== ========================================

获取通知通过电子邮件到我的帖子?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========

此帖子按原样提供。没有保证,也没有授予任何权利。
Hi Notre,

Yes, just as Ben pointed out, .Net Winform encapsulates the GUI message
loop in the .Net BCL code. Also, to support some special key function in
..Net Winform, the WndProc of .Net Winform code may implement some type of
preprocessing to the message before dispatching to your OnKeyDown handler.
You may use Reflector to view the source code of
System.Windows.Forms.Application.ThreadContext.Pre TranslateMessage method
to get a glance of the preprocessing.

So I suspect the .Net Winform preprocessing code may identify the ESC key
as a special key and did not dispatch to the MFC handler correctly.

Is it possible for you to create a little sample C++/CLI MFC project to
help me reproduce this problem? Once I can give it a local reproduce, I
will perform some debugging over it and provide some suggestion to you.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


感谢Ben&杰弗里对你的快速反应!


我不确定我是否正确地说明了这个问题,或者我可能只是没有

了解响应。


扩展CFrameWnd的编辑器是按下Esc键时无法识别

OnKeyDown处理程序的编辑器。这个编辑器本身就是一个

无模式窗口。我的

托管应用程序和我的旧MFC应用程序之间的''父级'窗口是不同的。在我管理的

应用程序中,这个父窗口是模态的。在我的遗留应用程序中,这个

父窗口是无模式的。


你们认为你的评论仍然适用,或者如果
编辑器窗口本身(扩展CFrameWnd的窗口)已经从

无模式更改为模态窗口?


再次感谢!!!

Notre
Thank you both Ben & Jeffrey for your prompt responses!

I''m not sure if I''m stating the problem correctly, or maybe I just do not
understand the responses.

The editor that extends CFrameWnd is the one that is not recognizing the
OnKeyDown handler when the Esc key is pressed. This editor is itself a
modeless window. It is the ''parent'' window that is different between my
managed application and my legacy MFC application. In my managed
application, this parent window is modal. In my legacy application, this
parent window is modeless.

Do you guys think that your comments still apply, or are they more if the
editor window itself (the one that extends CFrameWnd) had changed from a
modeless to a modal window?

Thanks again!!!
Notre


这篇关于OnKeyDown并与托管代码集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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