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

📄 statusui.cpp

📁 基于Pocket PC的简体中文拼音输入法中的用户接口部分的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

#include <windows.h>
#include <imm.h>
#include <string.h>
#include "uipriv.h"

#define SPACING					3

extern PPOINT pptStatusPos;
extern void GetWorkArea(LPRECT lprcWorkArea);

void PASCAL DrawDragBorder(HWND hWnd, LONG lCursorPos, LONG lCursorOffset, RECT rcWorkArea)
{
    HDC  hDC;
    int  cxBorder, cyBorder;
    int  x, y;
    RECT rcWnd;

    cxBorder = GetSystemMetrics(SM_CXBORDER);   // width of border
    cyBorder = GetSystemMetrics(SM_CYBORDER);   // height of border

    // get cursor position
    x = (*(LPPOINTS)&lCursorPos).x;
    y = (*(LPPOINTS)&lCursorPos).y;

    // calculate the org by the offset
    x -= (*(LPPOINTS)&lCursorOffset).x;
    y -= (*(LPPOINTS)&lCursorOffset).y;

    // check for the min boundary of the display
    if (x < rcWorkArea.left) {
        x = rcWorkArea.left;
    }

    if (y < rcWorkArea.top) {
        y = rcWorkArea.top;
    }

    // check for the max boundary of the display
    GetWindowRect(hWnd, &rcWnd);

    if (x + rcWnd.right - rcWnd.left > rcWorkArea.right)
        x = rcWorkArea.right - (rcWnd.right - rcWnd.left);

    if (y + rcWnd.bottom - rcWnd.top > rcWorkArea.bottom)
        y = rcWorkArea.bottom - (rcWnd.bottom - rcWnd.top);

    // draw the moving track
    hDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
    SelectObject(hDC, GetStockObject(GRAY_BRUSH));

    // ->
    PatBlt(hDC, x, y, rcWnd.right - rcWnd.left - cxBorder, cyBorder,
        PATINVERT);
    // v
    PatBlt(hDC, x, y + cyBorder, cxBorder, rcWnd.bottom - rcWnd.top -
        cyBorder, PATINVERT);
    // _>
    PatBlt(hDC, x + cxBorder, y + rcWnd.bottom - rcWnd.top,
        rcWnd.right - rcWnd.left - cxBorder, -cyBorder, PATINVERT);
    //  v
    PatBlt(hDC, x + rcWnd.right - rcWnd.left, y,
        - cxBorder, rcWnd.bottom - rcWnd.top - cyBorder, PATINVERT);

    DeleteDC(hDC);
    return;
}

/**********************************************************************/
/* GetStatusWnd                                                       */
/* Return Value :                                                     */
/*      window handle of status window                                */
/**********************************************************************/
HWND PASCAL GetStatusWnd(HWND hUIWnd)                // UI window
{
    HLOCAL   hUIPrivate;
    LPUIPRIV lpUIPrivate;
    HWND     hStatusWnd;

    hUIPrivate = (HLOCAL)GetWindowLong(hUIWnd, IMMGWL_PRIVATE);
    if (!hUIPrivate) 
    	return (HWND)NULL;

    lpUIPrivate = (LPUIPRIV)LocalLock(hUIPrivate);
    if (!lpUIPrivate) 
    	return (HWND)NULL;

    hStatusWnd = lpUIPrivate->hStatusWnd;

    LocalUnlock(hUIPrivate);

    return (hStatusWnd);
}

/**********************************************************************/
/* AdjustStatusBoundary()                                             */
/**********************************************************************/
void PASCAL AdjustStatusBoundary(LPPOINTS lppt,	HWND hUIWnd)
{
    LPUIPRIV        lpUIPrivate;

    lpUIPrivate = (LPUIPRIV)GetWindowLong(hUIWnd, IMMGWL_PRIVATE);
    if (lpUIPrivate->hStatusWnd == NULL)
    	return;
    // display boundary check
    if (lppt->x < g_sImeUIG.rcWorkArea.left) {
    	lppt->x = (short)g_sImeUIG.rcWorkArea.left;
    } 
    else if (lppt->x + lpUIPrivate->nStatusWidth > g_sImeUIG.rcWorkArea.right) {
    	lppt->x = (short)(g_sImeUIG.rcWorkArea.right - lpUIPrivate->nStatusWidth);
    }

    if (lppt->y < g_sImeUIG.rcWorkArea.top) {
    	lppt->y = (short)g_sImeUIG.rcWorkArea.top;
    } 
    else if (lppt->y + lpUIPrivate->nStatusHeight > g_sImeUIG.rcWorkArea.bottom) {
    	lppt->y = (short)(g_sImeUIG.rcWorkArea.bottom - lpUIPrivate->nStatusHeight);
    }
    return;
}

/**********************************************************************/
/* SetStatusWindowPos()                                               */
/**********************************************************************/
LRESULT PASCAL SetStatusWindowPos(HWND hStatusWnd)
{
    HWND           hUIWnd;
    HIMC           hIMC;
    LPINPUTCONTEXT lpIMC;
    POINTS         ptPos;

    hUIWnd = GetWindow(hStatusWnd, GW_OWNER);

    hIMC = (HIMC)GetWindowLong(hUIWnd, IMMGWL_IMC);
    if (!hIMC)
    	return (1L);

    lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
    if (!lpIMC) 
    	return (1L);


    ptPos.x = (short)lpIMC->ptStatusWndPos.x;
    ptPos.y = (short)lpIMC->ptStatusWndPos.y;

    // display boundary adjust
    AdjustStatusBoundary(&ptPos, hUIWnd);

	pptStatusPos->x = ptPos.x;
	pptStatusPos->y = ptPos.y;
    SetWindowPos(hStatusWnd, NULL,
                 ptPos.x, ptPos.y,
                 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);

    ImmUnlockIMC(hIMC);

    return (0L);
}

/**********************************************************************/
/* ShowStatus()                                                       */
/**********************************************************************/
void PASCAL ShowStatus( HWND hUIWnd, int  nShowStatusCmd)
{
    HLOCAL   hUIPrivate;
    LPUIPRIV lpUIPrivate;
    HIMC           hIMC;
    LPINPUTCONTEXT lpIMC;

    hUIPrivate = (HLOCAL)GetWindowLong(hUIWnd, IMMGWL_PRIVATE);
    if (!hUIPrivate)
    	return;

    lpUIPrivate = (LPUIPRIV)LocalLock(hUIPrivate);
    if (!lpUIPrivate) 
    	return;
    	
    hIMC = (HIMC)GetWindowLong(hUIWnd, IMMGWL_IMC);
    if (!hIMC) {
    	LocalUnlock(hUIPrivate);
    	return;
    }
    
    lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);

    if (lpUIPrivate->hStatusWnd) {
		if (lpUIPrivate->nShowStatusCmd != nShowStatusCmd) {
			GetWorkArea(&g_sImeUIG.rcWorkArea);
			if (lpIMC) {
				if (pptStatusPos->x >= 0 && pptStatusPos->y >= 0) {
					lpIMC->ptStatusWndPos.x = pptStatusPos->x;
					lpIMC->ptStatusWndPos.y = pptStatusPos->y;
				}
				else {
					pptStatusPos->x = lpIMC->ptStatusWndPos.x;
					pptStatusPos->y = lpIMC->ptStatusWndPos.y;
				}
		    	ImmUnlockIMC(hIMC);
			}
			
			SetStatusWindowPos(lpUIPrivate->hStatusWnd);
			ShowWindow(lpUIPrivate->hStatusWnd, nShowStatusCmd);
			lpUIPrivate->nShowStatusCmd = nShowStatusCmd;
	    }
    }

    LocalUnlock(hUIPrivate);

    return;
}

/**********************************************************************/
/* OpenStatus()                                                       */
/**********************************************************************/
void PASCAL OpenStatus( HWND hUIWnd)
{
    HLOCAL         hUIPrivate;
    LPUIPRIV       lpUIPrivate;
    HIMC           hIMC;
    LPINPUTCONTEXT lpIMC;
    POINT          ptPos;
    int            nShowStatusCmd;

    hUIPrivate = (HLOCAL)GetWindowLong(hUIWnd, IMMGWL_PRIVATE);
    if (!hUIPrivate) 
    	return;

    lpUIPrivate = (LPUIPRIV)LocalLock(hUIPrivate);
    if (!lpUIPrivate) 
    	return;

    if (!lpUIPrivate->hStatusWnd) {
        lpUIPrivate->hStatusWnd = CreateWindowEx(WS_EX_NOACTIVATE|WS_EX_TOPMOST|WS_EX_TOOLWINDOW,v_szStatusClassName, NULL,WS_POPUP|WS_BORDER|WS_NOTIFY|CLS_FRACTION, 0, 0, 50, 27, hUIWnd, (HMENU)NULL, lpUIPrivate->hInst, NULL);

        if (!lpUIPrivate->hStatusWnd) {
            LocalUnlock(hUIPrivate);
            return;
        }
    }
    
    GetWorkArea(&g_sImeUIG.rcWorkArea);
    
    hIMC = (HIMC)GetWindowLong(hUIWnd, IMMGWL_IMC);
    if (!hIMC) {
    	ptPos.x = g_sImeUIG.rcWorkArea.right - lpUIPrivate->nStatusWidth;
    	ptPos.y = g_sImeUIG.rcWorkArea.bottom - lpUIPrivate->nStatusHeight;
    	nShowStatusCmd = SW_HIDE;
    } 
    else if (lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC)) {
    	if (lpIMC->ptStatusWndPos.x < g_sImeUIG.rcWorkArea.left)
    	    ptPos.x = g_sImeUIG.rcWorkArea.right - lpUIPrivate->nStatusWidth;
    	else if (lpIMC->ptStatusWndPos.x + lpUIPrivate->nStatusWidth > g_sImeUIG.rcWorkArea.right)
    	    ptPos.x = g_sImeUIG.rcWorkArea.right - lpUIPrivate->nStatusWidth;
    	else
    		ptPos.x = lpIMC->ptStatusWndPos.x;
    
    	if (lpIMC->ptStatusWndPos.y < g_sImeUIG.rcWorkArea.top)
    	    ptPos.y = g_sImeUIG.rcWorkArea.bottom - lpUIPrivate->nStatusHeight;
    	else if (lpIMC->ptStatusWndPos.y + lpUIPrivate->nStatusHeight > g_sImeUIG.rcWorkArea.right)
    	    ptPos.y = g_sImeUIG.rcWorkArea.bottom - lpUIPrivate->nStatusHeight;
    	else
    		ptPos.y = lpIMC->ptStatusWndPos.y;
    	
    	ImmUnlockIMC(hIMC);
    	nShowStatusCmd = SW_SHOWNOACTIVATE;
    } 
    else {
    	ptPos.x = g_sImeUIG.rcWorkArea.right - lpUIPrivate->nStatusWidth;
    	ptPos.y = g_sImeUIG.rcWorkArea.bottom - lpUIPrivate->nStatusHeight;
    	nShowStatusCmd = SW_HIDE;
    }

	if (pptStatusPos->x < 0 && pptStatusPos->y < 0)
   		*pptStatusPos = ptPos;
   	else
   		ptPos = *pptStatusPos;

    if (lpUIPrivate->hStatusWnd)
    	SetWindowPos(lpUIPrivate->hStatusWnd, HWND_TOPMOST, ptPos.x, ptPos.y, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE);
    
//    lpUIPrivate->fdwSetContext |= ISC_SHOWUIALL;

    if (hIMC)
    	ShowStatus(hUIWnd, SW_SHOWNOACTIVATE);

    LocalUnlock(hUIPrivate);

    return;
}

/**********************************************************************/
/* DestroyStatusWindow()                                              */
/**********************************************************************/
void PASCAL DestroyStatusWindow( HWND hStatusWnd)
{
    HWND     hUIWnd;
    HLOCAL   hUIPrivate;
    LPUIPRIV lpUIPrivate;

    hUIWnd = GetWindow(hStatusWnd, GW_OWNER);

    hUIPrivate = (HLOCAL)GetWindowLong(hUIWnd, IMMGWL_PRIVATE);
    if (!hUIPrivate) 
    	return;

    lpUIPrivate = (LPUIPRIV)LocalLock(hUIPrivate);
    if (!lpUIPrivate) 
        return;

    lpUIPrivate->nShowStatusCmd = SW_HIDE;

    lpUIPrivate->hStatusWnd = (HWND)NULL;

    LocalUnlock(hUIPrivate);

    return;
}

/**********************************************************************/
/* SetStatus                                                          */

⌨️ 快捷键说明

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