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

📄 options.cpp

📁 WinCE5.0下软键盘LARGEKB源代码
💻 CPP
字号:
//
// 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.
//
//
//
/*++


Module Name:

    options.cpp

Abstract:

    Options dialog code for Microsoft Input Method

Revision History:

--*/

#include <windows.h>
#include <sipapi.h>
#include "im.h"
#include "resource.h"

static TCHAR const g_pwszRegKey[] = TEXT("CLSID\\{A523DFC7-1A7E-4af6-991A-510E75847828}");
static TCHAR const g_pwszKBMode[] = TEXT("KBMode");
static TCHAR const g_pwszKBMode[] = TEXT("KBWidth");
static TCHAR const g_pwszKBMode[] = TEXT("KBHeight");
extern HINSTANCE g_hInstDll;

#define VALIDKB(uKB) (uKB == ASCIIKB || uKB == ASCIIKB_LS || uKB == ASCIIKB_SMALL || uKB == ASCIIKB_SS)

UINT IM_ReadRegistry(void)
{
    HKEY hKey;
    DWORD dwSize, dwKBMode = ASCIIKB;
    HRESULT hRes;

    if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT,
                                     g_pwszRegKey,
                                     0,
                                     (REGSAM)NULL,
                                     &hKey))
    {
        dwSize = sizeof(DWORD);
        hRes = RegQueryValueEx(hKey, g_pwszKBMode, 0, NULL, (LPBYTE)&dwKBMode, &dwSize);
        RegCloseKey(hKey);
        if (hRes == ERROR_SUCCESS && !VALIDKB(dwKBMode))
        {
            RETAILMSG(1, (TEXT("MSIM: IM_ReadRegistry found bad data in registry! KB read == %ld\r\n"), dwKBMode));
            //Uh, bogus data in this key, default to ASCIIKB
            dwKBMode = ASCIIKB;
        }
    }

    RETAILMSG(1, (TEXT("MSIM: IM_ReadRegistry read KB %ld\r\n"), dwKBMode));

    return (UINT)dwKBMode;
}


void IM_WriteRegistry(UINT uKB)
{
    long retval;
    DWORD dwDisp;
    HKEY hKey;

    RETAILMSG(1, (TEXT("MSIM: IM_WriteRegistry writing KB %ld\r\n"), uKB));

    retval = RegCreateKeyEx(HKEY_CLASSES_ROOT, g_pwszRegKey, 0, NULL, 
                            REG_OPTION_NON_VOLATILE, 
                            (REGSAM)NULL, NULL, &hKey, &dwDisp);
        	
    if (retval == ERROR_SUCCESS)
    {
        RegSetValueEx(hKey, 
                      g_pwszKBMode, 
                      0, 
                      REG_DWORD, 
                      (CONST BYTE *)&uKB, 
                      sizeof(DWORD));
        RegCloseKey(hKey);
    }
}


void UpdateKeysBitmap(HWND hDlg, 
                      HBITMAP hbmLgKeys, 
                      HBITMAP hbmSmKeys, 
                      HBITMAP hbmSmKeysSwipe)
{
    BOOL fSwipe;
    HBITMAP hbm = hbmLgKeys;

    if ((BOOL)SendDlgItemMessage(hDlg, IDC_SMALLKEYS, BM_GETCHECK, 0, 0L))
    {
        fSwipe = (BOOL)SendDlgItemMessage(hDlg, IDC_SWIPE, BM_GETCHECK, 0, 0L);
        hbm = fSwipe ? hbmSmKeysSwipe : hbmSmKeys;
    }

    SendDlgItemMessage(hDlg, IDC_KEYSBITMAP, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbm);
}


BOOL IM_OptionsDlg(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    BOOL fRetVal = TRUE, fSwipe;
    SIPINFO si;
    UINT uKB;
    CLSID clsid;
    int   id = IDC_LARGEKEYS;
    HBITMAP hbm;
    static HBITMAP hbmLgKeys = NULL, hbmSmKeys = NULL, hbmSmKeysSwipe = NULL;

    switch (msg)
    {
        case WM_INITDIALOG:
            uKB = IM_ReadRegistry();
            if (uKB == ASCIIKB_SMALL || uKB == ASCIIKB_SS)
            {
                id = IDC_SMALLKEYS;
            }
            CheckRadioButton(hDlg, IDC_LARGEKEYS, IDC_SMALLKEYS, id);

            if (uKB == ASCIIKB_LS || uKB == ASCIIKB_SS)
            {
                SendDlgItemMessage(hDlg, IDC_SWIPE, BM_SETCHECK, TRUE, 0L);
            }
            if (hbm = LoadBitmap(g_hInstDll, MAKEINTRESOURCE(IDB_OPTIONS_SWIPE_INSTRUCT)))
            {
                SendDlgItemMessage(hDlg, 
                                   IDC_SWIPEBITMAP, 
                                   STM_SETIMAGE, 
                                   IMAGE_BITMAP,
                                   (LPARAM)hbm);
            }

            //Now, load the large and small key bitmaps
            hbmLgKeys = LoadBitmap(g_hInstDll, MAKEINTRESOURCE(IDB_OPTIONS_LARGE_KEYS));
            hbmSmKeys = LoadBitmap(g_hInstDll, MAKEINTRESOURCE(IDB_OPTIONS_SMALL_KEYS));
            hbmSmKeysSwipe = LoadBitmap(g_hInstDll, MAKEINTRESOURCE(IDB_OPTIONS_SMALL_KEYS_SWIPE));

            UpdateKeysBitmap(hDlg, hbmLgKeys, hbmSmKeys, hbmSmKeysSwipe);
            break;

        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
                case IDOK:
                    fSwipe = (BOOL)SendDlgItemMessage(hDlg, IDC_SWIPE, BM_GETCHECK, 0, 0L);

                    if ((BOOL)SendDlgItemMessage(hDlg, IDC_LARGEKEYS, BM_GETCHECK, 0, 0L))
                    {
                        uKB = fSwipe ? ASCIIKB_LS : ASCIIKB;
                    }
                    else
                    {
                        uKB = fSwipe ? ASCIIKB_SS : ASCIIKB_SMALL;
                    }

                    IM_WriteRegistry(uKB);

                    RETAILMSG(1, (TEXT("MSIM: Options dialog, setting KB to %ld\r\n"), uKB));

                    memset(&si, 0, sizeof(SIPINFO));
                    si.cbSize = sizeof(SIPINFO);
//                    SHSipInfo(SPI_GETCURRENTIM, 0, &clsid, 0);
                    if (IsEqualCLSID(clsid, CLSID_CMSQwertyIm))
                    {
//                        SHSipInfo(SPI_GETSIPINFO, 0, &si, FALSE);
                        si.cbSize = sizeof(SIPINFO);
                        si.dwImDataSize = sizeof(UINT);
                        si.pvImData = (void *)&uKB;
//                        SHSipInfo(SPI_SETSIPINFO, 0, &si, FALSE);
                    }

                    // ||   ||
                    // \/   \/  Fall through!!!

                case IDCANCEL:
                    if (hbm = (HBITMAP)SendDlgItemMessage(hDlg, 
                                                          IDC_SWIPEBITMAP, 
                                                          STM_GETIMAGE, 
                                                          IMAGE_BITMAP,
                                                          0L))
                    {
                        DeleteObject(hbm);
                    }
                    if (hbmLgKeys)
                    {
                        DeleteObject(hbmLgKeys);
                    }
                    if (hbmSmKeys)
                    {
                        DeleteObject(hbmSmKeys);
                    }
                    if (hbmSmKeysSwipe)
                    {
                        DeleteObject(hbmSmKeysSwipe);
                    }
                    EndDialog(hDlg, TRUE);
                    fRetVal = TRUE;
                    break;

                case IDC_LARGEKEYS:
                case IDC_SMALLKEYS:
                case IDC_SWIPE:
                    switch (HIWORD(wParam))
                    {
                        case BN_CLICKED:
                            UpdateKeysBitmap(hDlg, hbmLgKeys, hbmSmKeys, hbmSmKeysSwipe);
                            fRetVal = TRUE;
                            break;

                        default:
                            break;
                    }
                    break;

                default:
                    break;
            }
            break;

        default:
            fRetVal = FALSE;
            break;
    }

    return fRetVal;
}

⌨️ 快捷键说明

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