/************************************************* * addword.c * * * * Copyright (C) 1995-1999 Microsoft Inc. * * * *************************************************/ #include "windows.h" #include "winuser.h" #include "immdev.h" #include "abc95def.h" #include "abcw2.h" #include "resource.h" BOOL WINAPI ErrExit(HWND hDlg, int err_number); WORD s_buf[0x1000]; extern struct INPT_BF kbf; extern HWND hCrtDlg; OFSTRUCT s_open; BYTE str[45]={0}; /******************************************************* write_data(): add the new word defined by the user into the user.rem ********************************************************/ BOOL WINAPI write_data(count,temp_bf) int count; BYTE *temp_bf; { int hd; int op_count; hd=OpenFile(user_lib,&s_open,OF_WRITE); if (hd==-1) return(ErrExit(NULL,1)); _llseek(hd,(data_start+count*data_record_length),0); op_count=_lwrite(hd,(LPSTR)temp_bf,data_record_length); if (op_count!=data_record_length) {_lclose(hd); return(ErrExit(NULL,1)); } _lclose(hd); return(TRUE); } /**************************************************** write_mulu(): write the changed index on the disk *****************************************************/ BOOL WINAPI write_mulu() { int hd; int op_count; hd=OpenFile(user_lib,&s_open,OF_WRITE); if (hd==-1) return(ErrExit(NULL,1)); op_count=_lwrite(hd,(LPSTR)&s_buf,mulu_true_length); if (op_count!=mulu_true_length) {_lclose(hd); return(ErrExit(NULL,1)); } _lclose(hd); return(TRUE); } int WINAPI find_empty_item() { int i; BYTE *p; read_mulu(); p = (BYTE *)&s_buf[8]; i = 0; while ( i < mulu_true_length ) { if ( p[i] & 0x80 ) return( i ); i += mulu_record_length; } return(-1); } //--------------------------------------------------------- // ErrExit() // for file operating erorrs //--------------------------------------------------------- BOOL WINAPI ErrExit(hDlg,err_number) HWND hDlg; int err_number; { MessageBox(hDlg, "文件操作错", NULL, MB_OK | MB_ICONHAND); return(FALSE); } /*********************************************************** read_mulu(): read the user definition index from the tmmr.rem *************************************************************/ BOOL WINAPI read_mulu() { int hd; int op_count; hd=OpenFile(user_lib,&reopen,OF_READ); if (hd==-1) return(ErrExit(NULL,1)); //error op_count=_lread(hd,&s_buf,16); if (op_count!=16) { _lclose(hd); return(ErrExit(NULL,1)); //error } mulu_true_length=s_buf[3]; op_count=_lread(hd,&s_buf[8],mulu_true_length-16); if (op_count!=mulu_true_length-16){ _lclose(hd); return(ErrExit(NULL,1)); //error } _lclose(hd); return(TRUE); } /***************************************************************** listbox(hDlg): list the new word definated by the user. ******************************************************************/ int WINAPI listbox(hDlg) HWND hDlg; { int i,c; BYTE *p; read_mulu(); i=0x10; while (i0x20) j++; i=j; if(j>0) for(j=0;j0xa0) i=0; if(!i) { MessageBox(hDlg, "编码中有非法字符", NULL, MB_OK | MB_ICONHAND); return (TRUE); } for (j=0;jmulu_max_length) { find_empty_flag = find_empty_item(); if ( find_empty_flag == -1 ) { MessageBox(hDlg,"用户定义区满", NULL, MB_OK | MB_ICONHAND); mulu_true_length-=mulu_record_length; return FALSE; } p=(BYTE *)(&s_buf[8]) + find_empty_flag; count=find_empty_flag/mulu_record_length; } else { p=(BYTE *)&s_buf[s_buf[3]/2]; count=(mulu_true_length-0x10)/mulu_record_length-1; } s_buf[3]=mulu_true_length; p[0]=kbf.true_length+0x30; /* fill string index length */ for (i=0; iuser_word_max_length */ kbf.buffer[i]=str[i]; /* move the string into writting buffer */ if (write_mulu() == -1) return FALSE; if (write_data(count,kbf.buffer) == -1) return FALSE; { char temp_bf[41]; WORD ndx; for(ndx=0; ndx<41;ndx++) temp_bf[ndx]=0x20; strncpy(&temp_bf[0],&p[1],kbf.true_length); strncpy(&temp_bf[10],&str[2],30); temp_bf[40]=0; ndx=(WORD)SendDlgItemMessage(hDlg,ID_LISTBOX, // add these new word LB_ADDSTRING, // onto the listbox 0, //1993.4.16 &str[2]->str[1] (LPARAM)((LPSTR *)&temp_bf[0])); //disp the space for deleting word SendDlgItemMessage(hDlg, ID_LISTBOX, LB_SETCURSEL, ndx, 0L); } break; case ID_DEL: index=(WORD)SendDlgItemMessage(hDlg,ID_LISTBOX, LB_GETCURSEL,0,0L); SendDlgItemMessage(hDlg,ID_LISTBOX, LB_GETTEXT,index, (LPARAM)(LPSTR *)str); i=0; //pointer the begining of string code while (str[i]&&(str[i]!=0x20)){ kbf.buffer[i]=str[i]; //get the string index code i++; } kbf.true_length=(WORD)i; //get code length read_mulu(); for (i=0x10; i<(mulu_true_length+0x10); i=i+mulu_record_length){ if (if_code_equ(i)){ p=(BYTE *)s_buf; p[i]|=0x80; write_mulu(); count=(i-0x10)/mulu_record_length; if (!read_data(count)) break; //break from the cycle out_svw[1]=0x2a; write_data(count,out_svw); SendDlgItemMessage(hDlg,ID_LISTBOX, LB_DELETESTRING, // add these new word index, // onto the listbox (LPARAM)((LPSTR *)str)); return(TRUE); } } MessageBox(hDlg, "删除操作失败", NULL, MB_OK | MB_ICONHAND); break; case IDOK: { HIMC hIMC; hIMC = ImmGetContext(hDlg); ImmSetOpenStatus(hIMC,TRUE); ImmDestroyContext(hIMC); ImmReleaseContext(hDlg,hIMC); } Return=NULL; EndDialog(hDlg, TRUE); return (TRUE); break; case IDCANCEL: Return=NULL; { HIMC hIMC; hIMC = ImmGetContext(hDlg); ImmSetOpenStatus(hIMC,TRUE); ImmDestroyContext(hIMC); ImmReleaseContext(hDlg,hIMC); } EndDialog(hDlg, TRUE); return (TRUE); case ID_NEWCHR: //1993.4.19 { HIMC hIMC; hIMC = ImmGetContext(hDlg); ImmSetOpenStatus(hIMC,TRUE); ImmReleaseContext(hDlg,hIMC); } break; case ID_SHU: //1993.4.19 { HIMC hIMC; hIMC = ImmGetContext(hDlg); ImmSetOpenStatus(hIMC,FALSE); ImmReleaseContext(hDlg,hIMC); } break; } break; case WM_INITDIALOG: // message: initialize hCrtDlg = hDlg; SendDlgItemMessage(hDlg, // dialog handle ID_NEWCHR, // where to send message EM_SETSEL, // select characters 0, // additional information MAKELONG(0, 0x7fff)); // entire contents SetFocus(GetDlgItem(hDlg, ID_NEWCHR)); listbox(hDlg); CenterWindow(hDlg); return (0); //##!!(NULL) Indicates the focus is set to a control case WM_PAINT: { PAINTSTRUCT ps; GetClientRect(hDlg, &Rect); //get the whole window area InvalidateRect(hDlg, &Rect, 1); hDC=BeginPaint(hDlg, &ps); Rect.left+=10;//5; Rect.top+=8;//5; Rect.right-=10;//5; Rect.bottom-=12;//5; DrawEdge(hDC, &Rect, EDGE_RAISED,/*EDGE_SUNKEN,*/ BF_RECT); EndPaint(hDlg, &ps); } break; case WM_DESTROY: { HIMC hIMC; hIMC = ImmGetContext(hDlg); ImmSetOpenStatus(hIMC,TRUE); ImmDestroyContext(hIMC); ImmReleaseContext(hDlg,hIMC); } return (TRUE); case WM_QUIT: case WM_CLOSE: Return=NULL; EndDialog(hDlg, TRUE); return (TRUE); } return FALSE; }