AppDict.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:4k
- // AppDict.cpp: implementation of the AppDict class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "AppDict.h"
- #include "windows.h"
- #include "stdio.h"
- #include "resource.h"
- #include "DllManager.h"
- extern DllManager ChLib;//定义在主DLL中
- char NewChina[1000];
- char NewCode[1000];
- extern HWND ActiveHwnd;
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- BOOL WINAPI AppendWord(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam )
- {
- switch (message)
- {
- case WM_INITDIALOG:
- SetDlgItemText(hDlg,IDC_EDIT1,NewChina);
- SetDlgItemText(hDlg,IDC_EDIT2,NewCode);
- SetWindowPos(hDlg, 0, 200,200,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER //16/1/4
- return TRUE;
- case WM_COMMAND:
- switch(wParam) {
- case IDOK:
- GetDlgItemText(hDlg,IDC_EDIT1,NewChina,1000);
- GetDlgItemText(hDlg,IDC_EDIT2,NewCode,100);
- //MessageBox(NULL,NewChina,NewCode,MB_OK);
- EndDialog(hDlg,IDOK);
- break;
- case IDCANCEL:
- EndDialog(hDlg,IDCANCEL);
- break;
- default:
- break;
- }
- break;
- }
- return FALSE;
- }
- AppDict::AppDict()
- {
- ChiSS[0]=0;
- appdictbool=0;
- }
- int AppDict::AppOne(char *pChi)
- {
- strcat(ChiSS,pChi);
- return 0;
- }
- int AppDict::AppSetDict(DWORD himc)
- {
- int ret;
- LPINPUTCONTEXT lpIMC;
- char temss[2000]="";
- char path[100]="c:\jsime\";
- if (!(lpIMC = ImmLockIMC(himc)))
- return 0L;
- if(appdictbool==0){
- appdictbool=1;
- ChiSS[0]=0;
- ret=0;
- }
- else
- {
- appdictbool=0;
- if(ChiSS[0]==0)
- {
- //WriteReg("ChiCodeEnd",ChiSS);
- WinExec("c:\jsime\词语管理.exe ShowMessageBox",1);
- //MessageBox(0,mydd.EnCodeEnd,mydd.ChiCodeEnd,0);
- }
- else
- {
- ChLib.ChissToCodeC("c:\jsime\MainCode.txt", ChiSS, temss);
- strcpy(NewCode,temss);
- strcpy(NewChina,ChiSS);
- ret=DialogBox(ChLib.hInstance,MAKEINTRESOURCE(IDD_AppendWordDIALOG1),lpIMC->hWnd,AppendWord);
- strcpy(temss,NewCode);
- strcpy(ChiSS,NewChina);
- if(ret==IDOK)
- {
- FILE *infp;
- char ss[2000];
- ChLib.insertNewWord(temss,ChiSS);
- infp=fopen("c:\jsime\userSource.txt", "a"); //打开文字文件
- if(infp==NULL){
- MessageBox(0,"c:\jsime\userSource.txt装载失败","fopen",0);
- return -1;
- }
- sprintf(ss,"xdxa%s %s",temss,ChiSS);
- fwrite(ss,strlen(ss),1,infp);
- fclose(infp);
- WriteReg("jsime",1);
- }
- }
- ret=1;
- }
- ImmUnlockIMC(himc);
- return ret;
- }
- ////////////////////////////////////////////////////////////////////
- //
- int AppDict::WriteReg(char *valname,char *keyVal)
- {
- HKEY hKey;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, valname,0,REG_MULTI_SZ,(LPBYTE)keyVal,strlen(keyVal));
- RegCloseKey(hKey);
- }
- return 0;
- }
- int AppDict::WriteReg(char *valname,DWORD keyVal)
- {
- HKEY hKey;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, valname,0,REG_DWORD,(LPBYTE)&keyVal,sizeof(DWORD));
- RegCloseKey(hKey);
- }
- return 0;
- }
- //读取注册表中的一个变量
- DWORD AppDict::mmReadReg(char *valname)
- {
- HKEY hKey;
- DWORD myupdate, myupdate1;
- unsigned long lon;
- myupdate=0;
- myupdate1=0;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- //如果没有键值就建立一个
- if( RegQueryValueEx( hKey,valname,NULL,NULL,(LPBYTE)&myupdate1,&lon) != ERROR_SUCCESS )
- {
- RegSetValueEx(hKey, valname,0,REG_DWORD,(LPBYTE)&myupdate,sizeof(DWORD));
- }
- RegCloseKey(hKey);
- }
- return myupdate1;
- }