DLL.CPP
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:8k
- // dll.cpp : Defines the entry point for the DLL application.
- //
- #include "stdafx.h"
- #include "windows.h"
- #include "string.h"
- #include "stdio.h"
- #include "EntoCh.h"
- EntoCh CHchang;
- HWND ATC=0;
- #define MYLIBAPI extern "C" __declspec(dllexport)
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- int WriteReg(char *valname,char *keyVal);
- DWORD mmReadReg(char *valname);
- DWORD ReadReg();
- MYLIBAPI BOOL keyprogress(int wparam,char *retInputBuf,char *SendCh,char *SendENbuf,char *Midtems,char*Control );
- BOOL WINAPI DllMain (
- HINSTANCE hInstDLL,
- DWORD dwFunction,
- LPVOID lpNot)
- {
- switch(dwFunction)
- {
- case DLL_PROCESS_ATTACH:
- CHchang.Start();
- break;
- case DLL_PROCESS_DETACH:
- break;
- case DLL_THREAD_DETACH:
- break;
- }
- return TRUE;
- }
- MYLIBAPI BOOL myImeProcessKey(long *fcmywnd,char *SendCH,char *Control,HIMC hIMC,UINT vKey,LPARAM lKeyData,CONST LPBYTE lpbKeyState)
- {
- int mykey;
- BOOL fRet = FALSE;
- unsigned char kbByte[256];
- char ss1[1000]="",ss2[1000]="",ss3[1000];
- try
- {
- mykey=(int)vKey;
- GetKeyboardState(kbByte);
- //GetAsyncKeyState上一次调用以来,如键已被按过,则位0设为1;
- //否则设为0。如键目前处于按下状态,则位8设为1;如抬起,则为0。
- //按住Ctrl 、Shift(10)或Alt时不进行编 VK_ATTN VK_CONTROL
- if (lpbKeyState[VK_ATTN] & 0x80)
- return FALSE;
- //////////////////////////////////////////////
- if(kbByte[VK_CAPITAL]&1)//大写字母打开时将不进行输入处理
- return 0;
- //sprintf(ss,"%d",mykey);
- ////////////////////////////////////////////////////
- //以下为转换功能
- ReadReg(); //查看软件是否需要更新字库
- fRet=keyprogress(mykey,ss1, SendCH,ss2,ss3,Control);
-
- //MessageBox(0,ss1,ss3,0);
- } catch (...) {
- MessageBox(0,"myImeProcessKey","字库有错误发生",0);
- }
- return fRet;
- }
- ////////////////////////////////////////////////
- // 按键处理
- //
- MYLIBAPI BOOL ClearBuf()
- {
- CHchang.ClearBuf();
- return 0;
- }
- MYLIBAPI BOOL insertNewWord( char *En,char *chi)
- {
- char ss[1500];
- int mode=1;
- //strcpy(En,"TKTK");
- //strcpy(chi,"和和");
- sprintf(ss,"%s %s",En,chi);
- MessageBox(0,ss,"insertNewWord",0);
- //mode=1表示从基本到扩展,mode=2表示从扩展到基本,mode=3表示仅基本,mode=4表示仅扩展
- //
- if(CHchang.myCHLib.mode==1||CHchang.myCHLib.mode==3)
- mode=1;
- if(CHchang.myCHLib.mode==2||CHchang.myCHLib.mode==4)
- mode=2;
- CHchang.myCHLib.ReadchNode.insertID(En,chi,mode);
- MessageBox(0,"End","insertNewWord",0);
- return 0;
- }
- MYLIBAPI BOOL getnextpage( char *Midtems,int torword)
- {
- char *pp;
- try
- {
- pp=CHchang.NextPage(torword);
- if(pp!=0)
- strcpy(Midtems,pp);
- else
- Midtems[0]=0;
-
- // MessageBox(0,Midtems,0,0);
- // if( Midtems[0]!=0)
- // MessageBox (0,"getnextpage",Midtems,0);
- } catch (...) {
- MessageBox(0,"keyprogress","字库有错误发生",0);
- }
- return 0;
- }
- MYLIBAPI BOOL keyprogress(int wparam,char *retInputBuf,char *SendCh,char *SendENbuf,char *Midtems,char*Control )
- {
- BOOL lresult=0;
- char ss[100];
- try
- {
- if(CHchang.loadFlage==0)
- return 0;
- //GetAsyncKeyState上一次调用以来,如键已被按过,则位0设为1;
- //否则设为0。如键目前处于按下状态,则位15设为1;如抬起,则为0。
- //按住Ctrl或Alt时不进行编 VK_ATTN VK_SHIFT
- //由于开始时需要更新GetAsyncKeyState的值,必须先调用一次。
- sprintf(ss," %d %d %d ",GetAsyncKeyState(16),GetAsyncKeyState(17),GetAsyncKeyState(18));
- if( (GetAsyncKeyState(17)&8000)==0 && (GetAsyncKeyState(18)&8000)==0 )
- {
- //Control返回值用于控制光标移动
- lresult=CHchang.Translatechar(wparam,retInputBuf, SendCh,Control); //翻译字符串
-
- if(SendCh[0]!=0)
- {
- char str[100];
- sprintf(str,"%d",wparam);
- //MessageBox(0,str,0,0);
- }
-
- if(Midtems[0]!='-')//为-说明调用者不要求设置,可防止下标越界
- if(CHchang.GetCurPage()!=NULL)
- strcpy(Midtems,CHchang.GetCurPage());
- if(SendENbuf[0]!='-')
- strcpy(SendENbuf,CHchang.SendENbuf);
- }
- else
- lresult=0;
- } catch (...) {
- MessageBox(0,"keyprogress","字库有错误发生",0);
- }
- return lresult;// 如果为0则向下传递信息,如果为1则不传递信息。
- }
- MYLIBAPI BOOL SetIMEModle (int Mode)
- {
- CHchang.ClearBuf();
- CHchang.myCHLib.IMEWBSetMode(Mode);
- return 0;
- }
- //////////////////////////////////////////////
- //加载字库,以及设置其他变量
- ///////////////////////////////////////////
- MYLIBAPI BOOL DLLstart (int update)
- {
- // char ss[100];
- if(update==1)
- {
- //sprintf(ss,"%d",update);
- //MessageBox(0,"loadChiLib",ss,0);
- CHchang.myCHLib.ReadchNode.Unloadmylib();
- }
- CHchang.Start();
- return 0;
- }
- int RegReadString(char *valname, char *keyVal)
- {
- HKEY hKey;
- unsigned long lon;
- char dd[100]="";
- keyVal[0]=0;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- //如果没有键值就建立一个
- if( RegQueryValueEx( hKey,valname,NULL,NULL,(LPBYTE)keyVal,&lon) != ERROR_SUCCESS ){
- //RegSetValueEx(hKey, valname,0,REG_SZ,(LPBYTE)dd,0);
- }
- RegCloseKey(hKey);
- }
- return 0;
- }
- ///////////////////////////////////////////////////
- int RegSaveString(char *pathname,char *valname, char *keyVal)
- {
- HKEY hKey;
- if ( RegCreateKey(HKEY_CURRENT_USER,pathname, &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, valname,0,REG_SZ,(LPBYTE)keyVal,strlen(keyVal)+1);
- RegCloseKey(hKey);
- }
- return 0;
- }
- ///////////////////////////////////////////////////////////////////////
- //设置指定的输入法为第一输入法
- MYLIBAPI int SetOrderIME(HKL instHKL)
- {
- char ss[1000],retss[100],temss[100],tempath[1000];
- int i,t=1,num;
- HKL hKB[100];
- HKL hCurKBDLayout;
- hCurKBDLayout = GetKeyboardLayout(0); //取得目前的输入法
- sprintf(ss,"%x", instHKL);
- ActivateKeyboardLayout (instHKL, 0);
- SetKeyboardState((unsigned char *)&ss);
- LoadKeyboardLayout(ss, KLF_REORDER);
- ActivateKeyboardLayout ((HKL)804, 0);
- SetKeyboardState((unsigned char *)&"00000804");
- LoadKeyboardLayout("00000804", KLF_REORDER);
- num = GetKeyboardLayoutList(25, hKB) ;//取得所有输入法
- for(i=0;i<num;i++)
- {
- sprintf(retss,"%x",hKB[i]);
- if(ImmIsIME(hKB[i])==0||strlen(retss)<8)
- {
- sprintf(retss,"%x",(unsigned short int)hKB[i]);
- sprintf(temss,"00000000");
- sprintf(&temss[8-strlen(retss)],retss);
- sprintf(ss,"%d",t);
- RegSaveString("Keyboard Layout\Preload",ss, temss);
- sprintf(tempath,"Keyboard Layout\Preload\%d",t);
- RegSaveString(tempath,"", temss);
- if(t==1)
- {
- SetKeyboardState((unsigned char *)&temss);
- LoadKeyboardLayout(temss, KLF_REORDER);
- //MessageBox(0,temss,temss,0);
- }
- t++;
- }
- }
- //保存当 前安装的输入法
- sprintf(ss,"%d",t);
- sprintf(retss,"%x",instHKL);
- RegSaveString("Keyboard Layout\Preload",ss, retss);
- sprintf(tempath,"Keyboard Layout\Preload\%d",t);
- RegSaveString(tempath,"", retss);
- t++;
-
- for(i=0;i<num;i++)
- {
- sprintf(retss,"%x",hKB[i]);
- if(ImmIsIME(hKB[i])==1 && hKB[i]!=instHKL&&strlen(retss)==8 )//跳过当前输入法
- {
- sprintf(ss,"%d",t);
- RegSaveString("Keyboard Layout\Preload",ss, retss);
- sprintf(tempath,"Keyboard Layout\Preload\%d",t);
- RegSaveString(tempath,"", retss);
- t++;
- }
- }
- ActivateKeyboardLayout (hCurKBDLayout, 0);
- return 0;
- }
- DWORD ReadReg()
- {
- HKEY hKey;
- DWORD myupdate1;
- unsigned long lon;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- if( RegQueryValueEx( hKey,"jsime",NULL,NULL,(LPBYTE)&myupdate1,&lon) == ERROR_SUCCESS )
- {
- if(myupdate1==1)
- {
- //char ss[100];
- //sprintf(ss,"需要更新字库%d",myupdate1);
- //MessageBox(0,ss,"ddd",0);
- myupdate1=0;
- RegSetValueEx(hKey, "jsime",0,REG_DWORD,(LPBYTE)&myupdate1,sizeof(DWORD));
- DLLstart(1);
- }
- }
- RegCloseKey(hKey);
- }
- else
- MessageBox(0,"Software\jsime","主键打开失败",0);
- return myupdate1;
- }