wxWidgets的EVT_CHAR_HOOK是什么? [英] What does wxWidgets' EVT_CHAR_HOOK do?

查看:546
本文介绍了wxWidgets的EVT_CHAR_HOOK是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在维护一个使用EVT_CHAR_HOOK捕获高级窗口中的关键事件的wxWidgets C ++应用程序。我找不到任何真正的文档,这个事件,但我可以推测,它截取的关键事件以某种方式优先于标准关键事件。我刚刚发现的一个令人不安的事情是,如果这个钩子到位,任何可能已定义的加速键不会再触发他们的事件,即使事件处理程序调用事件上的Skip()。我在google上搜索时也看到一些帖子,似乎暗示EVT_CHAR_HOOK可能不是在所有平台上都支持。这是真的,我应该使用它吗?

I am maintaining a wxWidgets C++ application that uses EVT_CHAR_HOOK to capture key events in a high level window. I can't find any real documentation for this event but I can surmise that it intercepts key events in some way that has priority over the "standard" key events. One disturbing thing that I just discovered is that, if this hook is in place, any accelerator keys that might have been defined will no longer fire their events even if the event handler calls Skip() on the event. I've also seen some posts when searching on google that seemed to suggest that EVT_CHAR_HOOK may not be supported on all platforms. Is this true and should I be using it?

推荐答案

我只是看看 src / gtk / window .cpp 并找到这一块:

I just looked into src/gtk/window.cpp and found this piece:

        // Implement OnCharHook by checking ancestor top level windows
        wxWindow *parent = win;
        while (parent && !parent->IsTopLevel())
            parent = parent->GetParent();
        if (parent)
        {
            event.SetEventType( wxEVT_CHAR_HOOK );
            ret = parent->HandleWindowEvent( event );
        }

        if (!ret)
        {
            event.SetEventType(wxEVT_CHAR);
            ret = win->HandleWindowEvent( event );
        }

因此,也许你只需要返回 false OnCharHook 事件处理程序

So, maybe you just need to return false from your OnCharHook event handler?

根据wx之一邮件列表post:

In accordance to one of wx Mailing list post:


如果您希望框架捕获所有char事件,请使用EVT_CHAR_HOOK,否则事件将发送给子级。如果你想捕获像escape这样的东西,你需要在帧上设置wxWANTS_CHARS标志。此外,确保你调用event.Skip()对你不处理的字符。

If you want the frame to catch all char events, use EVT_CHAR_HOOK, otherwise the events get sent to the children. If you want to catch stuff like escape, you need to set wxWANTS_CHARS flag on the frame. Also, make sure you call event.Skip() on chars you don't process.

但另一篇帖子声明:


...不要使用EVT_CHAR_HOOK(),它是一个黑客。此外,它是一个Windows特定的黑客和
我个人根本不感兴趣,使其正常工作。如果有什么,
我想弃用它,并彻底摆脱它。 VZ。

...don't use EVT_CHAR_HOOK(), it is a hack. Moreover, it is a Windows-specific hack and I'm personally not at all interested in getting it to work right. If anything, I'd like to deprecate it and get rid of it completely. VZ.

此信息可能对您感兴趣

这篇关于wxWidgets的EVT_CHAR_HOOK是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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