當我們鍵入字母或者文字開始時,那么類
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
?
}
在這里為什么要進行窗口的消息凍結呢?又為什么需要進行消息處理和消息變化后處理呢?下一次再告訴你。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
