📄 toascii.c
字号:
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_NOTIFY;
lpTransMsg->wParam = IMN_PRIVATE;
lpTransMsg->lParam = IMN_PRIVATE_UPDATE_STATUS;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_IMN_DESTROYCAND) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_NOTIFY;
lpTransMsg->wParam = IMN_PRIVATE;
lpTransMsg->lParam = IMN_PRIVATE_DESTROYCANDWIN;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_BACKSPACE) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_CHAR;
lpTransMsg->wParam = TEXT('\b');
lpTransMsg->lParam = 0x000e;
lpTransMsg++;
}
}
if (!i) {
HIMCC hMem;
if (!uNumMsg) {
return (uNumMsg);
}
if (lpImcP->fdwImeMsg & MSG_IN_IMETOASCIIEX) {
UINT uNumMsgLimit;
uNumMsgLimit = lpTransBuf->uMsgCount;
if (uNumMsg <= uNumMsgLimit) {
lpTransMsg = lpTransBuf->TransMsg;
continue;
}
}
// we need to use message buffer
if (!lpIMC->hMsgBuf) {
lpIMC->hMsgBuf = ImmCreateIMCC(uNumMsg * sizeof(TRANSMSG));
lpIMC->dwNumMsgBuf = 0;
} else if (hMem = ImmReSizeIMCC(lpIMC->hMsgBuf,
(lpIMC->dwNumMsgBuf + uNumMsg) * sizeof(TRANSMSG))) {
if (hMem != lpIMC->hMsgBuf) {
ImmDestroyIMCC(lpIMC->hMsgBuf);
lpIMC->hMsgBuf = hMem;
}
} else {
return (0);
}
lpTransMsg= (LPTRANSMSG) ImmLockIMCC(lpIMC->hMsgBuf);
if (!lpTransMsg) {
return (0);
}
lpTransMsg += lpIMC->dwNumMsgBuf;
bLockMsgBuf = TRUE;
} else {
if (bLockMsgBuf) {
ImmUnlockIMCC(lpIMC->hMsgBuf);
}
}
}
return (uNumMsg);
}
/**********************************************************************/
/* ImeToAsciiEx() */
/* Return Value: */
/* the number of translated message */
/**********************************************************************/
UINT WINAPI ImeToAsciiEx(
UINT uVirtKey,
UINT uScanCode,
CONST LPBYTE lpbKeyState,
LPTRANSMSGLIST lpTransBuf,
UINT fuState,
HIMC hIMC)
{
WORD wCharCode;
LPINPUTCONTEXT lpIMC;
LPCOMPOSITIONSTRING lpCompStr;
LPPRIVCONTEXT lpImcP;
UINT uNumMsg;
int iRet;
wCharCode = HIWORD(uVirtKey);
uVirtKey = LOBYTE(uVirtKey);
// hIMC=NULL?
if (!hIMC) {
uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
wCharCode);
return (uNumMsg);
}
// get lpIMC
lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
if (!lpIMC) {
uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
wCharCode);
return (uNumMsg);
}
// get lpImcP
lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
if (!lpImcP) {
ImmUnlockIMC(hIMC);
uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
wCharCode);
return (uNumMsg);
}
// get lpCompStr and init
if (lpImcP->fdwGcsFlag & (GCS_RESULTREAD|GCS_RESULT)) {
lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
if (lpCompStr) {
lpCompStr->dwResultStrLen = 0;
}
ImmUnlockIMCC(lpIMC->hCompStr);
lpImcP->fdwGcsFlag = (DWORD)0;
}
// Now all composition realated information already pass to app
// a brand new start
// init lpImcP->fdwImeMsg
lpImcP->fdwImeMsg = lpImcP->fdwImeMsg & (MSG_ALREADY_OPEN|
MSG_ALREADY_START) | MSG_IN_IMETOASCIIEX;
//__asm int 3;
// Process Key(wCharCode)
iRet = ProcessKey(wCharCode, uVirtKey, uScanCode, lpbKeyState, lpIMC,
lpImcP);
// iRet process
// CST_ALPHANUMERIC
// CST_SYMBOL
// CST_SOFTKB
if (iRet == CST_SOFTKB) {
WORD wSymbolCharCode;
WORD CHIByte, CLOByte;
int SKDataIndex;
// Mapping VK
if(uVirtKey == 0x20) {
SKDataIndex = 0;
} else if(uVirtKey >= 0x30 && uVirtKey <= 0x39) {
SKDataIndex = uVirtKey - 0x30 + 1;
} else if (uVirtKey >= 0x41 && uVirtKey <= 0x5a) {
SKDataIndex = uVirtKey - 0x41 + 0x0b;
} else if (uVirtKey >= 0xba && uVirtKey <= 0xbf) {
SKDataIndex = uVirtKey - 0xba + 0x25;
} else if (uVirtKey >= 0xdb && uVirtKey <= 0xde) {
SKDataIndex = uVirtKey - 0xdb + 0x2c;
} else if (uVirtKey == 0xc0) {
SKDataIndex = 0x2b;
} else {
SKDataIndex = 0;
}
if (lpbKeyState[VK_SHIFT] & 0x80) {
wSymbolCharCode = SKLayoutS[lpImeL->dwSKWant][SKDataIndex];
} else {
wSymbolCharCode = SKLayout[lpImeL->dwSKWant][SKDataIndex];
}
if(wSymbolCharCode == 0x0020) {
MessageBeep((UINT) -1);
// __asm int 3;
uNumMsg = 0;
} else {
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
}
}
// CST_ALPHANUMERIC
else if (iRet == CST_ALPHANUMERIC) {
if (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN) {
lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg | MSG_CLOSE_CANDIDATE) &
~(MSG_OPEN_CANDIDATE) & ~(MSG_IN_IMETOASCIIEX);
GenerateMessage(hIMC, lpIMC, lpImcP);
}
if (lpIMC->fdwConversion & IME_CMODE_SYMBOL) {
WORD wSymbolCharCode;
if(wCharCode == TEXT('.')) {
wSymbolCharCode = 0x3002;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT(',')) {
wSymbolCharCode = 0xff0c;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT(';')) {
wSymbolCharCode = 0xff1b;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT(':')) {
wSymbolCharCode = 0xff1a;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('?')) {
wSymbolCharCode = 0xff1f;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('!')) {
wSymbolCharCode = 0xff01;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('(')) {
wSymbolCharCode = 0xff08;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT(')')) {
wSymbolCharCode = 0xff09;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('\\')) {
wSymbolCharCode = 0x3001;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('@')) {
wSymbolCharCode = 0x00b7;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('&')) {
wSymbolCharCode = 0x2014;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('$')) {
wSymbolCharCode = 0xffe5;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('_')) {
wSymbolCharCode = 0x2014;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, TRUE);
} else if(wCharCode == TEXT('^')) {
wSymbolCharCode = 0x2026;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, TRUE);
} else if(wCharCode == TEXT('"')) {
if(lpImcP->uSYHFlg) {
wSymbolCharCode = 0x201d;
} else {
wSymbolCharCode = 0x201c;
}
lpImcP->uSYHFlg ^= 0x00000001;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('\'')) {
if(lpImcP->uDYHFlg) {
wSymbolCharCode = 0x2019;
} else {
wSymbolCharCode = 0x2018;
}
lpImcP->uDYHFlg ^= 0x00000001;
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('<')) {
if(lpImcP->uDSMHFlg) {
wSymbolCharCode = 0x3008;
lpImcP->uDSMHCount++;
} else {
wSymbolCharCode = 0x300a;
lpImcP->uDSMHFlg = 0x00000001;
}
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else if(wCharCode == TEXT('>')) {
if((lpImcP->uDSMHFlg) && (lpImcP->uDSMHCount)) {
wSymbolCharCode = 0x3009;
lpImcP->uDSMHCount--;
} else {
wSymbolCharCode = 0x300b;
lpImcP->uDSMHFlg = 0x00000000;
}
uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
} else {
if (lpIMC->fdwConversion & IME_CMODE_FULLSHAPE) {
// convert to DBCS
uNumMsg = TranslateFullChar(lpTransBuf, wCharCode);
} else {
uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
wCharCode);
}
}
} else if (lpIMC->fdwConversion & IME_CMODE_FULLSHAPE) {
// convert to DBCS
uNumMsg = TranslateFullChar(lpTransBuf, wCharCode);
} else {
uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
wCharCode);
}
}
// CST_CHOOSE
else if (iRet == CST_CHOOSE) {
LPCANDIDATEINFO lpCandInfo;
lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
if(!lpCandInfo){
return (CST_INVALID);
}
if (uVirtKey == VK_PRIOR) {
wCharCode = TEXT('-');
} else if (uVirtKey == VK_NEXT) {
wCharCode = TEXT('=');
} else if (uVirtKey == VK_SPACE) {
wCharCode = TEXT('1');
} else if (uVirtKey >= 0 && uVirtKey <= TEXT('9')) {
// convert shift-0 ... shift-9 to 0 ... 9
wCharCode = (WORD)uVirtKey;
} else if (uVirtKey == VK_HOME) {
wCharCode = 0x24;
} else if (uVirtKey == VK_END) {
wCharCode = 0x23;
} else {
}
lpImcP->iImeState = CST_CHOOSE;
ChooseCand(wCharCode, lpIMC, lpCandInfo, lpImcP);
ImmUnlockIMCC(lpIMC->hCandInfo);
uNumMsg = TranslateImeMessage(lpTransBuf, lpIMC, lpImcP);
}
// CST_INPUT(IME_CMODE_CHARCODE)
else if (iRet == CST_INPUT &&
lpIMC->fdwConversion & IME_CMODE_CHARCODE) {
uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
wCharCode);
}
// CST_INPUT
else if (iRet == CST_INPUT) {
LPGUIDELINE lpGuideLine;
// get lpCompStr & lpGuideLine
lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
if(!lpCompStr){
return (CST_INVALID);
}
lpGuideLine = (LPGUIDELINE)ImmLockIMCC(lpIMC->hGuideLine);
if(!lpGuideLine){
ImmUnlockIMCC(lpIMC->hCompStr);
return (CST_INVALID);
}
if( lpCompStr->dwCursorPos >= 5 )
{ /////动态改变编辑框长度
int cxBorder;
cxBorder = GetSystemMetrics(SM_CXBORDER);
lpImeL->rcCompText.right = lpImeL->rcCompText.left + sImeG.xChiCharWi * ((lpCompStr->dwCursorPos + 2) / 2);
lpImeL->xCompWi=lpImeL->rcCompText.right+lpImeL->cxCompBorder*2+cxBorder*4;
}
else
{
int cxBorder;
cxBorder = GetSystemMetrics(SM_CXBORDER);
lpImeL->rcCompText.right = lpImeL->rcCompText.left + sImeG.xChiCharWi * ((6 + 2) / 2);
lpImeL->xCompWi=lpImeL->rcCompText.right+lpImeL->cxCompBorder*2+cxBorder*4;
}
lpImcP->fdwImeMsg |= MSG_IMN_COMPOSITIONPOS;
//__asm int 3;
// composition
CompWord(wCharCode, lpIMC, lpCompStr, lpImcP, lpGuideLine);
ImmUnlockIMCC(lpIMC->hGuideLine);
ImmUnlockIMCC(lpIMC->hCompStr);
// generate message
uNumMsg = TranslateImeMessage(lpTransBuf, lpIMC, lpImcP);
}
// ELSE
else if (iRet == CST_INVALID_INPUT) {
MessageBeep((UINT) -1);/////////1111111111111111
// __asm int 3;
uNumMsg = 0;
}else if( iRet == CST_SHIFT )
{
//__asm int 3;
//if( wCharCode == 0 )
//{
// DWORD fdwConversion;
// if( uCaps == 0 )
// {
// fdwConversion = (lpIMC->fdwConversion | IME_CMODE_NATIVE)&
// ~(IME_CMODE_CHARCODE | IME_CMODE_EUDC);
// uCaps = 1;
// } else {
// // change to native mode
// fdwConversion = lpIMC->fdwConversion & ~(IME_CMODE_CHARCODE |
// IME_CMODE_NATIVE | IME_CMODE_EUDC);
// uCaps = 0;
// }
// ImmSetConversionStatus(hIMC, fdwConversion, lpIMC->fdwSentence);
//}
}else
{
uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
wCharCode);
}
// reset lpImcP->fdwImeMsg
lpImcP->fdwImeMsg &= (MSG_ALREADY_OPEN|MSG_ALREADY_START);
lpImcP->fdwGcsFlag &= (GCS_RESULTREAD|GCS_RESULT);
ImmUnlockIMCC(lpIMC->hPrivate);
ImmUnlockIMC(hIMC);
return (uNumMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -