谷歌浏览器的源码分析(7)

 

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

#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  }

 

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

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

caimouse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值