home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winui / input / ime / imeapps / setcomp.c < prev    next >
C/C++ Source or Header  |  1997-09-11  |  5KB  |  200 lines

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /*      comp.C                                                        */
  4. /*                                                                    */
  5. /**********************************************************************/
  6.  
  7. #include "windows.h"
  8. #include "imm.h"
  9. #include "resource.h"
  10. #include "imeapps.h"
  11.  
  12. DWORD GetTargetClause()
  13. {
  14.     int nMaxClause = (int)(dwCompClsLen / sizeof(DWORD)) - 1;
  15.     int nCnt;
  16.  
  17.  
  18.     if (nMaxClause <= 0)
  19.         return (DWORD)-1L;
  20.     
  21.     for (nCnt = 0; nCnt < nMaxClause; nCnt++)
  22.     {
  23.         DWORD dwCls = dwCompCls[nCnt];
  24.  
  25.         if ((bCompAttr[dwCompCls[nCnt]] == ATTR_TARGET_CONVERTED) ||
  26.             (bCompAttr[dwCompCls[nCnt]] == ATTR_TARGET_NOTCONVERTED))
  27.             return nCnt;
  28.     }
  29.  
  30.     return (DWORD)-1L;
  31. }
  32.  
  33. LRESULT HandleChangeAttr(HWND hWnd,BOOL fNext)
  34. {
  35.     BYTE bAttr[512];
  36.     BYTE bAttrRead[512];
  37.     UINT i,j;
  38.     UINT uClause;
  39.     UINT uMaxClause;
  40.     UINT uCnt;
  41.     UINT uCntRead;
  42.     BYTE bAt;
  43.     BOOL fAttrOK = FALSE;
  44.     BOOL fAttrReadOK = FALSE;
  45.     HIMC hIMC;
  46.     BOOL bRet = FALSE;
  47.  
  48.  
  49.     uMaxClause = (dwCompClsLen / sizeof(DWORD)) - 1;
  50.     uClause = GetTargetClause();
  51.  
  52.     if (uClause == (DWORD)-1L)
  53.     {
  54.          return 0L;
  55.     }
  56.  
  57.     if (fNext)
  58.     {
  59.         if (uClause + 1 <= uMaxClause)
  60.             uClause++;
  61.         else
  62.             return 0L;
  63.     }
  64.     else
  65.     {
  66.         if (uClause > 0)
  67.             uClause--;
  68.         else
  69.             return 0L;
  70.     }
  71.  
  72.  
  73.     uCnt = 0;
  74.  
  75.     if (uClause < uMaxClause)
  76.     {
  77.         for (i=0; i < uMaxClause; i++)
  78.         {
  79.             if (i == uClause)
  80.             {
  81.                 switch (bCompAttr[dwCompCls[i]])
  82.                 {
  83.                     case ATTR_INPUT:
  84.                         bAt = ATTR_TARGET_NOTCONVERTED;
  85.                         break;
  86.                         break;
  87.                     case ATTR_CONVERTED:
  88.                         bAt = ATTR_TARGET_CONVERTED;
  89.                         break;
  90.                     default:
  91.                         bAt = bCompAttr[dwCompCls[i]];
  92.                         break;
  93.                 }
  94.             }
  95.             else
  96.             {
  97.                 switch (bCompAttr[dwCompCls[i]])
  98.                 {
  99.                     case ATTR_TARGET_CONVERTED:
  100.                         bAt = ATTR_CONVERTED;
  101.                         break;
  102.                         break;
  103.                     case ATTR_TARGET_NOTCONVERTED:
  104.                         bAt = ATTR_INPUT;
  105.                         break;
  106.                     default:
  107.                         bAt = bCompAttr[dwCompCls[i]];
  108.                         break;
  109.                 }
  110.             }
  111.  
  112.             for (j = 0; j < (dwCompCls[i+1] - dwCompCls[i]); j++)
  113.             {
  114.                 bAttr[uCnt++] = bAt;
  115.             }
  116.         }
  117.         fAttrOK = TRUE;
  118.     }
  119.  
  120.     uCntRead = 0;
  121.  
  122.     if (uClause < uMaxClause)
  123.     {
  124.         for (i=0; i < uMaxClause; i++)
  125.         {
  126.             if (i == uClause)
  127.             {
  128.                 switch (bCompReadAttr[dwCompReadCls[i]])
  129.                 {
  130.                     case ATTR_INPUT:
  131.                         bAt = ATTR_TARGET_NOTCONVERTED;
  132.                         break;
  133.                         break;
  134.                     case ATTR_CONVERTED:
  135.                         bAt = ATTR_TARGET_CONVERTED;
  136.                         break;
  137.                     default:
  138.                         bAt = bCompReadAttr[dwCompReadCls[i]];
  139.                         break;
  140.                 }
  141.             }
  142.             else
  143.             {
  144.                 switch (bCompReadAttr[dwCompReadCls[i]])
  145.                 {
  146.                     case ATTR_TARGET_CONVERTED:
  147.                         bAt = ATTR_CONVERTED;
  148.                         break;
  149.                         break;
  150.                     case ATTR_TARGET_NOTCONVERTED:
  151.                         bAt = ATTR_INPUT;
  152.                         break;
  153.                     default:
  154.                         bAt = bCompReadAttr[dwCompReadCls[i]];
  155.                         break;
  156.                 }
  157.             }
  158.  
  159.             for (j = 0; j < (dwCompReadCls[i+1] - dwCompReadCls[i]); j++)
  160.             {
  161.                 bAttrRead[uCntRead++] = bAt;
  162.             }
  163.         }
  164.         fAttrReadOK = TRUE;
  165.     }
  166.  
  167.  
  168.     if (fAttrReadOK && fAttrOK)
  169.     {
  170.         hIMC = ImmGetContext(hWndCompStr);
  171. #ifdef USEWAPI
  172.         bRet = ImmSetCompositionStringW(hIMC,SCS_CHANGEATTR,bAttr,uCnt,
  173.                                                     bAttrRead,uCntRead);
  174. #else
  175.         bRet = ImmSetCompositionString(hIMC,SCS_CHANGEATTR,bAttr,uCnt,
  176.                                                     bAttrRead,uCntRead);
  177. #endif
  178.         // bRet = ImmSetCompositionString(hIMC,SCS_CHANGEATTR,NULL,0,
  179.         //                                             bAttrRead,uCntRead);
  180.         // bRet = ImmSetCompositionString(hIMC,SCS_CHANGEATTR,bAttr,uCnt,
  181.         //                                             NULL,0);
  182.         ImmReleaseContext(hWndCompStr,hIMC);
  183.     }
  184.     else
  185.     {
  186. #ifdef DEBUG
  187.         OutputDebugString("Can not call ImmSetCompositionString\r\n");
  188.         bRet = TRUE;
  189. #endif
  190.     }
  191.  
  192. #ifdef DEBUG
  193.     if (!bRet)
  194.         OutputDebugString("ImmSetCompositionString return FALSE\r\n");
  195. #endif
  196.  
  197.  
  198.     return 1;
  199. }
  200.