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

📄 ui.c

📁 蒙古文输入法源码
💻 C
📖 第 1 页 / 共 3 页
字号:
            lpIMC->cfCandForm[0].dwStyle = CFS_DEFAULT;
        }


        lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
        if (!lpImcP) {
            GlobalUnlock(hUIPrivate);
            ImmUnlockIMC(hIMC);
            return;
        }

        // init ime properties & reset context
        {
            HKEY  hKeyCurrVersion;
            HKEY  hKeyGB;
            DWORD ValueType;
            DWORD ValueSize;
            LONG    retCode;

            retCode = OpenReg_PathSetup(&hKeyCurrVersion);
            if (retCode) {
            TCHAR    Buf[MAX_PATH];
                wsprintf (Buf, TEXT("Error: RegOpenKeyEx = %d"), retCode);
                MessageBox (lpIMC->hWnd, Buf, szWarnTitle, MB_OK | MB_ICONINFORMATION);
                return;
            }

            retCode = OpenReg_User (hKeyCurrVersion,
                               szImeRegName,
                               &hKeyGB);
            // query 光标跟随 value
            ValueSize = sizeof(DWORD);
            RegQueryValueEx (hKeyGB,szTrace ,
                            (DWORD)0,
                               (LPDWORD)&ValueType,
                            (LPBYTE)&sImeG.IC_Trace,
                            (LPDWORD)&ValueSize);
            if(RegQueryValueEx (hKeyGB, szRegRevKL,
                     NULL,
                     NULL,             //null-terminate string
                     (LPBYTE)&sImeG.hRevKL,              //&bData,
                     &ValueSize) != ERROR_SUCCESS)
            sImeG.hRevKL = NULL;
            if(RegQueryValueEx (hKeyGB, szRegRevMaxKey,
                     NULL,
                     NULL,             //null-terminate string
                     (LPBYTE)&sImeG.nRevMaxKey,              //&bData,
                     &ValueSize) != ERROR_SUCCESS)
            sImeG.hRevKL = NULL;
        

            // query 光标跟随 value
            ValueSize = sizeof(DWORD);
            RegQueryValueEx (hKeyGB, szRegImeIndex,
                            (DWORD)0,
                            (LPDWORD)&ValueType,
                            (LPBYTE)&dwRegImeIndex,
                            (LPDWORD)&ValueSize);

            RegCloseKey(hKeyGB);
            RegCloseKey(hKeyCurrVersion);

        }

        if(sImeL.dwRegImeIndex != dwRegImeIndex) {
        DWORD    dwConvMode;
        int        cxBorder, cyBorder;

            //change current IME index
            dwConvMode = lpIMC->fdwConversion ^ (IME_CMODE_INDEX_FIRST << sImeL.dwRegImeIndex);
            sImeL.dwRegImeIndex = dwRegImeIndex;
            szImeName = pszImeName[dwRegImeIndex];
            dwConvMode |= (IME_CMODE_INDEX_FIRST << dwRegImeIndex);
            // re-caculate statusuidata
            cxBorder = GetSystemMetrics(SM_CXBORDER);
            cyBorder = GetSystemMetrics(SM_CYBORDER);
            InitStatusUIData(cxBorder, cyBorder);

            ImmSetConversionStatus(hIMC, dwConvMode, lpIMC->fdwSentence);
        }

        if(sImeG.IC_Trace != SaTC_Trace) {
            int UI_MODE;

            lpImcP->iImeState = CST_INIT;
            CompCancel(hIMC, lpIMC);
            
            // init fields of hPrivate
            lpImcP->fdwImeMsg = (DWORD)0;
            lpImcP->dwCompChar = (DWORD)0;
            lpImcP->fdwGcsFlag = (DWORD)0;
            lpImcP->uSYHFlg = 0x00000000;
            lpImcP->uDYHFlg = 0x00000000;

            // change compwnd size

            // init fields of hIMC
            lpIMC->fOpen = TRUE;

            SendMessage(GetCandWnd(hUIWnd), WM_DESTROY, (WPARAM)0, (LPARAM)0);
            
            // set cand window data
            if(sImeG.IC_Trace) {
                UI_MODE = BOX_UI;
            } else {
                POINT ptSTFixPos;
            
    
                UI_MODE = LIN_UI;
                ptSTFixPos.x = 0;
                ptSTFixPos.y = rcWorkArea.bottom - sImeG.yStatusHi;
                ImmSetStatusWindowPos(hIMC, (LPPOINT)&ptSTFixPos);
            }
            
            InitCandUIData(
                GetSystemMetrics(SM_CXBORDER),
                GetSystemMetrics(SM_CYBORDER), UI_MODE);
        }
            
        SaTC_Trace = sImeG.IC_Trace;

        // init Caps
        {/////////////处理,蒙文与英文转换,改变成用SHIFT
            //BYTE  lpbKeyState[256];
            DWORD fdwConversion;

            //GetKeyboardState(lpbKeyState);
            //if (lpbKeyState[VK_CAPITAL] & 0x01) {
                // 10.11 add
            //    uCaps = 1;
                // change to alphanumeric mode
            //    fdwConversion = lpIMC->fdwConversion & ~(IME_CMODE_CHARCODE |
            //        IME_CMODE_NATIVE | IME_CMODE_EUDC);
            //} else {
                // change to native mode
                if(uCaps == 0) {
                    fdwConversion = (lpIMC->fdwConversion | IME_CMODE_NATIVE) &
                        ~(IME_CMODE_CHARCODE | IME_CMODE_EUDC);
					uCaps = 1;
                } else {
                    //fdwConversion = lpIMC->fdwConversion;
				    fdwConversion = lpIMC->fdwConversion & ~(IME_CMODE_CHARCODE |
					    IME_CMODE_NATIVE | IME_CMODE_EUDC);
					uCaps = 0;

                }
             //   uCaps = 0;
            //}
            ImmSetConversionStatus(hIMC, fdwConversion, lpIMC->fdwSentence);
        }

        if ((lpIMC->cfCompForm.dwStyle & CFS_FORCE_POSITION)
            && (sImeG.IC_Trace)) {
            POINT ptNew;            // new position of UI
            POINT ptSTWPos;

            ImmGetStatusWindowPos(hIMC, (LPPOINT)&ptSTWPos);

            ptNew.x = ptSTWPos.x + sImeG.xStatusWi + UI_MARGIN;
            if((ptSTWPos.x + sImeG.xStatusWi + sImeG.xCandWi + lpImeL->xCompWi + 2 * UI_MARGIN) >=
              rcWorkArea.right) { 
                ptNew.x = ptSTWPos.x - lpImeL->xCompWi - UI_MARGIN;
            }
            ptNew.x += lpImeL->cxCompBorder;
            ptNew.y = ptSTWPos.y + lpImeL->cyCompBorder;
            lpIMC->cfCompForm.ptCurrentPos = ptNew;

            ScreenToClient(lpIMC->hWnd, &lpIMC->cfCompForm.ptCurrentPos);
            lpIMC->cfCompForm.dwStyle = CFS_DEFAULT;
        }
    } else {
        lpUIPrivate->fdwSetContext &= ~ISC_SETCONTEXT_UI;
    }

    GlobalUnlock(hUIPrivate);

    UIPaint(hUIWnd);

    ImmUnlockIMC(hIMC);
    return;
}


/**********************************************************************/
/* GetCompWindow()                                                    */
/**********************************************************************/
LRESULT PASCAL GetCompWindow(
    HWND              hUIWnd,
    LPCOMPOSITIONFORM lpCompForm)
{
    HWND hCompWnd;
    RECT rcCompWnd;

    hCompWnd = GetCompWnd(hUIWnd);

    if (!hCompWnd) {
        return (1L);
    }

    if (!GetWindowRect(hCompWnd, &rcCompWnd)) {
        return (1L);
    }

    lpCompForm->dwStyle = CFS_POINT|CFS_RECT;
    lpCompForm->ptCurrentPos = *(LPPOINT)&rcCompWnd;
    lpCompForm->rcArea = rcCompWnd;

    return (0L);
}

/**********************************************************************/
/* SelectIME()                                                        */
/**********************************************************************/
void PASCAL SelectIME(          // switch IMEs
    HWND hUIWnd,
    BOOL fSelect)
{
    if (!fSelect) {
        ShowUI(hUIWnd, SW_HIDE);
    } else {

        ShowUI(hUIWnd, SW_SHOWNOACTIVATE);
          
    }

    return;
}

/**********************************************************************/
/* UIPaint()                                                          */
/**********************************************************************/
LRESULT PASCAL UIPaint(
    HWND        hUIWnd)
{
    PAINTSTRUCT ps;
    MSG         sMsg;
    HGLOBAL     hUIPrivate;
    LPUIPRIV    lpUIPrivate;

    // for safety
    BeginPaint(hUIWnd, &ps);
    EndPaint(hUIWnd, &ps);

    // some application will not remove the WM_PAINT messages
    PeekMessage(&sMsg, hUIWnd, WM_PAINT, WM_PAINT, PM_REMOVE|PM_NOYIELD);

    hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
    if (!hUIPrivate) {
        return (0L);
    }

    lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
    if (!lpUIPrivate) {
        return (0L);
    }

    if (lpUIPrivate->fdwSetContext & ISC_SETCONTEXT_UI) {
        ShowUI(hUIWnd, SW_SHOWNOACTIVATE);
    } else {
        ShowUI(hUIWnd, SW_HIDE);
    }

    GlobalUnlock(hUIPrivate);

    return (0L);
}

/**********************************************************************/
/* UIWndProc()                                                        */
/**********************************************************************/
LRESULT CALLBACK UIWndProc(
    HWND   hUIWnd,
    UINT   uMsg,
    WPARAM wParam,
    LPARAM lParam)
{

    switch (uMsg) {
    case WM_CREATE:
        CreateUIWindow(hUIWnd);
        break;
    case WM_DESTROY:
        DestroyUIWindow(hUIWnd);
        break;
    case WM_IME_STARTCOMPOSITION:
        // you can create a window as the composition window here
        StartComp(hUIWnd);
        break;
    case WM_IME_COMPOSITION:
        if (!sImeG.IC_Trace) {
        } else if (lParam & GCS_RESULTSTR) {
            MoveDefaultCompPosition(hUIWnd);
        } else {
        }

        {
            HWND hCompWnd;
			HWND hCandWnd;

            hCompWnd = GetCompWnd(hUIWnd);
			hCandWnd = GetCandWnd(hUIWnd);
            if (hCompWnd) {
                RECT rcRect;

				//__asm int 3;
                rcRect = lpImeL->rcCompText;
                // off by 1
                rcRect.right += 1;
                rcRect.bottom += 1;

				MoveWindow( hCompWnd, 
					lpImeL->ptNewComp.x, lpImeL->ptNewComp.y , lpImeL->xCompWi, lpImeL->yCompHi,
					TRUE);

                RedrawWindow(hCompWnd, &rcRect, NULL, RDW_INVALIDATE);

            }
			if( hCandWnd )
			{
				MoveWindow( hCandWnd, 
					lpImeL->ptNewComp.x + lpImeL->xCompWi + 5, lpImeL->ptNewComp.y + 1,
                     sImeG.xCandWi, sImeG.yCandHi, TRUE);
			}
        }
        break;
    case WM_IME_ENDCOMPOSITION:
        // you can destroy the composition window here
        EndComp(hUIWnd);
        break;
    case WM_IME_NOTIFY:
        NotifyUI(hUIWnd, wParam, lParam);
        break;
    case WM_IME_SETCONTEXT:
        SetContext(hUIWnd, (BOOL)wParam, lParam);
        
        if (wParam && GetWindowLongPtr(hUIWnd, IMMGWLP_IMC))
            SetWindowPos(hUIWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOMOVE);

        break;
    case WM_IME_CONTROL:
        switch (wParam) {
        case IMC_GETCANDIDATEPOS:
            return (1L);                    // not implemented yet
        case IMC_GETCOMPOSITIONFONT:
            return (1L);                    // not implemented yet
        case IMC_GETCOMPOSITIONWINDOW:
            return GetCompWindow(hUIWnd, (LPCOMPOSITIONFORM)lParam);
        case IMC_GETSTATUSWINDOWPOS:
            {
                HWND   hStatusWnd;
                RECT   rcStatusWnd;
                LPARAM lParam;

                hStatusWnd = GetStatusWnd(hUIWnd);
                if (!hStatusWnd) {
                    return (0L);    // fail, return (0, 0)?
                }

                if (!GetWindowRect(hStatusWnd, &rcStatusWnd)) {
                     return (0L);    // fail, return (0, 0)?
                }

                lParam = MAKELRESULT(rcStatusWnd.left, rcStatusWnd.top);

                return (lParam);
            }
            return (0L);
        case IMC_SETSTATUSWINDOWPOS:
            {
                HIMC            hIMC;
                LPINPUTCONTEXT  lpIMC;
                LPPRIVCONTEXT   lpImcP;
                //COMPOSITIONFORM CompForm;
                POINT           ptPos;
                RECT            rcWorkArea;

#ifdef MUL_MONITOR
                rcWorkArea = ImeMonitorWorkAreaFromWindow(hUIWnd);
#else
                rcWorkArea = sImeG.rcWorkArea;
#endif

                ptPos.x = ((LPPOINTS)&lParam)->x;
                ptPos.y = ((LPPOINTS)&lParam)->y;

                hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
                if (!hIMC) {
                    return (1L);
                }

                if(!ImmSetStatusWindowPos(hIMC, &ptPos)) {
                    return (1L);
                }

                // set comp window position when TraceCuer
                lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
                if (!lpIMC) {
                    return (1L);
                }

                lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
                if (!lpImcP) {
                    return (1L);
                }

                if(!sImeG.IC_Trace) {
                    lpIMC->cfCompForm.dwStyle = CFS_RECT;
                    lpIMC->cfCompForm.ptCurrentPos.x = ptPos.x + sImeG.xStatusWi + UI_MARGIN;
                    lpIMC->cfCompForm.ptCurrentPos.y = ptPos.y;
                    CopyRect(&lpIMC->cfCompForm.rcArea, &rcWorkArea);

                    ScreenToClient(lpIMC->hWnd, &lpIMC->cfCompForm.ptCurrentPos);
                    // set composition window to the new poosition
                    PostMessage(GetCompWnd(hUIWnd), WM_IME_NOTIFY, IMN_SETCOMPOSITIONWINDOW, 0);

                }

                ImmUnlockIMCC(lpIMC->hPrivate);
                ImmUnlockIMC(hIMC);

                return (0L);
            }
            return (1L);
        default:
            return (1L);
        }
        break;
    case WM_IME_COMPOSITIONFULL:
        return (0L);
    case WM_IME_SELECT:
//#if  defined(LATER)
        SetContext(hUIWnd, (BOOL)wParam, 0);
//#else
//        SelectIME(hUIWnd, (BOOL)wParam);
//#endif
        return (0L);
    case WM_MOUSEACTIVATE:
        return (MA_NOACTIVATE);
    case WM_PAINT:
        return UIPaint(hUIWnd);
    default:
        return DefWindowProc(hUIWnd, uMsg, wParam, lParam);
    }
    return (0L);
}

void DrawConvexRect(HDC hDC, int x1, int y1, int x2, int y2)
{
    HPEN hPen, hOldPen;
    
    SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
    SelectObject(hDC, GetStockObject(WHITE_PEN));
    MoveToEx(hDC, x1, y1,NULL);
    LineTo(hDC, x2, y1);
    MoveToEx(hDC, x1, y1,NULL);
    LineTo(hDC, x1, y2);
    hPen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
    hOldPen = SelectObject (hDC, hPen);
    MoveToEx(hDC, x2-1, y2-1,NULL);
    LineTo(hDC, x2-1, y1);
    MoveToEx(hDC, x2-1, y2-1,NULL);
    LineTo(hDC, x1, y2-1);
    SelectObject(hDC, hOldPen);
    DeleteObject(hPen);          
}

void DrawConvexRectP(HDC hDC, int x1, int y1, int x2, int y2)
{
    HPEN hPen, hOldPen;
    
    SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
    SelectObject(hDC, GetStockObject(WHITE_PEN));
    MoveToEx(hDC, x1, y1,NULL);
    LineTo(hDC, x2 - 1, y1);
    MoveToEx(hDC, x1, y1,NULL);
    LineTo(hDC, x1, y2 - 1);
    hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
    hOldPen = SelectObject (hDC, hPen);
    MoveToEx(hDC, x2-1, y2-1,NULL);
    LineTo(hDC, x2-1, y1);
    MoveToEx(hDC, x2-1, y2-1,NULL);
    LineTo(hDC, x1, y2-1);
    SelectObject(hDC, hOldPen);
    DeleteObject(hPen);          
}

void DrawConcaveRect(HDC hDC, int x1, int y1, int x2, int y2)
{
    HPEN hLtPen = CreatePen(PS_SOLID, 1, 0x00808080);
    HPEN OldPen = SelectObject(hDC, hLtPen);
    MoveToEx(hDC, x1, y1,NULL);
    LineTo(hDC, x2, y1);
    MoveToEx(hDC, x1, y1,NULL);
    LineTo(hDC, x1, y2);
    SelectObject(hDC, GetStockObject(WHITE_PEN));
    MoveToEx(hDC, x2  , y2,NULL);
    LineTo(hDC, x2  , y1-1);
    MoveToEx(hDC, x2  , y2,NULL);
    LineTo(hDC, x1-1, y2);
    SelectObject(hDC, OldPen);
    DeleteObject(hLtPen);     
}


⌨️ 快捷键说明

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