test.c
资源名称:大熊猫输入法原码.zip [点击查看]
上传用户:szljw888
上传日期:2010-04-11
资源大小:124k
文件大小:26k
源码类别:
输入法编程
开发平台:
C/C++
- /* 大熊猫输入法(Free Chinese Input) 由YJMSIR(yjmsir@163.com)编写
- * 协议: GPL
- * freeinput( A Chinese Input Method) by YJMSIR(yjmsir@163.com)
- * Licence: GPL
- */
- #include "freepy.h"
- //#include <windows.h>
- #include <commdlg.h>
- //static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH] ;
- #define GBK_QUFIRST 0x81
- #define GBK_QULAST 0xFE //7e=128-2=126
- #define GBK_WEIFIRST 0x40
- #define GBK_WEILAST 0xFE //Be=192-2=190 //126*190=23940,即24k //×4=96k
- BOOL YjmBatchMakeWord(TCHAR *FromFile,TCHAR *ToFile,BOOL bOUTPUTFILE,BOOL bINSERTWBLIB)
- {
- FILE *fpDict,*fpDict1;
- char strText[MAXPERLINESTRLENGTH];
- int i,iCount;
- if((fpDict=_tfopen(FromFile,"r"))==NULL){
- MessageBoxPrintf("init","%s can not found",FromFile);
- return 1;
- }
- if(bOUTPUTFILE){
- if((fpDict1=_tfopen(ToFile,"wt"))==NULL){
- MessageBoxPrintf("init","%s can not found",ToFile);
- return 1;
- }
- }
- for (;;) {
- //首先读取一行
- if (!fgets (strText, MAXPERLINESTRLENGTH, fpDict))
- break;
- //删除末尾的空格和回车键
- iCount = strlen (strText) - 1;
- while ((strText[iCount] == 'n') || (strText[iCount] == ' ')) {
- strText[iCount] = ' ';
- if (!iCount)
- break;
- iCount--;
- }
- //删除行中的空格
- for(i=0;i<iCount;i++){
- if(*(strText+i)==0x20){
- _tcscpy(strText+i,strText+i+1);
- if (!iCount)
- break;
- i--;
- iCount--;
- }
- }
- if(wConversionSet1 & C_SET1_ERBIMAKEWORD)
- AutoGetWordErbiCode(strText,bINSERTWBLIB);
- else AutoGetWordWubiCode(strText,bINSERTWBLIB);
- if(bOUTPUTFILE) fprintf(fpDict1,"%s %sn",AutoWuBiCode,strText);
- }
- fclose (fpDict);
- fclose (fpDict1);
- return TRUE;
- }
- BOOL WINAPI BATCHMAKEWORDDialogProc(
- HWND hWnd ,
- UINT message ,
- WPARAM wParam ,
- LPARAM lParam )
- {
- static TCHAR szBATCHMAKEWORDFileName[2][MAX_PATH]={0};
- static BOOL bOUTPUTFILE=0,bINSERTWBLIB=0;
- switch(message) {
- case WM_INITDIALOG:
- if(!(wConversionSet & CONVERSION_SET_USEWB)){
- EndDialog(hWnd,TRUE);
- break;
- }
- if(!_tcslen(szBATCHMAKEWORDFileName[0]))
- Add(CurrentTableDir,"word.txt",szBATCHMAKEWORDFileName[0]);
- if(!_tcslen(szBATCHMAKEWORDFileName[1]))
- Add(CurrentTableDir,"wordout.txt",szBATCHMAKEWORDFileName[1]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[0]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[1]);
- break;
- case WM_COMMAND:
- switch(wParam) {
- case IDOK:
- GetDlgItemText(hWnd,IDC_EDIT1,szBATCHMAKEWORDFileName[0],MAX_PATH);
- GetDlgItemText(hWnd,IDC_EDIT2,szBATCHMAKEWORDFileName[1],MAX_PATH);
- if(!IsFileExist(szBATCHMAKEWORDFileName[0])){
- MessageBox(NULL,_T("没有找到文件"),_T("没有找到文件!"),MB_OK);
- EndDialog(hWnd,TRUE);
- break;
- }
- bOUTPUTFILE=(IsDlgButtonChecked(hWnd,IDC_OUTPUTFILE) == BST_CHECKED)?1:0;
- bINSERTWBLIB=(IsDlgButtonChecked(hWnd,IDC_INSERTWBLIB) == BST_CHECKED)?1:0;
- if(IsFileExist(szBATCHMAKEWORDFileName[1]) && bOUTPUTFILE){
- if (MessageBox(NULL, _T("是否覆盖?"),_T("已经存在文件!"),
- MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) != IDYES) {
- EndDialog(hWnd,TRUE);
- break;
- }
- }
- //excute
- if(bOUTPUTFILE||bINSERTWBLIB)
- YjmBatchMakeWord(szBATCHMAKEWORDFileName[0],szBATCHMAKEWORDFileName[1],bOUTPUTFILE,bINSERTWBLIB);
- EndDialog(hWnd,TRUE);
- break;
- case IDCANCEL:
- EndDialog(hWnd,TRUE);
- break;
- case IDC_BUTTONDEF:
- Add(CurrentTableDir,"word.txt",szBATCHMAKEWORDFileName[0]);
- Add(CurrentTableDir,"wordout.txt",szBATCHMAKEWORDFileName[1]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[0]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[1]);
- //EndDialog(hWnd,TRUE);
- break;
- case IDC_BUTTONSYSSEL:
- if(YjmFileOpenTextDlg (NULL,szBATCHMAKEWORDFileName[0],YJMMessage,0)){
- SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[0]);
- }
- break;
- case IDC_BUTTONUSRSEL:
- if(YjmFileOpenTextDlg (NULL,szBATCHMAKEWORDFileName[1],YJMMessage,0)){
- SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[1]);
- }
- break;
- default:
- return FALSE;
- break;
- }
- break;
- default:
- return FALSE;
- break;
- }
- return TRUE;
- }
- BOOL YjmSortStr(TCHAR *str,BOOL FromSmallToBig)
- {
- UINT i,j,k;
- TCHAR temp;
- k=_tcslen(str);
- if(k){
- for(i=0;i<k;i++){
- if(*(str+i)==0x20){
- _tcscpy(str+i,str+i+1);
- i--;
- k--;
- }
- }
- }
- if(k){
- for(i=0;i<k;i++){
- for(j=i;j<k;j++){
- if(FromSmallToBig?(*(str+i)>*(str+j)):(*(str+i)<*(str+j))){
- temp=*(str+i);
- *(str+i)=*(str+j);
- *(str+j)=temp;
- }
- }
- }
- }
- return 1;
- }
- BOOL SetwubiFirstLeadChr(TCHAR cFirstChr)
- {
- WORD wHead=cFirstChr-_T('!');
- if(wubiFirstLeadChr[wHead]->prev==wubiDictHead->next)
- return 0;
- while(wubiFirstLeadChr[wHead]->prev->strCode[0]>=cFirstChr &&
- wubiFirstLeadChr[wHead]->prev!=wubiDictHead->next){
- wubiFirstLeadChr[wHead]=wubiFirstLeadChr[wHead]->prev;
- }
- return 1;
- }
- BOOL ReInitDictionaryWubi()
- {
- ReLoadWubi:
- if ( (lpWubiMapFileBase = (LPVOID) MapViewOfFile( hWubiMapFile,
- FILE_MAP_ALL_ACCESS ,
- 0,
- 0,
- 0)) != NULL) {
- SwitchUserPath=1;
- DestroyDictionaryWubi(1);
- SwitchUserPath=0;
- if(!EnlargeWubiShareMemoryNumAndWriteUserIni())
- exit(1);//扩大五兆
- }
- if(InitDictionaryWubi()==2) {
- goto ReLoadWubi;
- }
- return 0;
- }
- BOOL ReInitDictionaryPinyin()
- {
- ReLoadPinyin:
- if ( (lpMapFileBase = (LPVOID) MapViewOfFile( hMapFile,
- FILE_MAP_ALL_ACCESS ,
- 0,
- 0,
- 0)) != NULL) {
- SwitchUserPath=1;
- DestroyDictionaryPinYin(1);
- SwitchUserPath=0;
- if(!EnlargePinyinShareMemoryNumAndWriteUserIni())
- exit(1);//扩大五兆
- }
- if(InitDictionaryPinYin()==2) {
- goto ReLoadPinyin;
- }
- return 0;
- }
- BOOL ReInitDictionaryAttachLib()
- {
- ReLoadAttachLib:
- if ( (lpAttachLibMapFileBase = (LPVOID) MapViewOfFile( hAttachLibMapFile,
- FILE_MAP_ALL_ACCESS ,
- 0,
- 0,
- 0)) != NULL) {
- SwitchUserPath=1;
- DestroyDictionaryAttachLib();
- SwitchUserPath=0;
- if(!EnlargeAttachShareMemoryNumAndWriteUserIni()) exit(1);//扩大五兆
- }
- if(InitDictionaryAttachLib()==2) {
- goto ReLoadAttachLib;
- }
- return 0;
- }
- BOOL EnlargePinyinShareMemoryNumAndWriteUserIni()
- {
- if(dwPinyinShareMemorySum<40000000){//40M
- dwPinyinShareMemorySum+=5000000;//5M
- WriteUserIni();
- return 1;
- }
- else
- return 0;
- }
- BOOL EnlargeWubiShareMemoryNumAndWriteUserIni()
- {
- if(dwWubiShareMemorySum<40000000){
- dwWubiShareMemorySum+=5000000;
- WriteUserIni();
- return 1;
- }
- else
- return 0;
- }
- BOOL EnlargeAttachShareMemoryNumAndWriteUserIni()
- {
- if(dwAttachShareMemorySum<40000000){
- dwAttachShareMemorySum+=5000000;
- WriteUserIni();
- return 1;
- }
- else
- return 0;
- }
- BOOL WINAPI MainLibDialogProc(
- HWND hWnd ,
- UINT message ,
- WPARAM wParam ,
- LPARAM lParam )
- {
- TCHAR ButtonText[2][20]={"启用主词库","禁用主词库"};
- static TCHAR szMainLibFileNametmp[2][MAX_PATH]={0};
- switch(message) {
- case WM_INITDIALOG:
- _tcscpy(szMainLibFileNametmp[0],szMainLibFileName[0]);
- _tcscpy(szMainLibFileNametmp[1],szMainLibFileName[1]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szMainLibFileNametmp[0]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szMainLibFileNametmp[1]);
- if(wConversionSet & CONVERSION_SET_USEWB){
- SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOMAIN),WM_SETTEXT,0,(LPARAM)ButtonText[1]);
- }
- else{
- SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOMAIN),WM_SETTEXT,0,(LPARAM)ButtonText[0]);
- }
- break;
- case WM_COMMAND:
- switch(wParam) {
- case IDOK:
- MessageBox(NULL,_T("请慎用这个功能!"),_T("注意!"),MB_OK);
- GetDlgItemText(hWnd,IDC_EDIT1,szMainLibFileName[0],MAX_PATH);
- GetDlgItemText(hWnd,IDC_EDIT2,szMainLibFileName[1],MAX_PATH);
- EndDialog(hWnd,TRUE);
- break;
- case IDCANCEL:
- _tcscpy(szMainLibFileName[0],szMainLibFileNametmp[0]);
- _tcscpy(szMainLibFileName[1],szMainLibFileNametmp[1]);
- EndDialog(hWnd,TRUE);
- break;
- case IDC_BUTTONDEF:
- szMainLibFileName[0][0]=' ';
- szMainLibFileName[1][0]=' ';
- SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szMainLibFileName[0]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szMainLibFileName[1]);
- WriteUserIni();
- //EndDialog(hWnd,TRUE);
- break;
- case IDC_BUTTONSYSSEL:
- MessageBox(NULL,_T("请慎用这个功能!"),_T("注意!"),MB_OK);
- if(YjmFileOpenTextDlg (NULL,szMainLibFileName[0],YJMMessage,0)){
- SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szMainLibFileName[0]);
- WriteUserIni();
- }
- break;
- case IDC_BUTTONUSRSEL:
- MessageBox(NULL,_T("请慎用这个功能!"),_T("注意!"),MB_OK);
- if(YjmFileOpenTextDlg (NULL,szMainLibFileName[1],YJMMessage,0)){
- SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szMainLibFileName[1]);
- WriteUserIni();
- }
- break;
- case IDC_BUTTONNOMAIN:
- if(wConversionSet & CONVERSION_SET_USEWB){
- wConversionSet &= ~CONVERSION_SET_USEWB;
- WriteUserIni();
- SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOMAIN),WM_SETTEXT,0,(LPARAM)ButtonText[0]);
- SwitchUserPath=1;
- DestroyDictionaryWubi(0);
- SwitchUserPath=0;
- }
- else{
- wConversionSet |= CONVERSION_SET_USEWB;
- WriteUserIni();
- SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOMAIN),WM_SETTEXT,0,(LPARAM)ButtonText[1]);
- InitDictionaryWubi();
- }
- EndDialog(hWnd,TRUE);
- break;
- case IDC_BUTTONATONCE:
- //wWubiMapCount=1;/**/
- SwitchUserPath=1;
- DestroyDictionaryWubi(0);
- SwitchUserPath=0;
- InitDictionaryWubi();
- EndDialog(hWnd,TRUE);
- break;
- default:
- return FALSE;
- break;
- }
- break;
- default:
- return FALSE;
- break;
- }
- return TRUE;
- }
- BOOL WINAPI AttachLibDialogProc(
- HWND hWnd ,
- UINT message ,
- WPARAM wParam ,
- LPARAM lParam )
- {
- TCHAR ButtonText[2][20]={"启用附加词库","禁用附加词库"};
- switch(message) {
- case WM_INITDIALOG:
- SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[0]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[1]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT3),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[2]);
- if(wConversionSet & CONVERSION_SET_USEATTACH){
- SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOATT),WM_SETTEXT,0,(LPARAM)ButtonText[1]);
- }
- else{
- SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOATT),WM_SETTEXT,0,(LPARAM)ButtonText[0]);
- }
- break;
- case WM_COMMAND:
- switch(wParam) {
- case IDOK:
- GetDlgItemText(hWnd,IDC_EDIT1,szAttachLibFileName[0],MAX_PATH);
- GetDlgItemText(hWnd,IDC_EDIT2,szAttachLibFileName[1],MAX_PATH);
- GetDlgItemText(hWnd,IDC_EDIT3,szAttachLibFileName[2],MAX_PATH);
- EndDialog(hWnd,TRUE);
- break;
- case IDCANCEL:
- EndDialog(hWnd,TRUE);
- break;
- case IDC_BUTTONDEF:
- szAttachLibFileName[0][0]=' ';
- szAttachLibFileName[1][0]=' ';
- szAttachLibFileName[2][0]=' ';
- WriteUserIni();
- SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[0]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[1]);
- SendMessage(GetDlgItem(hWnd,IDC_EDIT3),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[2]);
- //EndDialog(hWnd,TRUE);
- break;
- case IDC_BUTTONATT1:
- if(YjmFileOpenTextDlg (NULL,szAttachLibFileName[0],YJMMessage,0)){
- WriteUserIni();
- SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[0]);
- }
- break;
- case IDC_BUTTONATT2:
- if(YjmFileOpenTextDlg (NULL,szAttachLibFileName[1],YJMMessage,0)){
- WriteUserIni();
- SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[1]);
- }
- break;
- case IDC_BUTTONATT3:
- if(YjmFileOpenTextDlg (NULL,szAttachLibFileName[2],YJMMessage,0)){
- WriteUserIni();
- SendMessage(GetDlgItem(hWnd,IDC_EDIT3),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[2]);
- }
- break;
- case IDC_BUTTONNOATT:
- if(wConversionSet & CONVERSION_SET_USEATTACH){
- wConversionSet &= ~CONVERSION_SET_USEATTACH;
- WriteUserIni();
- SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOATT),WM_SETTEXT,0,(LPARAM)ButtonText[0]);
- SwitchUserPath=1;
- DestroyDictionaryAttachLib();
- SwitchUserPath=0;
- }
- else{
- wConversionSet |= CONVERSION_SET_USEATTACH;
- WriteUserIni();
- SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOATT),WM_SETTEXT,0,(LPARAM)ButtonText[1]);
- InitDictionaryAttachLib();
- }
- EndDialog(hWnd,TRUE);
- break;
- case IDC_BUTTONATONCE:
- //wAttachLibMapCount=1;
- SwitchUserPath=1;
- DestroyDictionaryAttachLib();
- SwitchUserPath=0;
- InitDictionaryAttachLib();
- EndDialog(hWnd,TRUE);
- break;
- default:
- return FALSE;
- break;
- }
- break;
- default:
- return FALSE;
- break;
- }
- return TRUE;
- }
- UINT QueryQuickSearchTablegbk(char *strHZ,char *resultcode)
- {
- unsigned char HZ[3]="aa",CODE[5]="aaaa",*lpcode;
- UINT k;
- if(_tcslen(strHZ)!=2) return 0;
- _tcscpy(HZ,strHZ);
- lpcode=WB4GBK+4*((GBK_WEILAST-GBK_WEIFIRST+1)*(HZ[0]-GBK_QUFIRST)+HZ[1]-GBK_WEIFIRST);
- for(k=0;k<4;k++){
- CODE[k]=*(lpcode+k);
- if(CODE[k]==0x20){
- CODE[k]=' ';
- break;
- }
- }
- CODE[4]=' ';
- if(!_tcslen(CODE)) return 0;
- _tcscpy(resultcode,CODE);
- return 1;
- }
- UINT GetQuickSearchTablegbk()
- {
- WBRecord __based(lpWubiMapFileBase) *recTemp;
- FILE *fp,*fp1;
- TCHAR QuickSearchTable[GBK_QULAST-GBK_QUFIRST+2][GBK_WEILAST-GBK_WEIFIRST+1][4]={0};
- unsigned char HZ[3]="aa",CODE[7]="aaaa";
- UINT i,j,k,l;
- for(i=GBK_QUFIRST;i<=GBK_QULAST;i++){
- for(j=GBK_WEIFIRST;j<=GBK_WEILAST;j++){
- for(k=0;k<4;k++){
- QuickSearchTable[i-GBK_QUFIRST][j-GBK_WEIFIRST][k]=0x20;
- }
- }
- }
- if((fp=YJMOpenFileForWrite("wb4codegbk.dat"))== NULL) exit(1);
- if((fp1=YJMOpenFileForWrite("wb4codegbkRef.txt"))== NULL) exit(1);
- for(l=1;l<=6;l++){
- recTemp = wubiDictHead->next;
- if(wubiDictHead->prev!=NULL){
- while (recTemp!= wubiDictHead->prev) {
- if(_tcslen(recTemp->strHZ)==2 && _tcslen(recTemp->strCode)==l){
- _tcscpy(HZ,recTemp->strHZ);
- _tcscpy(CODE,recTemp->strCode);
- CODE[4]=' ';
- if(HZ[0]<=GBK_QULAST && HZ[0]>=GBK_QUFIRST &&
- HZ[1]<=GBK_WEILAST && HZ[1]>=GBK_WEIFIRST){
- for(k=0;k<4;k++){
- if(CODE[k]==' ') goto yjm_next_hz;
- QuickSearchTable[HZ[0]-GBK_QUFIRST][HZ[1]-GBK_WEIFIRST][k]=CODE[k];
- }
- yjm_next_hz:;
- }
- }
- recTemp = recTemp->next;
- }
- }
- }
- fprintf (fp, "%s", QuickSearchTable);
- fprintf (fp1, _T("生成此前4码表用于自动造词时参考,同时可以加快造词速度。方便大家检查码表是否标准。也希望大家共同努力制定出一个标准的反查表来。n"));
- fprintf (fp1, _T("汉字 编码 区码 位码n"));
- for(i=GBK_QUFIRST;i<=GBK_QULAST;i++){
- for(j=GBK_WEIFIRST;j<=GBK_WEILAST;j++){
- HZ[0]=i;
- HZ[1]=j;
- HZ[2]=' ';
- for(k=0;k<4;k++){
- CODE[k]=QuickSearchTable[i-GBK_QUFIRST][j-GBK_WEIFIRST][k];
- }
- CODE[4]=' ';
- fprintf (fp1, "%s %s %x %xn",HZ,CODE,i,j);
- }
- }
- fclose (fp);
- fclose (fp1);
- return 0;
- }
- BOOL YjmFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName,int iSave)
- {
- static OPENFILENAME ofn ;
- static TCHAR szFilter[] = TEXT ("Picture Files (*.bmp) *.bmp ");
- ofn.lStructSize = sizeof (OPENFILENAME) ;
- ofn.hwndOwner = hwnd ;
- ofn.hInstance = NULL ;
- ofn.lpstrFilter = szFilter ;
- ofn.lpstrCustomFilter = NULL ;
- ofn.nMaxCustFilter = 0 ;
- ofn.nFilterIndex = 0 ;
- //ofn.lpstrFile = NULL ; // Set in Open and Close functions
- ofn.nMaxFile = MAX_PATH ;
- //ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions
- ofn.nMaxFileTitle = MAX_PATH ;
- ofn.lpstrInitialDir = NULL ;
- ofn.lpstrTitle = NULL ;
- ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |OFN_PATHMUSTEXIST ;// Set in Open and Close functions
- ofn.nFileOffset = 0 ;
- ofn.nFileExtension = 0 ;
- ofn.lpstrDefExt = TEXT ("bmp") ;
- ofn.lCustData = 0L ;
- ofn.lpfnHook = NULL ;
- ofn.lpTemplateName = NULL ;
- // ofn.hwndOwner = hwnd ;
- ofn.lpstrFile = pstrFileName ;
- ofn.lpstrFileTitle = pstrTitleName ;
- //ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
- if(!iSave)
- return GetOpenFileName (&ofn);
- else return GetSaveFileName (&ofn);
- }
- BOOL YjmFileOpenTextDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName,int iSave)
- {
- static OPENFILENAME ofn ;
- static TCHAR szFilter[] = TEXT ("Text Files (*.*) *.* ");
- ofn.lStructSize = sizeof (OPENFILENAME) ;
- ofn.hwndOwner = hwnd ;
- ofn.hInstance = NULL ;
- ofn.lpstrFilter = szFilter ;
- ofn.lpstrCustomFilter = NULL ;
- ofn.nMaxCustFilter = 0 ;
- ofn.nFilterIndex = 0 ;
- //ofn.lpstrFile = NULL ; // Set in Open and Close functions
- ofn.nMaxFile = MAX_PATH ;
- //ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions
- ofn.nMaxFileTitle = MAX_PATH ;
- ofn.lpstrInitialDir = NULL ;
- ofn.lpstrTitle = NULL ;
- ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |OFN_PATHMUSTEXIST ; // Set in Open and Close functions
- ofn.nFileOffset = 0 ;
- ofn.nFileExtension = 0 ;
- ofn.lpstrDefExt = TEXT ("txt") ;
- ofn.lCustData = 0L ;
- ofn.lpfnHook = NULL ;
- ofn.lpTemplateName = NULL ;
- // ofn.hwndOwner = hwnd ;
- ofn.lpstrFile = pstrFileName ;
- ofn.lpstrFileTitle = pstrTitleName ;
- //ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
- if(!iSave)
- return GetOpenFileName (&ofn);
- else return GetSaveFileName (&ofn);
- }
- UINT YjmGetColor(COLORREF *ColorTarget)
- {
- CHOOSECOLOR cc ;
- COLORREF crCustColors[16];
- cc.lStructSize = sizeof (CHOOSECOLOR) ;
- cc.hwndOwner = NULL ;
- cc.hInstance = NULL ;
- cc.rgbResult = RGB (0x80, 0x80, 0x80) ;
- cc.lpCustColors = crCustColors ;
- cc.Flags = CC_RGBINIT | CC_FULLOPEN ;
- cc.lCustData = 0 ;
- cc.lpfnHook = NULL ;
- cc.lpTemplateName = NULL ;
- if(ChooseColor (&cc))
- *ColorTarget=crCustColors[0];
- return 1;
- }
- //输出词条文件
- UINT GetSingWordPerLine(UINT num,UINT codenum)
- {
- WBRecord __based(lpWubiMapFileBase) *recTemp;
- FILE *fp;
- TCHAR szTabFileName[MAX_PATH],szPreStr[100],szPrePreStr[100],szPrePrePreStr[100];
- UINT num2=num*2;
- Add(CurrentTableDir,"SingWordPerLine.txt",szTabFileName);
- if( (fp = _tfopen( szTabFileName, "wt" )) == NULL ){
- MessageBoxPrintf("init","%s can not found",szTabFileName);
- exit(1);
- }
- recTemp = wubiDictHead->next;
- if(wubiDictHead->prev!=NULL){
- while (recTemp!= wubiDictHead->prev) {
- if(_tcslen(recTemp->strHZ)==num2){
- if(codenum!=0){
- if(_tcslen(recTemp->strCode)==codenum){
- fprintf (fp, "%s %sn", (char *)recTemp->strHZ,(char *)recTemp->strCode);
- }
- }
- else if(_tcscmp(szPreStr,(char *)recTemp->strHZ)&&
- _tcscmp(szPrePreStr,(char *)recTemp->strHZ)&&
- _tcscmp(szPrePrePreStr,(char *)recTemp->strHZ)){
- fprintf (fp, "%sn", (char *)recTemp->strHZ);
- _tcscpy(szPrePrePreStr,szPrePreStr);
- _tcscpy(szPrePreStr,szPreStr);
- _tcscpy(szPreStr,(char *)recTemp->strHZ);
- }
- }
- recTemp = recTemp->next;
- }
- }
- fclose (fp);
- return 0;
- }
- //输出词条文件
- UINT GetSingWordPerLinePinyin(UINT num,UINT codenum)
- {
- FILE *stream;
- TCHAR szTabFileName[MAX_PATH];
- int i,j,k;
- WORD awKey[MAX_PHRASE_LEN];
- WORD wLen;
- BYTE bLen;
- LPKEYPH lpKPh;
- LPHZPH lpHZPh;
- BOOL fFirst1,fFirst2;
- WORD wPhLen;
- TCHAR YJMaPYTab[MAX_PY_NUM][MAX_PHRASE_LEN+1] = {0};
- Add(CurrentTableDir,"word_PY2.txt",szTabFileName);
- if( (stream = _tfopen( szTabFileName, "wt" )) == NULL ){
- MessageBoxPrintf("init","%s can not found",szTabFileName);
- exit(1);
- }
- for(i=0;i<26;i++){
- for(j=0;j<MAX_EACH_PY_NUM;j++){
- if(aPYTab[i][j].wKey){
- _tcscpy(YJMaPYTab[aPYTab[i][j].wKey],aPYTab[i][j].szPY);
- //fprintf (stream, "%d %sn",aPYTab[i][j].wKey,aPYTab[i][j].szPY);
- }
- }
- }
- //
- for(i=0;i<2;i++){
- for(j=0;j<MAX_PY_NUM;j++){
- if( !(lpKPh=(LPKEYPH)((LPBYTE)lpMapFileBase+i*MAX_PY_NUM*sizeof(KEYPH))+j)->wLen ) {
- continue;//如果是本码位没有词组,进入下一码位。
- }
- fFirst1 = TRUE;
- do {
- if( fFirst1 ) fFirst1 = FALSE;
- else lpKPh = lpKPh->lpNext;
- if( lpKPh->wLen !=(int) num ) continue;//yjm
- if( lpKPh->wLen < 0 ) continue;
- wLen = lpKPh->wLen;
- bLen = (BYTE)wLen;
- lpHZPh = lpKPh->lpHZPH;
- memcpy(awKey,lpKPh->awKey,wLen*2);
- fFirst2 = TRUE;
- wPhLen = 0;
- do {
- if( fFirst2 ) fFirst2 = FALSE;
- else lpHZPh = lpHZPh->lpNext;
- fprintf (stream, "%s", (char *)lpHZPh->szHZ);
- if(codenum>=1){
- for(k=0;k<bLen;k++){
- fprintf (stream, " %s",YJMaPYTab[awKey[k]]);
- }
- }
- if(codenum>=2){
- fprintf (stream, " %d",lpHZPh->dwAttrib);
- }
- fprintf (stream, "n");
- }while(lpHZPh->lpNext != NULL);
- } while(lpKPh->lpNext != NULL);
- }
- }
- fclose (stream);
- return 0;
- }
- UINT GetFreePYTable()
- {
- WBRecord __based(lpWubiMapFileBase) *recTemp;
- FILE *fp;
- TCHAR szTabFileName[MAX_PATH],szHZStr[2000];
- char i,j,k[3];
- BOOL bFirst;
- LPTSTR lpDest;
- Add(CurrentTableDir,"freepyout.tab",szTabFileName);
- if( (fp = _tfopen( szTabFileName, "wt" )) == NULL ){
- MessageBoxPrintf("init","%s can not found",szTabFileName);
- exit(1);
- }
- fprintf (fp, "n[PUNCTUATION]nnn[DICTIONARY]");
- k[2]=' ';
- for(i='a';i<='z';i++){
- for(j='a';j<='z';j++){
- k[0]=i;
- k[1]=j;
- //fprintf (fp, "n%s ",k);
- bFirst=TRUE;
- recTemp = wubiDictHead->next;
- if(wubiDictHead->prev!=NULL){
- while (recTemp!= wubiDictHead->prev) {
- if((strlen(recTemp->strHZ)==2) &&
- (recTemp->strCode[0]==i) &&
- (recTemp->strCode[1]==j)){
- if(bFirst==TRUE) strcpy(szHZStr,recTemp->strHZ);
- else if((lpDest=strstr(szHZStr,recTemp->strHZ))==NULL||
- ((lpDest-szHZStr)%2))
- strcat(szHZStr,recTemp->strHZ);
- bFirst=FALSE;
- }
- recTemp = recTemp->next;
- }
- }
- if(bFirst!=TRUE)fprintf (fp, "n%s %s",k,szHZStr);
- }
- }
- fprintf (fp, "nn");
- fclose (fp);
- return 0;
- }
- BOOL WINAPI TestDialogProc(
- HWND hWnd ,
- UINT message ,
- WPARAM wParam ,
- LPARAM lParam )
- {
- TCHAR lpStr[4]="1";
- UINT num,codenum=0;
- //HWND hWndyjm;
- switch(message) {
- case WM_INITDIALOG:
- break;
- case WM_COMMAND:
- switch(wParam) {
- case IDOK:
- GetDlgItemText(hWnd,IDC_EDIT1,lpStr,3);
- sscanf(lpStr,"%u",&num);
- if(IsDlgButtonChecked(hWnd,IDC_CHECK1) == BST_CHECKED){
- GetDlgItemText(hWnd,IDC_EDIT2,lpStr,2);
- sscanf(lpStr,"%u",&codenum);
- }
- GetSingWordPerLine(num,codenum);
- EndDialog(hWnd,TRUE);
- break;
- case IDCANCEL:
- EndDialog(hWnd,TRUE);
- //MessageBox(NULL,_T("已经放弃."),_T("输出汉字词语"),MB_OK);
- break;
- case IDC_QUICKSEARCHGBK:
- GetQuickSearchTablegbk();
- EndDialog(hWnd,TRUE);
- break;
- case IDC_FREEPYTAB:
- GetFreePYTable();
- EndDialog(hWnd,TRUE);
- break;
- case IDC_FREEPYITEMTEXT:
- GetDlgItemText(hWnd,IDC_EDIT1,lpStr,3);
- if(!_tcslen(lpStr)){
- EndDialog(hWnd,TRUE);
- break;
- }
- sscanf(lpStr,"%u",&num);
- if(num<1 || num>MAX_PHRASE_LEN){
- EndDialog(hWnd,TRUE);
- break;
- }
- if(IsDlgButtonChecked(hWnd,IDC_CHECK1) == BST_CHECKED){
- GetDlgItemText(hWnd,IDC_EDIT2,lpStr,2);
- sscanf(lpStr,"%u",&codenum);
- }
- GetSingWordPerLinePinyin(num,codenum);
- EndDialog(hWnd,TRUE);
- break;
- /* case IDC_SOFTKB:
- if((hWndyjm=ImmCreateSoftKeyboard(SOFTKEYBOARD_TYPE_C1,hWnd,1,1))!=NULL)
- ImmShowSoftKeyboard(hWndyjm, SW_SHOWNOACTIVATE);
- else
- MessageBoxPrintf("调试中","锁定");
- EndDialog(hWnd,TRUE);
- break;*/
- //
- default:
- return FALSE;
- break;
- }
- break;
- default:
- return FALSE;
- break;
- }
- return TRUE;
- }
- //打开文件用于读入,如果没有文件,则生成一个空文件,并且报警退出。
- FILE *YJMOpenFileAndProcess(TCHAR filename[MAX_PATH])
- {
- TCHAR szFileName[MAX_PATH];
- FILE *fp;
- Add(CurrentTableDir,filename,szFileName);
- if( (fp = _tfopen( szFileName, "r" )) == NULL ){
- Add(InstallFromDir,filename,szFileName);
- if( (fp = _tfopen( szFileName, "r" )) == NULL ){
- MessageBoxPrintf("init","%s can not found",szFileName);
- fp = _tfopen( szFileName, "wt" );
- fclose(fp);
- return NULL;
- }
- }
- return fp;
- }
- //打开文件用于写入,如果出错则报警退出。
- FILE *YJMOpenFileForWrite(TCHAR filename[MAX_PATH])
- {
- TCHAR szFileName[MAX_PATH];
- FILE *fp;
- Add(CurrentTableDir,filename,szFileName);
- if( (fp = _tfopen( szFileName, "wt" )) == NULL ){
- MessageBoxPrintf("init","%s can not found",szFileName);
- return NULL;
- }
- return fp;
- }