Implementation of a simple T9 input method (with code)

Source: Internet
Author: User

Article Difficulty: Beginners

About T9 Input method of the core program (provided by my friend Nix), a total of two documents, one is NixInputMethod.h, there is a t9.c; See appendix.

The implementation of the specific input method is as follows:

1. First create a dialog box, and then put two controls in it: Idc_edit1 and Idc_word (static control)

2. In order to achieve the input in the edit, the static will appear in the intelligent function, so our implementation is as follows:

A The overloaded function PreTranslateMessage enables it to capture all the events of the keyboard, so it is implemented as follows:

BOOL Cmy11dlg::P retranslatemessage (msg* pMsg)

{

try {

cwnd* Pctrl = GetFocus ();

/*

* Can be built by enter the cursor focus of the switch

*/

if (pmsg->message = = Wm_keydown && getasynckeystate (vk_tab))

{

Get the char index of the caret position

int NPOs = LoWord (M_myeditctl.charfrompos (M_myeditctl.getcaretpos ()));

Select Zero chars

M_myeditctl.setsel (NPOs, NPOs);

Then replace that selection with a TAB

M_myeditctl.replacesel ("/t", TRUE);

No need to does a msg translation, so quit.

That's way no further processing gets done

return TRUE;

} else

if (Getasynckeystate (Vk_return))//Enter

{

Switch (Pctrl->getdlgctrlid ()) {

Case IDOK:

if (!reset) {

AfxMessageBox ("OK");

reset = 1;

} else {

reset = 0;

GetDlgItem (idc_static)->setfocus ();

}

Break

Default

Pmsg->wparam = Vk_tab;

}

} else

/*

* Through 1, 2, 3 ... Select the first few words

*/

if (pmsg->message = = Wm_keydown && (isdigit (pmsg->wparam) | | (Pmsg->wparam >64 && Pmsg->wparam < 91))) {

CString str;

if (IsDigit (Pmsg->wparam)) {

GetDlgItem (Idc_word)->getwindowtext (str);

char* temp = str. GetBuffer (100);

Char zi[3];

                                                 zi[0] = temp[

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.