Imm.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:8k
- #include "stdafx.h"
- #include "stdio.h"
- #include "imm.h"
- #include "jsIME.h"
- #include "DllManager.h"
- #include "resource.h"
- #include "stdio.h"
- HINSTANCE hInst;
- HWND ActiveHwnd; //提示窗口
- extern DllManager DllMns;
- extern HWND outMainhWnd;
- extern HWND hSoftKbdWnd;
- extern int myFullErr;
- LPDWORD lpdwCurTransKey = NULL;
- HIMC savehIMC=NULL;
- int intinat=0;
- BOOL IMESenChiApp(HIMC hIMC, char *ss);
- BOOL GenerateMessage(HIMC hIMC, LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg);
- //如果出现LPIMEINFO等没有定义,可能是系统使用自带的Imm.h
- // LPTSTR lpszWndClass, //当前输入法的名称
- BOOL WINAPI ImeInquire(LPIMEINFO lpIMEInfo,LPTSTR lpszUIClass,LPCTSTR lpszOption)
- {
- if (!lpIMEInfo) {
- return (FALSE);
- }
- lpIMEInfo->dwPrivateDataSize = sizeof(PRIVCONTEXT);
- lpIMEInfo->fdwProperty = IME_PROP_KBD_CHAR_FIRST|IME_PROP_IGNORE_UPKEYS;
- lpIMEInfo->fdwConversionCaps = IME_CMODE_NATIVE|IME_CMODE_FULLSHAPE|
- IME_CMODE_CHARCODE|IME_CMODE_SOFTKBD|IME_CMODE_NOCONVERSION;
- lpIMEInfo->fdwSentenceCaps = 0;
- // IME will have different distance base multiple of 900 escapement
- lpIMEInfo->fdwUICaps = UI_CAP_ROT90|UI_CAP_SOFTKBD;
- // composition string is the reading string for simple IME
- lpIMEInfo->fdwSCSCaps = SCS_CAP_COMPSTR|SCS_CAP_MAKEREAD;
- // IME want to decide conversion mode on ImeSelect
- lpIMEInfo->fdwSelectCaps = (DWORD)NULL;
- _tcscpy(lpszUIClass,UICLASSNAME);
- return TRUE;
- }
- BOOL WINAPI ImeConfigure(HKL hKL,HWND hWnd, DWORD dwMode, LPVOID lpData)
- {
- MessageBox (0,"极速五笔无需进行输入法配置!!","极速五笔输入法配置对话框",0);
- return TRUE;
- }
- DWORD WINAPI ImeConversionList(HIMC hIMC,LPCTSTR lpSource,LPCANDIDATELIST lpCandList,DWORD dwBufLen,UINT uFlag)
- {
- return 0;
- }
- BOOL WINAPI ImeDestroy(UINT uForce)
- {
- //MessageBox (0,"ImeDestroy",0,0);
- //DllMns.mgCloseWin();
- return FALSE;
- }
- LRESULT WINAPI ImeEscape(HIMC hIMC,UINT uSubFunc,LPVOID lpData)
- {
- return FALSE;
- }
- //键盘过滤,0为不过滤
- BOOL WINAPI ImeProcessKey(HIMC hIMC,UINT vKey,LPARAM lKeyData,CONST LPBYTE lpbKeyState)
- {
- BOOL ret=0;
- ret=DllMns.myImeProcessKey(&DllMns.hmainWin,DllMns.SendCH,DllMns.Control,hIMC,vKey,lKeyData, lpbKeyState);
-
- //MessageBox (0,"dddd",DllMns.SendCH,0);
- return ret;
- }
- //当本输入法被选中或被撤消时调用.
- BOOL WINAPI ImeSelect(HIMC hIMC, BOOL fSelect)
- {
- LPINPUTCONTEXT lpIMC;
- // it's NULL context.
- if (!hIMC)
- return TRUE;
- if (!(lpIMC = ImmLockIMC(hIMC)))//锁存数据
- return 1;
- savehIMC=hIMC;
- ImmUnlockIMC(hIMC);
- {
- char ss[100];
- sprintf(ss,"%d",lpIMC->hWnd);
- //MessageBox(0,ss,"ImeSelect",0);
- }
- return 0;
- }
- BOOL WINAPI ImeSetActiveContext(HIMC hIMC,BOOL fFlag)
- {
- return TRUE;
- }
- UINT WINAPI ImeToAsciiEx (UINT uVKey,UINT uScanCode,CONST LPBYTE lpbKeyState,
- LPDWORD lpdwTransKey,UINT fuState,HIMC hIMC)
- {
- //把转换后的汉字发到接收程序中使用内部机制.
- // char ss[100];
- //MessageBox (0,"dddd",DllMns.SendCH,0);
- try{
- if (uScanCode & 0x8000)
- return 0;
- else
- {
- if (strlen(DllMns.SendCH)){
- lpdwCurTransKey = lpdwTransKey;
- if(strcmp(DllMns.Control,"move")==0)
- keybd_event(VK_LEFT, 0,0,0);
- lpdwCurTransKey=lpdwTransKey;
- IMESenChiApp( hIMC,DllMns.SendCH);
- DllMns.SendCH[0]=0;
- }
- }
- } catch (...) {
- MessageBox(0,"ImeToAsciiEx","有错误发生",0);
- }
- return 0;
- }
- BOOL WINAPI NotifyIME(HIMC hIMC,DWORD dwAction,DWORD dwIndex,DWORD dwValue)
- {
- BOOL bRet = FALSE;
- // char ss[100];
- try {
- switch(dwAction)
- {
- case NI_CONTEXTUPDATED:
- switch (dwValue)
- {
- case IMC_SETOPENSTATUS:
- ///////////////////////////////////////////////////
- // it's NULL context.
- DllMns.mgUpDateaWin(hIMC);
- bRet = TRUE;
- break;
- case IMC_SETCOMPOSITIONFONT:
- //if(dwValue!=12)
- //{
- //sprintf(ss,"%d",dwValue);
- //MessageBox(0,ss,0,0);
- //}
- //DllMns.mgSetShowString("","");
- //DllMns.mgHideWin();
- bRet = TRUE;
- break;
- default:
- break;
- }
- break;
- case NI_COMPOSITIONSTR:
- DllMns.mgSetShowString("","");
- DllMns.mgHideWin();
- bRet = TRUE;
- break;
- }
- } catch (...) {
- MessageBox(0,"ImeToAsciiEx","有错误发生",0);
- }
- return bRet;
- }
- BOOL WINAPI ImeRegisterWord(LPCTSTR lpRead, DWORD dw, LPCTSTR lpStr)
- {
- return FALSE;
- }
- BOOL WINAPI ImeUnregisterWord(LPCTSTR lpRead, DWORD dw, LPCTSTR lpStr)
- {
- return FALSE;
- }
- UINT WINAPI ImeGetRegisterWordStyle(UINT nItem, LPSTYLEBUF lp)
- {
- return 0;
- }
- UINT WINAPI ImeEnumRegisterWord(REGISTERWORDENUMPROC lpfn, LPCTSTR lpRead, DWORD dw, LPCTSTR lpStr, LPVOID lpData)
- {
- return 0;
- }
- BOOL WINAPI ImeSetCompositionString(HIMC hIMC, DWORD dwIndex, LPCVOID lpComp, DWORD dwComp, LPCVOID lpRead, DWORD dwRead)
- {
- return FALSE;
- }
- //用于向系统发送消息
- BOOL GenerateMessage(HIMC hIMC, LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg)
- {
- LPINPUTCONTEXT lpIMC;
- if( (lpIMC = ImmLockIMC(hIMC)) == NULL )
- return FALSE;
-
- if (IsWindow(lpIMC->hWnd))
- {
- LPDWORD lpdw;
- if (!(lpIMC->hMsgBuf = ImmReSizeIMCC(lpIMC->hMsgBuf,
- sizeof(DWORD) * (lpIMC->dwNumMsgBuf +1) * 3)))
- return FALSE;
-
- if (!(lpdw = (LPDWORD)ImmLockIMCC(lpIMC->hMsgBuf)))
- return FALSE;
-
- lpdw += (lpIMC->dwNumMsgBuf) * 3;
- *((LPGENEMSG)lpdw) = *lpGeneMsg;
- ImmUnlockIMCC(lpIMC->hMsgBuf);
- lpIMC->dwNumMsgBuf++;
-
- ImmGenerateMessage(hIMC);
- }
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- //特殊字符处理
- int specsif(char *ss)
- {
- int i,t,t1,t2,len;
- //特殊字符处理,以便支持特殊字符了输入
- len=strlen(ss);
- if(len>=4)
- {
- t=-1;
- for(i=0;i<len;i++)
- {
- t++;
- t1=t2=-1;
- if(ss[i]=='0' && (ss[i+1]=='x'||ss[i+1]=='X') && i<len-2 )
- {
- if(ss[i+2]>='0' && ss[i+2]<='9')
- t1=ss[i+2]-'0';
- if(ss[i+2]>='a' && ss[i+2]<='f')
- t1=ss[i+2]-'a'+10;
- if(ss[i+2]>='A' && ss[i+2]<='F')
- t1=ss[i+2]-'A'+10;
- if(ss[i+3]>='0' && ss[i+3]<='9')
- t2=ss[i+3]-'0';
- if(ss[i+3]>='a' && ss[i+3]<='f')
- t2=ss[i+3]-'a'+10;
- if(ss[i+3]>='A' && ss[i+3]<='F')
- t2=ss[i+3]-'A'+10;
- }
- if(t1!=-1 && t2!=-1)
- {
- //char tem[100];
- //sprintf(tem,"%d %d",t1,t2);
- t1=t1*16+t2;
- ss[t]=t1;
- //MessageBox(0,tem,ss,0);
- i=i+3;
- }
- else
- ss[t]=ss[i];
- }
- ss[t+1]=0;
- }
- return 0;
- }
- //把转换后的汉字发到接收程序中使用内部机制.
- BOOL IMESenChiApp(HIMC hIMC, char *ss)
- {
- //内部发送在首次发送时可能失效,因此暂时不用
- specsif(ss);
- if(strlen(ss)<1)
- {
- GENEMSG GnMsg;
- LPCOMPOSITIONSTRING lpCompStr;
- LPINPUTCONTEXT lpIMC;
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- if(strlen(ss))
- {
- strcpy(GETLPRESULTSTR(lpCompStr),ss);
- //_tcscpy(GETLPRESULTSTR(lpCompStr),"高点");
- lpCompStr->dwResultStrLen =strlen(ss);
- //{
- // char sss[100];
- // sprintf(sss,"%d",strlen(ss));
- // MessageBox(0,sss,0,0);
- //}
- GnMsg.msg = WM_IME_COMPOSITION;//
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_RESULTSTR;
- GenerateMessage(hIMC, 0,(LPGENEMSG)&GnMsg);
- }
- }
- else
- {
- //向获得焦点的窗口发送字符串
- //发送过多的字符有可能失去挂钩
- int i;
- for(i=0;i<(int)strlen(ss);)
- {
- if(ss[i]<0)
- {
- SendMessage(GetFocus(), WM_IME_CHAR, MAKEWORD(ss[i+1],ss[i]), 0);
- i+=2;
- }
- else
- {
- SendMessage(GetFocus(), WM_IME_CHAR, MAKEWORD(ss[i],0), 1);
- if(ss[i]==13&&ss[i+1]==10)
- i++;
- i++;
- }
- }
- }
- ss[0]=0;
- return TRUE;
- }