OS/2 codes: How to support DBCS #3 Process WM_CHAR

On PM, users' key inputs are delivered with WM_CHAR message. First see a syntax of WM_CHAR.

This message is sent when an operator presses a key.

param1
     USHORT  fsflags     /*  Keyboard control codes. */
     UCHAR   ucrepeat    /*  Repeat count. */
     UCHAR   ucscancode  /*  Hardware scan code. */

param2
     USHORT  usch        /*  Character code. */
     USHORT  usvk        /*  Virtual key codes. */

Here, the relavant things are [fsflags](=SHORT1FROMMP(mp1)), [ucscancode](=CHAR4FROMMP(mp1)) and [usch](=SHORT1FROMMP(mp2)).

A DBCS character consists of two bytes. So do not assume that [usch] is a single-byte. Then what is the way to distinguish a SBCS character and a DBCS character ? Check a high-byte of [usch]. If it is 0, then a SBCS character, or a DBCS character. If it is a DBCS character, its low-byte is a lead-byte and its high-byte is a trail-byte. You can access these bytes of [usch] with several ways. First is to use [usch] itself. In this case, use LOBYTE() for a lead-byte and HIBYTE() for a trail-byte. Second is to use [mp2] directly. In this case, CHAR1FROMMP(mp2) for a lead-byte, CHAR2FROMMP(mp2) for a trail-byte.

Here is a simple code snippet.

1
2
3
szBuf[ current++ ] = CHAR1FROMMP( mp2 );
if( CHAR2FROMMP( mp2 ))
    szBuf[ current++ ] = CHAR2FROMMP( mp2 );


[szBuf] is an array of char to contain user's inputs. [current] is an index to insert a character to [szBuf].

Just check a high byte of [usch] when [fsflags] has KC_CHAR flag. And if it has some value, then add it, too. That's all. What a simple !!!.

Finally, if [usch] is a DBCS character, [ucscancode] may be 0. So, do not ignore WM_CHAR message even if [ucscancode] is 0.






댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷