Enable HGE to support Chinese (2)-HGE Chinese Input

Source: Internet
Author: User

 

Crazy and depressing ing...

I did not see any text when I wrote something yesterday...

It's a waste of time.

I have to do it again today... how does this CSDN work?

Forget it. Let's talk about how it works, typing tired...

Because the method I mentioned is to directly change the HGE kernel ..

So there are not many changes, but not a few lines of code ..

Steps:

1: Add a structure to hge. h to save our input data.

Struct hgeIMEEvent
{
Bool isIME;
Char value [3];
};

2: add an interface for retrieving input data in hge. h:

Virtual bool CALL Input_GetIMEEvent (hgeIMEEvent * ime) = 0;

3: Next we need a table to store the input data. We use the general HGE style and add the structure in hge_impl.h:

Struct CIMEEventList
{
HgeIMEEvent ime;
CIMEEventList * next;
};

4: complete the interface declaration. Add the interface in hge_impl.h:

Virtual bool CALL Input_GetIMEEvent (hgeIMEEvent * ime );

5: the data source and processing are added to hge_impl.h. All the real-time input data will be stored here for processing, but you will not be notified.

CIMEEventList * imeEvent;
Void _ BulidIMEEvent (char key [3], bool isIME );
Void _ ClearIMEEvent ();

6: complete the function bodies of the preceding interfaces. Add them to input. cpp.

(Welcome to repost: Original Author's BLOG (ShowLong ))

Void HGE_Impl: _ BulidIMEEvent (char key [3], bool isIME)
{
CIMEEventList * newEvent = new CIMEEventList; newEvent-> next = 0;
NewEvent-> ime. isIME = isIME;
If (isIME)
{
NewEvent-> ime. value [0] = key [0];
NewEvent-> ime. value [1] = key [1];
NewEvent-> ime. value [2] = '/0 ';
}
Else
{
NewEvent-> ime. value [0] = key [0];
NewEvent-> ime. value [1] = '/0 ';
NewEvent-> ime. value [2] = '/0 ';
} If (! ImeEvent)
ImeEvent = newEvent;
Else
{
CIMEEventList * last = imeEvent;
While (last-> next)
Last = last-> next;
Last-> next = newEvent;
}
} Bool HGE_Impl: Input_GetIMEEvent (hgeIMEEvent * ime)
{
CIMEEventList * eptr; if (imeEvent)
{
Eptr = imeEvent;
Memcpy (ime, & eptr-> ime, sizeof (hgeIMEEvent ));
ImeEvent = eptr-> next;
Delete eptr;
Return true;
} Return false;
} Void HGE_Impl: _ ClearIMEEvent ()
{
CIMEEventList * next, * ptr = imeEvent; while (ptr)
{
Next = ptr-> next;
Delete ptr;
Ptr = next;
}
ImeEvent = 0;
}

7: Find all the call _ ClearQueue (); and add the code below it:

_ ClearIMEEvent ();

8: In system. cpp, find the System_Start function body. The code to be replaced is started. below:

TranslateMessage (& msg );

9: do not forget to write the following sentence when constructing hge_impl:

ImeEvent = 0;

10: This is the key. With the above code, you can get the input.

Insert the code before the next case of case WM_SETCURSOR: in the main WindowProc function body:

Case WM_IME_CHAR:
{
Char imeChar [3];
ImeChar [0] = (char) (wparam> 8 );
ImeChar [1] = (char) wparam;
ImeChar [2] = '/0 ';
PHGE-> _ BulidIMEEvent (imeChar, true );
}
Break;
Case WM_CHAR:
{
If (wparam = VK_BACK |
Wparam = VK_TAB |
Wparam = VK_RETURN |
(Char) wparam <= 0)
Break; char imeChar [3];
ImeChar [0] = (char) wparam;
ImeChar [1] = '/0 ';
ImeChar [2] = '/0 ';
PHGE-> _ BulidIMEEvent (imeChar, false );
}
Break;

Now, all the code is added...

If you want to create a GUI to call it, try it.

Only three codes are required.

HgeIMEEvent imeEvent;
While (tKernelServer: Instance ()-> Device ()-> Input_GetIMEEvent (& imeEvent ))
{
AddChar (imeEvent. value, imeEvent. isIME );
}

It's easy enough. As for why imeEvent should be defined like this... I will not explain it here... if you don't think you need to change it.

If you have any questions, you have to ask me QQ: 29774874.

Or add it to my group: 32800303

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.