sp; i++;
95. szID.Format(TEXT("%s//%d"),szProload,i);
96. }
97.
98. ::RegCloseKey(hPreload);
99. return (NULL != m_pILHead);
100. }
101. //
102. void Clear()
103. {
104. InputLink *pOne = m_pILHead;
105. InputLink *pTwo;
106.
107. while(pOne)
108. {
109. pTwo = pOne;
110. pOne = pOne->pNext;
111. free(pTwo);
112. }
113. m_pILHead = NULL;
114. }
115.public:
116. CInputLanguage()
117. {
118. m_pILHead = NULL;
119. ListAllIM();
120. }
121. //
122. ~CInputLanguage()
123. {
124. Clear();
125. }
126. //
127. bool SelectInputIM(InputLink *pIL)
128. {
129. if(!pIL)
130. return FALSE;
131. HKL hkl;
132.
133. hkl = LoadKeyboardLayout(pIL->tcID,KLF_ACTIVATE); // 装载输入法
134. if(NULL == hkl)
135. return FALSE;
136. else
137. {
138. ActivateKeyboardLayout(hkl,KLF_SETFORPROCESS); // 激活输入法
139. }
140.
141. return TRUE;
142. }
143. //获得输入法信息链表头结点指针。
144. InputLink* GetInputIMList()
145. {
146. return m_pILHead;
147. }
148.};
149.#endif
/****************************************************************************
* Copyright (C), 2006, Leo.Zheng
* File name: InputOper.h
* Description: CE 5.0 输入法列表的获得
* Version: Version 0.1
* History: Leo.Zheng created 2007-10-15
* ......
*****************************************************************************/
#ifndef __INPUT_OPERATION_
#define __INPUT_OPERATION_
#include "stdafx.h"
#include "Afx.h"
#include "Winreg.h"
#define IDBufSize 30
#define NameBufSize 100
struct InputLink
{
TCHAR tcID[IDBufSize]; //输入法代号。
TCHAR tcName[NameBufSize]; //输入法的说明文字。
InputLink* pNext;
};
class CInputLanguage
{
private:
InputLink *m_pILHead;
//
bool ListAllIM()
{
HKEY hPreload;
HKEY hLayouts;
DWORD cp = IDBufSize;
TCHAR tcLp[IDBufSize];
TCHAR tcLpDefault[IDBufSize];
CString szID;
CString szValueName;
CString szProload = "Keyboard Layout//Preload"; // 输入法顺序
CString szLayouts = "System//CurrentControlSet//Control//Layouts//"; // 输入法名称
int i = 1;
DWORD lpT = REG_SZ;
// TCHAR tcBuffer[NameBufSize] = {0};
DWORD dwLen = 0;
LONG nRetValue = 0;
// 读默认的输入法
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,szProload,0,0,&hPreload))
{
nRetValue = RegQueryValueEx(hPreload,TEXT(""),NULL,&lpT,(LPBYTE)tcLp,&cp);
if(ERROR_SUCCESS == nRetValue)
{
wcscpy(tcLpDefault,tcLp);
}
}
// 读所有的输入法
szID.Format(TEXT("%s//%d"),szProload,i);
while(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,szID,0,0,&hPreload))
{
szValueName.Format(TEXT("%s"),TEXT(""));
// RegEnumKeyEx(hPreload,0,tcBuffer,&dwLen,NULL,NULL,NULL,NULL);
if(ERROR_SUCCESS == RegQueryValueEx(hPreload,szValueName,NULL,&lpT,(LPBYTE)tcLp,&cp))
{
CString szTempName;
szTempName = szLayouts + (LPCTSTR)(LPTSTR)tcLp;
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,szTempName,0,0,&hLayouts))
{
TCHAR lpD[NameBufSize];
DWORD lpS = NameBufSize; // DataSize
if(ERROR_SUCCESS == RegQueryValueEx(hLayouts,TEXT("Layout Text"),NULL,&lpT,(LPBYTE)lpD,&lpS))
{
InputLink *pOne = m_pILHead;
InputLink *pTwo = (InputLink *)malloc(sizeof(struct InputLink));
wcscpy(pTwo->tcID,tcLp);
wcscpy(pTwo->tcName,lpD);
pTwo->pNext = NULL;
if(pOne)
{
while(pOne->pNext)
{
pOne = pOne->pNext;
}
pOne->pNext = pTwo;
}
else
{
m_pILHead = pTwo;
}
}
}
::RegCloseKey(hLayouts);
}
i++;
szID.Format(TEXT("%s//%d"),szProload,i);
}
::RegCloseKey(hPreload);
return (NULL != m_pILHead);
}
//
void Clear()
{
InputLink *pOne = m_pILHead;
InputLink *pTwo;
while(pOne)
{
pTwo = pOne;
pOne = pOne->pNext;
free(pTwo);
}
m_pILHead = NULL;
}
public:
CInputLanguage()
{
m_pILHead = NULL;
ListAllIM();
}
//
~CInputLanguage()
{
Clear();
}
//
bool SelectInputIM(InputLink *pIL)
{
if(!pIL)
return FALSE;
HKL hkl;
hkl = LoadKeyboardLayout(pIL->tcID,KLF_ACTIVATE); // 装载输入法
if(NULL == hkl)
return FALSE;
else
{
ActivateKeyboardLayout(hkl,KLF_SETFORPROCESS); // 激活输入法
}
return TRUE;
}
//获得输入法信息链表头结点指针。
InputLink* GetInputIMList()
{
return m_pILHead;
}
};
#endif
调用示例:
[cpp] view plaincopyprint?
01.// TestIM.cpp : Defines the entry point for the application.
02.//
03.#include "stdafx.h"
04.#include "InputOper.h"
05.int WINAPI WinMain( HINSTANCE hInstance,
06. HINSTANCE hPrevInstance,
07. LPTSTR&
上一页 [1] [2] [3] 下一页