C # Implementation of the blank form on the Chinese input, you can implement the type of PS Text tool

Source: Internet
Author: User

Open the Input method on the blank form, the blank window in C # is not open the input method anyway. This is set. Imemode= Imemode.nocontrol is also unable to open the input method of the Recording Word window. I asked some questions at the Microsoft Development Forum. Thank you for the week Xuefeng moderator and Riquel_dong moderator to give guidance. API function: Immassociatecontext (IntPtr hWnd, IntPtr HIMC); Finally, the input method is tuned out, its function is to associate the input with the specified window.

The code is as follows:

f (m.Msg == WM_IME_SETCONTEXT && m.WParam.ToInt32() == 1)
{
ImmAssociateContext(this.Handle, m_hImc);
}

You can now invoke the IME. But there are new problems. How do I get the words on the input word form?

When you open an Input method to enter text, a WM_IME_CHAR message is sent. We'll get the Chinese characters under the news.

You can use the IMM function: immgetcompositionstring (IntPtr himc, int dwindex, StringBuilder lpbuf, int dwbuflen); get the kanji or Nuicode class entered on the record form The word. Of course, there's nothing else to look at here. Only the Chinese character problem.

The code to take the word is as follows:

case WM_IME_CHAR:

int size = ImmGetCompositionString(m_hImc, GCS_COMPSTR, null, 0);
size +=  sizeof(Char);
ImmGetCompositionString(m_hImc, GCS_RESULTSTR, str, size);
sb.Append(str.ToString());
MessageBox.Show (str.ToString());
intoText();//打印文字
isShowChina =  true;


break;

OK, it looks like it's done. Test to find out that the printed is a duplicate of the text. For example, the input "serve the people", printed out is "for the public service services" My God, what's the problem?

Check out MSDN. There is a description of the Wm_ime_char:

The Wm_ime_char message includes a double-byte character and the application passes this message to DefWindowProc

Is this the problem? is to send a message two times.

Read an online discussion and come up with a solution: plus judgment

if  (m.WParam.ToInt32() == PM_REMOVE)
{
}

Test. Finally, there's no more questions.

Related Article

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.