谷歌浏览器的源码分析 7

 

当我们键入字母或者文字开始时,那么类AutocompleteEdit就会从窗口消息里获取到相应的字母或者文字,然后根据输入的信息到本地或者网络上保存的信息库里查找相应的输入提示,这就是自动完成的实现。下面就来先分析输入的函数:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

#001  void AutocompleteEdit::OnChar(TCHAR ch, UINT repeat_count, UINT flags) {

#002    // Don't let alt-enter beep.  Not sure this is necessary, as the standard

#003    // alt-enter will hit DiscardWMSysChar() and get thrown away, and

#004    // ctrl-alt-enter doesn't seem to reach here for some reason?  At least not on

#005    // my system... still, this is harmless and maybe necessary in other locales.

 

 

下面把alt-enter组合键消息过滤掉。

#006    if (ch == VK_RETURN && (flags & KF_ALTDOWN))

#007      return;

#008 

#009    // Escape is processed in OnKeyDown.  Don't let any WM_CHAR messages propagate

#010    // as we don't want the RichEdit to do anything funky.

 

 

下面把ESC键的消息过滤掉。

#011    if (ch == VK_ESCAPE && !(flags & KF_ALTDOWN))

#012      return;

#013 

 

 

下面把TAB键的消息过滤掉。

#014    if (ch == VK_TAB) {

#015      // Don't add tabs to the input.

#016      return;

#017    }

#018 

 

 

这里处理其它有用的按键消息。

#019    HandleKeystroke(GetCurrentMessage()->message, ch, repeat_count, flags);

#020  }

 

 

AutocompleteEdit::OnChar函数是WTL里的WM_CHAR消息处理,当用户键入字母时就会触发这个消息。这个函数先跳过几个不要处理的消息,最后调用函数HandleKeystroke来处理,如下:

#001  void AutocompleteEdit::HandleKeystroke(UINT message, TCHAR key,

#002                                         UINT repeat_count, UINT flags) {

 

 

冻结RichEdit的更新。

#003    ScopedFreeze freeze(this, GetTextObjectModel());

 

 

处理消息变化前的动作。

#004    OnBeforePossibleChange();

 

 

处理消息

#005    DefWindowProc(message, key, MAKELPARAM(repeat_count, flags));

 

 

处理消息变化后的动作。

#006    OnAfterPossibleChange();

#007  }

 

 

在这里为什么要进行窗口的消息冻结呢?又为什么需要进行消息处理和消息变化后处理呢?下一次再告诉你。

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自www.cnblogs.com/skiwnchh/p/10346949.html
今日推荐