PAINT.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:11k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /*      PAINT.C                                                       */
  4. /*                                                                    */
  5. /*      Copyright (c) 1995-1997  Microsoft Corporation                */
  6. /*                                                                    */
  7. /**********************************************************************/
  8. #include "windows.h"
  9. #include "imm.h"
  10. #include "resource.h"
  11. #include "imeapps.h"
  12. #define DEBUG 1
  13. void SetAttrColor(HDC hDC, BYTE bAttr)
  14. {
  15.     switch (bAttr)
  16.     {
  17.         case ATTR_INPUT:
  18.             SetTextColor(hDC,RGB(0,0,0));
  19.             SetBkMode(hDC,TRANSPARENT);
  20.             break;
  21.         case ATTR_TARGET_CONVERTED:
  22.             SetTextColor(hDC,RGB(255,255,255));
  23.             SetBkMode(hDC,OPAQUE);
  24.             SetBkColor(hDC,RGB(0,0,255));
  25.             break;
  26.         case ATTR_CONVERTED:
  27.             SetTextColor(hDC,RGB(0,0,255));
  28.             SetBkMode(hDC,TRANSPARENT);
  29.             break;
  30.         case ATTR_TARGET_NOTCONVERTED:
  31.             SetTextColor(hDC,RGB(255,255,255));
  32.             SetBkMode(hDC,OPAQUE);
  33.             SetBkColor(hDC,RGB(0,255,0));
  34.             break;
  35.         case ATTR_INPUT_ERROR:
  36.             SetTextColor(hDC,RGB(255,255,0));
  37.             SetBkMode(hDC,TRANSPARENT);
  38.             break;
  39.         case ATTR_FIXEDCONVERTED:
  40.             SetTextColor(hDC,RGB(255,0,0));
  41.             SetBkMode(hDC,TRANSPARENT);
  42.             break;
  43.         default:
  44.             SetTextColor(hDC,RGB(0,0,0));
  45.             SetBkMode(hDC,TRANSPARENT);
  46.             break;
  47.     }
  48. }
  49. LRESULT HandlePaint(HWND hWnd,WPARAM wParam, LPARAM lParam)
  50. {
  51.     HDC hDC;
  52.     PAINTSTRUCT ps;
  53.     UINT i;
  54.     int x = ORG_X;
  55.     int y = ORG_Y;
  56.     SIZE sz;
  57.     HFONT hOldFont = 0;
  58.     HFONT hDefFont = GetStockObject(DEFAULT_GUI_FONT);
  59.     int height,defheight;
  60.     const char  szResult[] = "Result String";
  61.     const char  szComp[] = "Composition String";
  62.     RECT rc;
  63.     GetClientRect(hWnd,&rc);
  64.     hDC = BeginPaint(hWnd, &ps);
  65.     if (hFont)
  66.         hOldFont = SelectObject(hDC,hDefFont);
  67.     // Get the height of the default gui font.
  68.     GetTextExtentPoint(hDC,"A",1,&sz);
  69.     defheight = sz.cy + 1;
  70.     // Get the height of the font.
  71.     SelectObject(hDC,hFont);
  72.     GetTextExtentPoint(hDC,"A",1,&sz);
  73.     height = sz.cy + 1;
  74.     SelectObject(hDC,hDefFont);
  75.     SetTextColor(hDC,RGB(0,0,0));
  76.     SetBkMode(hDC,TRANSPARENT);
  77.     TextOut(hDC,ORG_X,y,szResult,lstrlen(szResult));
  78.     y += defheight;
  79.     if (Mylstrlen(szPaintResult))
  80.     {
  81.         x = ORG_X;
  82.         SelectObject(hDC,hFont);
  83.         SetTextColor(hDC,RGB(255,0,0));
  84.         SetBkMode(hDC,TRANSPARENT);
  85. #ifdef USEWAPI
  86.         TextOutW(hDC,x,y,szPaintResult,Mylstrlen(szPaintResult));
  87. #else
  88.         TextOut(hDC,x,y,szPaintResult,Mylstrlen(szPaintResult));
  89. #endif
  90.     }
  91.     y += height;
  92.     if (Mylstrlen(szPaintResultRead))
  93.     {
  94.         x = ORG_X;
  95.         SelectObject(hDC,hFont);
  96.         SetTextColor(hDC,RGB(255,0,0));
  97.         SetBkMode(hDC,TRANSPARENT);
  98. #ifdef USEWAPI
  99.         TextOutW(hDC,x,y,szPaintResultRead,Mylstrlen(szPaintResultRead));
  100. #else
  101.         TextOut(hDC,x,y,szPaintResultRead,Mylstrlen(szPaintResultRead));
  102. #endif
  103.     }
  104. #if 0
  105.     if (dwResultReadStrLen)
  106.     {
  107.         x = ORG_X;
  108.         SelectObject(hDC,hFont);
  109.         SetTextColor(hDC,RGB(0,0,0));
  110.         SetBkMode(hDC,TRANSPARENT);
  111.         if (dwResultReadClsLen)
  112.         {
  113.             dwResultReadCls[127] = 0;
  114.             i = 1;
  115.             SetTextColor(hDC,RGB(255,0,0));
  116.             while (dwResultReadCls[i] && dwResultReadCls[i-1] < dwResultReadStrLen)
  117.             {
  118.                 DWORD dwTextLen = dwResultReadCls[i] - dwResultReadCls[i-1];
  119.                 LPSTR lpStart = szResultReadStr + dwResultReadCls[i-1];
  120.                 TextOut(hDC,x,y,lpStart,dwTextLen);
  121.                 GetTextExtentPoint(hDC,lpStart,dwTextLen,&sz);
  122.                 x += sz.cx;
  123.                 TextOut(hDC,x,y,",",1);
  124.                 GetTextExtentPoint(hDC,",",1,&sz);
  125.                 x += (sz.cx + 2);
  126.                 i++;
  127.             }
  128.         }
  129.         else
  130.         {
  131.             SetTextColor(hDC,RGB(255,0,0));
  132.             SetBkMode(hDC,TRANSPARENT);
  133.             TextOut(hDC,x,y,szResultReadStr,dwResultReadStrLen);
  134.         }
  135.     }
  136. #endif
  137.     y += height;
  138.     SelectObject(hDC,hDefFont);
  139.     SetTextColor(hDC,RGB(0,0,0));
  140.     SetBkMode(hDC,TRANSPARENT);
  141.     TextOut(hDC,ORG_X,y,szComp,lstrlen(szComp));
  142.     y += defheight;
  143.     if (dwCompStrLen)
  144.     {
  145.         x = ORG_X;
  146.         SelectObject(hDC,hFont);
  147.         SetTextColor(hDC,RGB(0,0,0));
  148.         if (dwCompClsLen && dwCompAttrLen)
  149.         {
  150.             dwCompCls[127] = 0;
  151.             i = 1;
  152.           
  153.             while (dwCompCls[i] && dwCompCls[i-1] < dwCompStrLen)
  154.             {
  155.                 DWORD dwTextLen = dwCompCls[i] - dwCompCls[i-1];
  156.                 LPMYSTR lpStart = szCompStr + dwCompCls[i-1];
  157.                 SetAttrColor(hDC, bCompAttr[dwCompCls[i-1]]);
  158. #ifdef USEWAPI
  159.                 TextOutW(hDC,x,y,lpStart,dwTextLen);
  160.                 GetTextExtentPointW(hDC,lpStart,dwTextLen,&sz);
  161. #else
  162.                 TextOut(hDC,x,y,lpStart,dwTextLen);
  163.                 GetTextExtentPoint(hDC,lpStart,dwTextLen,&sz);
  164. #endif
  165.                 x += sz.cx;
  166.                 SetTextColor(hDC,RGB(0,0,0));
  167.                 SetBkMode(hDC,TRANSPARENT);
  168. #ifdef USEWAPI
  169.                 TextOutW(hDC,x,y,MYTEXT(","),1);
  170.                 GetTextExtentPointW(hDC,MYTEXT(","),1,&sz);
  171. #else
  172.                 TextOut(hDC,x,y,",",1);
  173.                 GetTextExtentPoint(hDC,",",1,&sz);
  174. #endif
  175.                 x += (sz.cx + 2);
  176.                 i++;
  177.             }
  178.         }
  179.         else
  180.         {
  181.             SetBkMode(hDC,TRANSPARENT);
  182. #ifdef USEWAPI
  183.             TextOutW(hDC,x,y,szCompStr,dwCompStrLen);
  184. #else
  185.             TextOut(hDC,x,y,szCompStr,dwCompStrLen);
  186. #endif
  187.         }
  188.     }
  189.     y += height;
  190.     if (dwCompReadStrLen)
  191.     {
  192.         x = ORG_X;
  193.         SelectObject(hDC,hFont);
  194.         SetTextColor(hDC,RGB(0,0,0));
  195.         SetBkMode(hDC,TRANSPARENT);
  196.         if (dwCompReadClsLen && dwCompReadAttrLen)
  197.         {
  198.             dwCompReadCls[127] = 0;
  199.             i = 1;
  200.             while (dwCompReadCls[i] && dwCompReadCls[i-1] < dwCompReadStrLen)
  201.             {
  202.                 DWORD dwTextLen = dwCompReadCls[i] - dwCompReadCls[i-1];
  203.                 LPMYSTR lpStart = szCompReadStr + dwCompReadCls[i-1];
  204.                 SetAttrColor(hDC, bCompReadAttr[dwCompReadCls[i-1]]);
  205. #ifdef USEWAPI
  206.                 TextOutW(hDC,x,y,lpStart,dwTextLen);
  207.                 GetTextExtentPointW(hDC,lpStart,dwTextLen,&sz);
  208. #else
  209.                 TextOut(hDC,x,y,lpStart,dwTextLen);
  210.                 GetTextExtentPoint(hDC,lpStart,dwTextLen,&sz);
  211. #endif
  212.                 x += sz.cx;
  213.                 SetTextColor(hDC,RGB(0,0,0));
  214.                 SetBkMode(hDC,TRANSPARENT);
  215. #ifdef USEWAPI
  216.                 TextOutW(hDC,x,y,MYTEXT(","),1);
  217.                 GetTextExtentPointW(hDC,MYTEXT(","),1,&sz);
  218. #else
  219.                 TextOut(hDC,x,y,",",1);
  220.                 GetTextExtentPoint(hDC,",",1,&sz);
  221. #endif
  222.                 x += (sz.cx + 2);
  223.                 i++;
  224.             }
  225.         }
  226.         else
  227.         {
  228.             SetBkMode(hDC,TRANSPARENT);
  229. #ifdef USEWAPI
  230.             TextOutW(hDC,x,y,szCompReadStr,dwCompReadStrLen);
  231. #else
  232.             TextOut(hDC,x,y,szCompReadStr,dwCompReadStrLen);
  233. #endif
  234.         }
  235.     }
  236.     y += height;
  237.     ptImeUIPos.y = y;
  238.     SelectObject(hDC,hOldFont);
  239.     EndPaint(hWnd,&ps);
  240.     return 1;
  241. }
  242. LRESULT HandleCandPaint(HWND hWnd,WPARAM wParam, LPARAM lParam)
  243. {
  244.     HDC hDC;
  245.     PAINTSTRUCT ps;
  246.     UINT i;
  247.     int x = ORG_X;
  248.     int y = ORG_Y;
  249.     SIZE sz;
  250.     HFONT hOldFont = 0;
  251.     HFONT hDefFont = GetStockObject(DEFAULT_GUI_FONT);
  252.     int height,defheight;
  253.     LPDWORD lpdwOffset;
  254.     RECT rect;
  255.     const char  szCand[] = "Candidate List";
  256.     const char  szCandNull[] = "";
  257.     const char  szCandRead[] = "Reading";
  258.     const char  szCandCode[] = "Code";
  259.     const char  szCandMean[] = "Meaning";
  260.     const char  szCandRadi[] = "Radical";
  261.     const char  szCandStrk[] = "Stroke";
  262.     GetClientRect(hWnd,&rect);
  263.     hDC = BeginPaint(hWnd, &ps);
  264.     if (!lpCandList)
  265.         goto pt_cand_10;
  266.     if (hFont)
  267.         hOldFont = SelectObject(hDC,hDefFont);
  268.     // Get the height of the default gui font.
  269.     GetTextExtentPoint(hDC,"A",1,&sz);
  270.     defheight = sz.cy + 1;
  271.     // Get the height of the font.
  272.     SelectObject(hDC,hFont);
  273.     GetTextExtentPoint(hDC,"A",1,&sz);
  274.     height = sz.cy + 1;
  275.     SelectObject(hDC,hDefFont);
  276.     SetTextColor(hDC,RGB(0,0,0));
  277.     SetBkMode(hDC,TRANSPARENT);
  278.     TextOut(hDC,ORG_X,y,szCand,lstrlen(szCand));
  279.     y += defheight;
  280.     switch (lpCandList->dwStyle)
  281.     {
  282.         case IME_CAND_READ:
  283.             TextOut(hDC,ORG_X,y,szCandRead,lstrlen(szCandRead));
  284.             break;
  285.         case IME_CAND_CODE:
  286.             TextOut(hDC,ORG_X,y,szCandCode,lstrlen(szCandCode));
  287.             break;
  288.         case IME_CAND_MEANING:
  289.             TextOut(hDC,ORG_X,y,szCandMean,lstrlen(szCandMean));
  290.             break;
  291.         case IME_CAND_RADICAL:
  292.             TextOut(hDC,ORG_X,y,szCandRadi,lstrlen(szCandRadi));
  293.             break;
  294.         case IME_CAND_STROKE:
  295.             TextOut(hDC,ORG_X,y,szCandStrk,lstrlen(szCandStrk));
  296.             break;
  297.         default:
  298.             break;
  299.     }
  300.     y += defheight;
  301.     if (!lpCandList->dwCount)
  302.         goto pt_cand_10;
  303.     lpdwOffset = &lpCandList->dwOffset[0];
  304.     lpdwOffset += lpCandList->dwPageStart;
  305.     for (i = lpCandList->dwPageStart;
  306.          (i < lpCandList->dwCount) && 
  307.          (i < lpCandList->dwPageStart + lpCandList->dwPageSize) &&
  308.          (y <= rect.bottom + height); i++)
  309.     {
  310.         LPSTR lpstr = (LPSTR)lpCandList + *lpdwOffset++;
  311.         x = ORG_X;
  312.         SelectObject(hDC,hFont);
  313.         if (i != lpCandList->dwSelection)
  314.         {
  315.             SetTextColor(hDC,RGB(0,0,0));
  316.             SetBkMode(hDC,TRANSPARENT);
  317.         }
  318.         else
  319.         {
  320.             SetTextColor(hDC,RGB(255,255,255));
  321.             SetBkColor(hDC,RGB(0,0,255));
  322.             SetBkMode(hDC,OPAQUE);
  323.         }
  324.         TextOut(hDC,x,y,lpstr,lstrlen(lpstr));
  325.         y += height;
  326.     }
  327.     SelectObject(hDC,hOldFont);
  328. pt_cand_10:
  329.     EndPaint(hWnd,&ps);
  330.     return 1;
  331. }