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

📄 freepy.cpp

📁 windows ce 平台下的輸入法 程序編寫 範例
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// freepy.cpp : Defines the entry point for the DLL application.
//
/*
 * Copyright (C) 1999.4  Li ZhenChun
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License; or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that is will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, M A 02139, USA.
 *
 * Author: Li ZhenChun  email: zhchli@163.net or zhchli@126.com
 * 
 */

//#include "stdafx.h"
#include "freepy.h"
#include "windows.h"
#define CS_FREEPY (CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS)
void SetWindowZorder(LPUIEXTRA	lpUIExtra);

BOOL WINAPI DllMain(
					 HANDLE    hInstDLL,//HINSTANCE
					 DWORD        dwFunction,
					 LPVOID       lpNot)
{
	
    switch(dwFunction)
    {
	case DLL_PROCESS_ATTACH:
		/* for debug ********************************/
#ifdef _MY_DEBUG
		if(nDebugLevel){
			if( (DebugLogFile=_tfopen( DEBUGLOGFILE, _T("w")))==NULL)
				MessageBox(NULL,_T("can not open Debuglogfile"),_T("debug"),MB_OK);
			DebugLog(1,(DebugLogFile,_T("Entry in\r\n")));
		}
#endif
		RETAILMSG(DEBUGMODE,(TEXT("Entry in\r\n")));
		/********************************************/

		InitDictionary();
		LOGFONT lf;
		memset(&lf,0,sizeof(lf));		
		lf.lfHeight = 16;
		lf.lfEscapement = 0;
		lf.lfOrientation = 0;
		lf.lfWeight = FW_BOLD;//		lf.lfWeight = FW_NORMAL;		
		lf.lfItalic = FALSE;
		lf.lfUnderline = FALSE;
		lf.lfStrikeOut = 0;
		lf.lfCharSet = DEFAULT_CHARSET;//DEFAULT_CHARSET;
		lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
		lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
		lf.lfQuality = DEFAULT_QUALITY;
		lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
		lstrcpy(lf.lfFaceName,_T("宋体"));
		hUIFont = CreateFontIndirect(&lf);		
		
		hInst = (HINSTANCE)hInstDLL;
		IMERegisterClass( hInst );
		break;
		
	case DLL_PROCESS_DETACH:
		DeleteObject(hUIFont);

		UnregisterClass(UICLASSNAME,hInst);
		UnregisterClass(COMPCLASSNAME,hInst);
		UnregisterClass(CANDCLASSNAME,hInst);
		UnregisterClass(STATUSCLASSNAME,hInst);

		DestroyDictionary();
		
		/* for debug ********************************/
#ifdef _MY_DEBUG
		if(nDebugLevel){
			DebugLog(1,(DebugLogFile,_T("Entry out\r\n")));
			if(DebugLogFile!=NULL)
				fclose(DebugLogFile);
		}
#endif
		/********************************************/
		RETAILMSG(DEBUGMODE,(TEXT("Entry out\r\n")));

		break;
		
	case DLL_THREAD_ATTACH:
		RETAILMSG(DEBUGMODE,(TEXT("IME:Thread attach\r\n")));
		break;
		
	case DLL_THREAD_DETACH:
		RETAILMSG(DEBUGMODE,(TEXT("IME:Thread detach\r\n")));
		break;
    }
    return TRUE;
}


BOOL IMERegisterClass( HANDLE hInstance )
{
    WNDCLASS wc;
	
    //
    // register class of UI window.
    //
    //wc.cbSize         = sizeof(WNDCLASS);
    wc.style          = CS_FREEPY | CS_IME;
    wc.lpfnWndProc    = UIWndProc;
    wc.cbClsExtra     = 0;
    wc.cbWndExtra     = 2 * sizeof(LONG);
    wc.hInstance      = (HINSTANCE)hInstance;
    wc.hCursor        = LoadCursor( NULL, IDC_ARROW );
    wc.hIcon          = NULL;
    wc.lpszMenuName   = (LPTSTR)NULL;
    wc.lpszClassName  = UICLASSNAME;
    wc.hbrBackground  = NULL;
    //wc.hIconSm        = NULL;
	
    if( !RegisterClass( (LPWNDCLASS)&wc ) )
        return FALSE;
	
    //
    // register class of composition window.
    //
    //wc.cbSize         = sizeof(WNDCLASS);
    wc.style          = CS_FREEPY | CS_IME;
    wc.lpfnWndProc    = CompWndProc;
    wc.cbClsExtra     = 0;
    wc.cbWndExtra     = UICHILDEXTRASIZE;
    wc.hInstance      = (HINSTANCE)hInstance;
    wc.hCursor        = LoadCursor( NULL, IDC_ARROW );
    wc.hIcon          = NULL;
    wc.lpszMenuName   = (LPTSTR)NULL;
    wc.lpszClassName  = COMPCLASSNAME;
    wc.hbrBackground  = NULL;
    //wc.hIconSm        = NULL;
	
    if( !RegisterClass( (LPWNDCLASS)&wc ) )
        return FALSE;
	
    //
    // register class of candadate window.
    //
    //wc.cbSize         = sizeof(WNDCLASS);
    wc.style          = CS_FREEPY | CS_IME;
    wc.lpfnWndProc    = CandWndProc;
    wc.cbClsExtra     = 0;
    wc.cbWndExtra     = UICHILDEXTRASIZE;
    wc.hInstance      = (HINSTANCE)hInstance;
    wc.hCursor        = LoadCursor( NULL, IDC_ARROW );
    wc.hIcon          = NULL;
    wc.lpszMenuName   = (LPTSTR)NULL;
    wc.lpszClassName  = CANDCLASSNAME;
    wc.hbrBackground  = NULL;
    //wc.hIconSm        = NULL;
	
    if( !RegisterClass( (LPWNDCLASS)&wc ) )
        return FALSE;
	
    //
    // register class of status window.
    //
    //wc.cbSize         = sizeof(WNDCLASS);
    wc.style          = CS_FREEPY | CS_IME;
    wc.lpfnWndProc    = StatusWndProc;
    wc.cbClsExtra     = 0;
    wc.cbWndExtra     = UICHILDEXTRASIZE;
    wc.hInstance      = (HINSTANCE)hInstance;
    wc.hCursor        = LoadCursor( NULL, IDC_ARROW );
    wc.hIcon          = NULL;
    wc.lpszMenuName   = (LPTSTR)NULL;
    wc.lpszClassName  = STATUSCLASSNAME;
    wc.hbrBackground  = NULL;
    //wc.hIconSm        = NULL;
	
    if( !RegisterClass( (LPWNDCLASS)&wc ) )
        return FALSE;
	
    return TRUE;
}


/**********************************************************************/
/*                                                                    */
/* UIWndProc()                                                   */
/*                                                                    */
/* IME UI window procedure                                            */
/*                                                                    */
/**********************************************************************/
LRESULT WINAPI UIWndProc(
				HWND hWnd,
				UINT message,
				WPARAM wParam,
				LPARAM lParam)
{
	
    HIMC           hUICurIMC;
    LPINPUTCONTEXT lpIMC;
    LPUIEXTRA      lpUIExtra;
    HGLOBAL        hUIExtra;
    LONG           lRet = 0L;
	
//	DebugLog(1,(DebugLogFile,_T("UIWnd\r\n")));
	//RETAILMSG(DEBUGMODE,(TEXT("UIWND\r\n")));
	
    hUICurIMC = (HIMC)GetWindowLong(hWnd,IMMGWL_IMC);
	
    //
    // Even if there is no current UI. these messages should not be pass to 
    // DefWindowProc().
    //
    if (!hUICurIMC)
    {
        switch (message)
        {
		case WM_IME_STARTCOMPOSITION:
		case WM_IME_ENDCOMPOSITION:
		case WM_IME_COMPOSITION:
		case WM_IME_NOTIFY:
		case WM_IME_CONTROL:
		case WM_IME_COMPOSITIONFULL:
		case WM_IME_SELECT:
		case WM_IME_CHAR:
			return 0L;
		default:
			break;
        }
    }
	
    switch (message)
    {
	case WM_CREATE:
		//DebugLog(1,(DebugLogFile,_T("UIWnd:WM_CREATE\r\n")));
		RETAILMSG(DEBUGMODE,(TEXT("UIWnd:WM_CREATE\r\n")));
		
		//
		// Allocate UI's extra memory block.
		//
		hUIExtra = GlobalAlloc(GHND,sizeof(UIEXTRA));
		lpUIExtra = (LPUIEXTRA)GlobalLock(hUIExtra);

		lpUIExtra->uiComp.pt.x = -1;
		lpUIExtra->uiComp.pt.y = -1;

		CreateCompWindow(hWnd,lpUIExtra);
		CreateCandWindow(hWnd,lpUIExtra);

		GlobalUnlock(hUIExtra);
		SetWindowLong(hWnd,IMMGWL_PRIVATE,(DWORD)hUIExtra);
		break;
		
	case WM_IME_SETCONTEXT:
		//DebugLog(1,(DebugLogFile,_T("UIWnd:WM_IME_SETCONTEXT\r\n")));
		RETAILMSG(DEBUGMODE,(TEXT("UIWnd:WM_IME_SETCONTEXT\r\n")));
		if (wParam)
		{
			
			hUIExtra = (HGLOBAL)GetWindowLong(hWnd,IMMGWL_PRIVATE);
			lpUIExtra = (LPUIEXTRA)GlobalLock(hUIExtra);
			//SetWindowZorder(lpUIExtra);
			
			if (hUICurIMC)
			{
				//
				// input context was chenged.
				// if there are the child windows, the diplay have to be
				// updated.
				//
				lpIMC = ImmLockIMC(hUICurIMC);
				if (lpIMC)
				{
					SetWindowZorder(lpUIExtra);
					MoveCompWindow(hWnd,lpUIExtra,lpIMC);
					MoveCandWindow(hWnd,lpUIExtra,lpIMC);
				}
				else
				{
					HideCandWindow(lpUIExtra);
					HideCompWindow(lpUIExtra);
				}
				ImmUnlockIMC(hUICurIMC);
			}
			else   // it is NULL input context.
			{
				HideCandWindow(lpUIExtra);
				HideCompWindow(lpUIExtra);

⌨️ 快捷键说明

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