⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toascii.cpp

📁 ElipseNC3.1开发环境培训范例代码BO-DMO简单使用入门阶段_范例1.rar
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}


void PageUporDown(LPCOMPOSITIONSTRING  lpCompStr,BOOL pagedown)
{
    int i,j ,MaxCount,StartItem ,iTotalLen =0 ;
    TCHAR *pDes ;		
    char  *pCurPinyin;	

    if(pagedown){
	  if(lpImeL->iStartItem<1)           return ;	         //first page
	  if(lpImeL->iStartItem > lpImeL->iTotalItem)
	  	lpImeL->iStartItem = lpImeL->iTotalItem ;
	  
	  MaxCount = lpImeL->iStartItem%COMP_MAX_ITEM ;
  	  if(MaxCount == 0)   MaxCount = COMP_MAX_ITEM;
	  StartItem = lpImeL->iStartItem - MaxCount-COMP_MAX_ITEM;
	  if(StartItem<0)     	            return ;
         MaxCount = COMP_MAX_ITEM ;
	  lpImeL->iStartItem = StartItem;
	  pCurPinyin  =&(CurrentPy[StartItem+ MaxCount -1][0]);
    } else {
	  if(lpImeL->iStartItem >= lpImeL->iTotalItem)   return;//last page
	      
	  if(lpImeL->iStartItem<1) lpImeL->iStartItem = 0;
	  
	  if(lpImeL->iTotalItem -lpImeL->iStartItem <(COMP_MAX_ITEM-1)) {
       	  MaxCount = lpImeL->iTotalItem%COMP_MAX_ITEM ;    
      } else {
		  MaxCount = COMP_MAX_ITEM;  
	  }
      StartItem    = lpImeL->iStartItem;
	  pCurPinyin  =&( CurrentPy[StartItem][0]);
    }

    i  = 0;	 	
    j = MultiByteToWideChar( GetACP(),
		                     0,
		                     pCurPinyin,
		                     -1, 
		                     lpImeL->tComCurItem, 
		                     COMP_MAX_PYLEN);
    pDes = lpImeL->tComSelItem;
    while(i<COMP_MAX_PYLEN && i<j) {
       *pDes++  = lpImeL->tComCurItem[i];
	   i++;
    }
    pDes = ((LPUNAWORD)((LPBYTE)lpCompStr + lpCompStr->dwCompReadStrOffset));
    for(i=StartItem;i<StartItem+MaxCount;i++) {
        j = MultiByteToWideChar( GetACP(),
		                     0,
		                     &(CurrentPy[i][0]),
		                     -1, 
		                     pDes, 
		                     COMP_MAX_PYLEN);
        if(j>0) {
           pDes += (j-1);
           iTotalLen +=(j-1);
           *pDes =  0x20; 	
           pDes++;
           iTotalLen++;
        }
    }
    *((LPUNAWORD)((LPBYTE)lpCompStr + lpCompStr->dwCompReadAttrOffset )) =((ATTR_TARGET_CONVERTED << 8)|ATTR_TARGET_CONVERTED); 			 
    lpCompStr->dwCompReadStrLen = iTotalLen;	 
    lpImeL->iStartItem += MaxCount;
	  
    // composition string is reading string for some simple IMEs
    lpCompStr->dwCompStrLen = lpCompStr->dwCompReadStrLen;

    // composition/reading attribute length is equal to reading string length
    lpCompStr->dwCompReadAttrLen = lpCompStr->dwCompReadStrLen;
    lpCompStr->dwCompAttrLen = lpCompStr->dwCompStrLen;

    // delta start from previous cursor position
    lpCompStr->dwDeltaStart = lpCompStr->dwCursorPos;
  
    // set new cursor with next to the composition string
    lpCompStr->dwCursorPos = lpCompStr->dwCompStrLen;
}

void  DoSelectItemPre(UINT uVirtKey,LPCOMPOSITIONSTRING  lpCompStr)
{
	 TCHAR* pDest;
	 TCHAR *pSelItem;				  
	 TCHAR* pCurPingyin;				  
		 
	 if(!lpCompStr )        return ;

	 pCurPingyin =  (LPTSTR)((LPBYTE)lpCompStr + lpCompStr->dwCompStrOffset);  
	
	 pDest = wcsstr(pCurPingyin,lpImeL->tComSelItem);

	 if((pDest -pCurPingyin ) <1  && uVirtKey == VK_LEFT) {
        PageUporDown(lpCompStr,TRUE);
	 } else if ((DWORD)(pDest -pCurPingyin +1) >=(lpCompStr->dwCompStrLen-lstrlen(lpImeL->tComSelItem)) 
        && uVirtKey == VK_RIGHT) {
        PageUporDown(lpCompStr,FALSE);
	 } else {
        TCHAR* pCurItem = lpImeL->tComCurItem;
        pSelItem =	 lpImeL->tComSelItem;
        if(uVirtKey == VK_LEFT) {
        if((pDest -pCurPingyin ) >1) pDest -= 2; //first space
		while(pDest > pCurPingyin && (*pDest) != 32)		 
           pDest--;
		   if(pDest <= pCurPingyin)
		     pDest = pCurPingyin; 	
		   else	
             pDest++;
        while(pDest < (pCurPingyin+lpCompStr->dwCompStrLen) 
			  && (*pDest) != 32) {
           *pCurItem++ =*pSelItem++ = *pDest++;
        }
        } else {
           pDest += lstrlen(lpImeL->tComSelItem);
		   pDest++;
		   if(*pDest == 32 )  return ;	
		   
           while(pDest < (pCurPingyin+lpCompStr->dwCompStrLen) 
			     && (*pDest) != 32) {
              *pCurItem++ =*pSelItem++     = *pDest++;
           }
        }
        *pCurItem =0;
        *pSelItem = 0;
        }
}
 void DoSelectChinese(UINT uVirtKey,
 	                  HIMC hIMC,  
 	                  LPINPUTCONTEXT  lpIMC, 
 	                  LPPRIVCONTEXT lpImcP)
 {
 
       LPCANDIDATEINFO lpCandInfo;
       LPCANDIDATELIST lpCandList;

       // get lpCandInfo
       lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
       lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo + lpCandInfo->dwOffset[0]);

       if(uVirtKey == VK_LEFT) {
          if(lpCandList->dwSelection>0 && sImeG.iCandSelID <1) {
              sImeG.iCandSelID = CANDPERPAGE;
	          ChooseCand('-', lpIMC, lpCandInfo, lpImcP);
	          NotifyIME(hIMC, NI_CHANGECANDIDATELIST, 0, 0);   	
          }
		  if(sImeG.iCandSelID>0)   sImeG.iCandSelID--;
       } else {
		  if((lpCandList->dwCount-lpCandList->dwSelection)>CANDPERPAGE ) {
		      if( sImeG.iCandSelID< (CANDPERPAGE-1)) {
                  sImeG.iCandSelID++;		
			  } else {
		          ChooseCand('=', lpIMC, lpCandInfo, lpImcP);
		          NotifyIME(hIMC, NI_CHANGECANDIDATELIST, 0, 0);  
			      sImeG.iCandSelID = 0;		
			  }
		  } else {  
			  if((DWORD)sImeG.iCandSelID<(lpCandList->dwCount-lpCandList->dwSelection) -1)
                  sImeG.iCandSelID++;
		  }
			   
       }
       ImmUnlockIMCC(lpIMC->hCandInfo);
 }
		 
/**********************************************************************/
/* ImeToAsciiEx()                                                                                                */
/* Return Value:                                                                                                  */
/*      the number of translated message                                                                */
/**********************************************************************/
UINT WINAPI ImeToAsciiEx(
    UINT    uVirtKey,
    UINT    uScanCode,
    CONST   LPBYTE lpbKeyState,
    LPTRANSMSGLIST lpTransBuf,
    UINT    fuState,
    HIMC    hIMC)
{
    WORD                wCharCode;
    LPINPUTCONTEXT      lpIMC;
    LPCOMPOSITIONSTRING lpCompStr;
    LPPRIVCONTEXT       lpImcP;
    UINT                uNumMsg=0;
    int                      iRet;
    TCHAR        Temp  = 0;

    wCharCode = HIWORD(uVirtKey);
    uVirtKey = LOBYTE(uVirtKey);
	
    // hIMC=NULL?
    if (!hIMC) {
        uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
            wCharCode);
        return (uNumMsg);
    }

    // get lpIMC
    lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
    
    if (!lpIMC) {
        uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
            wCharCode);
        return (uNumMsg);
    }

    // get lpImcP
    lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
    
    if (!lpImcP) {
        ImmUnlockIMC(hIMC);
        uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
            wCharCode);
        return (uNumMsg);
    }

    // get lpCompStr and init
    if (lpImcP->fdwGcsFlag & (GCS_RESULTREAD|GCS_RESULT)) {
        lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC ->hCompStr);

        if (lpCompStr) {
            lpCompStr->dwResultStrLen = 0;
        }
        ImmUnlockIMCC(lpIMC->hCompStr);
        lpImcP->fdwGcsFlag = (DWORD)0;
    }

    // Now all composition realated information already pass to app
    // a brand new start

    // init lpImcP->fdwImeMsg
    lpImcP->fdwImeMsg = lpImcP->fdwImeMsg & (MSG_ALREADY_OPEN|
        MSG_ALREADY_START) | MSG_IN_IMETOASCIIEX;
    //__asm int 3;
    // Process Key(wCharCode)
    iRet = ProcessKey(wCharCode, uVirtKey, uScanCode, lpbKeyState, lpIMC, lpImcP);
    if (iRet == CST_BACKSPACE) {
        wCharCode = TEXT('\b');
	 Temp = lpImcP->bSeq[0];
	 iRet = CST_INPUT;
    }
	
    if(iRet == CST_INPUT){
        lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
        if(!lpCompStr)    return (CST_INVALID);
  	
        lpImcP->fdwImeMsg |= MSG_IMN_COMPOSITIONPOS;
        CompWord(wCharCode, lpIMC, lpCompStr, lpImcP);
		
	 {
      		int   cxBorder;
		cxBorder = GetSystemMetrics(SM_CXBORDER);
		lpImeL->rcCompText.right = lpImeL->rcCompText.left + sImeG.xChiCharWi *  ((COMP_MAX_ITEM *6 )/2);
		lpImeL->xCompWi=lpImeL->rcCompText.right+lpImeL->cxCompBorder*2+cxBorder*4+UI_CANDBTW*2;
        }
	 
        if (wCharCode == TEXT('\b')) {
	      if(Temp == lpImcP->bSeq[0])
	      {
	          if(Temp == 0)
	          {
	             lpImcP->fdwImeMsg |= MSG_BACKSPACE|MSG_END_COMPOSITION|MSG_ALREADY_START;
	          }
	      }
	      else
	      {
	         lpImcP->fdwImeMsg |= MSG_END_COMPOSITION|MSG_ALREADY_START;
	      }
        }
        ImmUnlockIMCC(lpIMC->hCompStr);
        // generate message
        uNumMsg = TranslateImeMessage(lpTransBuf, lpIMC, lpImcP);
    }else if(iRet == CST_ESCAPE ){ //exit t9 ime
        lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
        if(!lpCompStr)    return (CST_INVALID);
        lpImcP->fdwImeMsg |= MSG_IMN_COMPOSITIONPOS;
	 memset(	 lpImcP->bSeq,0,COMP_MAX_PYLEN);

        lpImeL->iTotalItem      = 0; 
	 memset(	lpImeL->tComSelItem,0,COMP_MAX_PYLEN);
	 memset(	lpImeL->tComCurItem,0,COMP_MAX_PYLEN);
        InitCompStr(lpCompStr);
        *((LPUNAWORD)((LPBYTE)lpCompStr + lpCompStr->dwCompReadStrOffset)) = 0;
        sImeG.bGetFocus    = FALSE;
        sImeG. iCandSelID  = 0;
        if (lpImcP->fdwImeMsg & (MSG_ALREADY_OPEN)) {
		ClearCand(lpIMC);
		lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg | MSG_CLOSE_CANDIDATE) &~(MSG_OPEN_CANDIDATE);
        }

	if(lpImcP->iImeState != CST_INIT) {
		lpImcP->iImeState = CST_INIT;
		lpCompStr->dwCompReadStrLen = lpCompStr->dwCompStrLen =
		lpCompStr->dwDeltaStart = lpCompStr->dwCursorPos;
	}

	if (lpImcP->fdwImeMsg & MSG_ALREADY_START) {
		lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg | MSG_END_COMPOSITION) & ~(MSG_START_COMPOSITION);
	}

	// reading string is composition string for some simple IMEs
	// delta start is the same as cursor position for backspace
	lpCompStr->dwCompStrLen =lpCompStr->dwCompReadStrLen; 
	lpCompStr->dwDeltaStart = lpCompStr->dwCursorPos;
	Finalize(lpIMC, lpCompStr, lpImcP);
       {
      		int   cxBorder;
		cxBorder = GetSystemMetrics(SM_CXBORDER);
		lpImeL->rcCompText.right = lpImeL->rcCompText.left + sImeG.xChiCharWi *  ((COMP_MAX_ITEM *6 )/2);
		lpImeL->xCompWi=lpImeL->rcCompText.right+lpImeL->cxCompBorder*2+cxBorder*4+UI_CANDBTW*2;
      }
      lpImcP->fdwImeMsg |= (MSG_END_COMPOSITION|MSG_ALREADY_START);
      ImmUnlockIMCC(lpIMC->hCompStr);
      // change to native mode  
      {
      		DWORD fdwConversion;
      		if (lpIMC->fdwConversion & IME_CMODE_NATIVE) {
	           fdwConversion = lpIMC->fdwConversion & ~(IME_CMODE_CHARCODE |IME_CMODE_NATIVE | IME_CMODE_EUDC);
      		}
      		ImmSetConversionStatus(hIMC, fdwConversion, lpIMC->fdwSentence);
      }
      //generate message
      uNumMsg = TranslateImeMessage(lpTransBuf, lpIMC, lpImcP);
    }else if(iRet == CST_PAGEUP){ 
		
    }else if(iRet == CST_PAGEDOWN){      
    
    }else if(iRet == CST_SELITEM){

    lpImcP->fdwImeMsg |= MSG_IMN_COMPOSITIONPOS; 
    if(wcscmp(lpImeL->tComCurItem,lpImeL->tComSelItem) != 0) {//selected item  
	   wcscpy(lpImeL->tComCurItem,lpImeL->tComSelItem);
	   Finalize(lpIMC, lpCompStr, lpImcP);                 // compsition
    }
	
    if(sImeG.bGetFocus){
	     DWORD  nStartItem = 0;
	     LPCANDIDATEINFO lpCandInfo;
	     LPCANDIDATELIST lpCandList;

	     lpImcP->fdwImeMsg = (MSG_IMN_COMPOSITIONPOS |MSG_ALREADY_OPEN); 
	     lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
	     if (lpCandInfo) {	
		    lpCandList = (LPCANDIDATELIST)  ((LPBYTE)lpCandInfo + lpCandInfo->dwOffset[0]);
		    nStartItem = lpCandList->dwSelection;
		    ImmUnlockIMCC(lpIMC->hCandInfo);	  
	     }
	     NotifyIME(hIMC, NI_SELECTCANDIDATESTR, 0,(sImeG.iCandSelID+nStartItem));	
	     sImeG.iCandSelID = 0;
	     sImeG.bGetFocus = FALSE;	
    } else {
	     sImeG.bGetFocus = TRUE;
	     lpImcP->fdwImeMsg  |=(MSG_IN_IMETOASCIIEX|MSG_COMPOSITION);
	     lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg |MSG_CHANGE_CANDIDATE) & ~(MSG_CLOSE_CANDIDATE);
    }
    uNumMsg = TranslateImeMessage(lpTransBuf, lpIMC, lpImcP);	  
    }else if(iRet == CST_SELITEMPRE){   //left or right          
	     lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
	     if(!lpCompStr)    return (CST_INVALID);
		 
	     if(sImeG.bGetFocus) {
	       DoSelectChinese(uVirtKey,hIMC, lpIMC,lpImcP);	
	       lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg | MSG_CHANGE_CANDIDATE) & ~(MSG_CLOSE_CANDIDATE);
		 } else {
              DoSelectItemPre(uVirtKey,lpCompStr);
 	       Finalize(lpIMC, lpCompStr, lpImcP);                 
	       lpImcP->fdwImeMsg |= ( MSG_IN_IMETOASCIIEX |MSG_IMN_COMPOSITIONPOS|MSG_COMPOSITION);
		 }
        
		 ImmUnlockIMCC(lpIMC->hCompStr);
         // generate message
		 uNumMsg = TranslateImeMessage(lpTransBuf, lpIMC, lpImcP);	   
    }else if (iRet == CST_INVALID_INPUT) {
    
        MessageBeep((UINT) -1);/////////1111111111111111
        uNumMsg = 0;
		
    } else {
         uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,wCharCode);
    }
    // reset lpImcP->fdwImeMsg
    
    lpImcP->fdwImeMsg &= (MSG_ALREADY_OPEN|MSG_ALREADY_START);
    lpImcP->fdwGcsFlag &= (GCS_RESULTREAD|GCS_RESULT);
    
    ImmUnlockIMCC(lpIMC->hPrivate);
    ImmUnlockIMC(hIMC);

    return (uNumMsg);
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -