#include <QMessageBox>
#include "testIME.h"
#include "inputmethod.h"
#include <Windows.h>
#include <iostream>
#include <QList>
#include <Msctf.h>
#include <atlcomcli.h>
#pragma comment ( lib , "User32.lib" )
#pragma comment ( lib , "imm32.lib" )
testIME::testIME(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
m_pIM = new InputMethod(parent);
QList<inputmethod::IMList*> pList = m_pIM->GetIMlist();
int nCount = pList.size();
QString strText;
int low = 0;
int high = 0;
BOOL bIme = false;
HKL hKL[4];
HKL hCurKL;
hCurKL=GetKeyboardLayout(0); //保存初始输入法
GetKeyboardLayoutList(nCount,hKL); //获取输入法列表,只获取两项
for ( int i = 0; i < nCount; i++ )
{
//printf("ID = %s,Name = %s\n",pList.at(i)->strID.c_str(),pList.at(i)->strName.c_str());
//std::cout<<"ID = "<<pList.at(i)->strID.c_str()<<","<<"Name = "<<pList.at(i)->strName.c_str()<<std::endl;
strText += QString::fromStdWString(pList.at(i)->strID);
strText += "\t";
strText += QString::fromStdWString(pList.at(i)->strName);
strText += "\n";
}
for ( int i = 0; i < nCount; i++ )
{
low = LOWORD(hKL[i]);
high = HIWORD(hKL[i]);
bIme = ImmIsIME(hKL[i]);//判断当前输入法是否打开(即是否非美式键盘的英文状态) 1:非美式的英文状态 0:美式的英文状态
strText += QString("high=%1").arg(high);
strText += "\t";
strText += QString("low=%1").arg(low);
strText += "\t";
strText += QString("bIme=%1").arg(bIme);
strText += "\n";
}
ui.textEdit->setText(strText);
ui.textEdit->installEventFilter(this);
bool bRes = IsWinVerGreaterThan(5,0);
//QMessageBox::information(this, QStringLiteral("提示"), QString("(5,0)bRes=%1").arg(bRes));
bRes = IsWinVerGreaterThan(6,1);
//QMessageBox::information(this, QStringLiteral("提示"), QString("(6,1)bRes=%1").arg(bRes));
bRes = IsWinVerGreaterThan(6,2);//其实是>=的意思
//QMessageBox::information(this, QStringLiteral("提示"), QString("(6,2)bRes=%1").arg(bRes));
bRes = IsWinVerGreaterThan(7,2);
//QMessageBox::information(this, QStringLiteral("提示"), QString("(7,2)bRes=%1").arg(bRes));
}
testIME::~testIME()
{
}
bool testIME::GetCurrentIme(QString & strName)
{
QWidget * pWidget = QApplication::activeWindow();
HWND hWnd = (HWND)pWidget->window();
DWORD thId;
HKL hkl;
thId=::GetWindowThreadProcessId(hWnd,NULL);
WCHAR buffer[255];
::memset(buffer,0,255);
hkl=::GetKeyboardLayout(thId);
QString strTemp("");
//win8 TSF
if ( IsWinVerGreaterThan(6,1) == true && IsWinVerGreaterThan(6,2) == true )
{
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("win8"));
HRESULT hr = S_OK;
CComPtr<ITfInputProcessorProfiles> pProfiles;
LANGID langid;
BSTR bstrImeName = NULL;
hr = CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER, IID_ITfInputProcessorProfiles, (LPVOID*)&pProfiles);
if ( hr != S_OK )
{
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("failed to call CoCreateInstance()"));
return false;
}
hr = pProfiles->GetCurrentLanguage(&langid);
if ( hr != S_OK )
{
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("failed to call GetCurrentLanguage()"));
return false;
}
CLSID textSrvId, profileId;
hr = pProfiles->GetDefaultLanguageProfile(langid, GUID_TFCAT_TIP_KEYBOARD, &textSrvId, &profileId);
if ( hr != S_OK )
{
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("failed to call GetDefaultLanguageProfile()"));
return false;
}
hr = pProfiles->GetActiveLanguageProfile(textSrvId, &langid, &profileId);
if ( hr != S_OK )
{
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("failed to call GetActiveLanguageProfile()"));
return false;
}
hr = pProfiles->GetLanguageProfileDescription(textSrvId, langid, profileId, &bstrImeName);
if ( hr != S_OK )
{
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("failed to call GetLanguageProfileDescription()"));
return false;
}
QString strTemp((QChar*)bstrImeName, wcslen(bstrImeName));
SysFreeString(bstrImeName);
}
//win7/xp IME
else if ( IsWinVerGreaterThan(6,1) == true && IsWinVerGreaterThan(6,2) == false || IsWinVerGreaterThan(6,1) == false )
{
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("win7"));
if (::ImmIsIME(hkl))
{
::ImmGetDescription(hkl,buffer,255);
}
else
{
::ImmGetDescription(hkl,buffer,255);
}
strTemp = QString::fromStdWString(buffer);
}
strName = strTemp;
return true;
}
bool testIME::eventFilter(QObject *watched, QEvent *event)
{
if ( watched == ui.textEdit )
{
if (event->type() == QEvent::FocusIn)
{
//setCN();
}
}
//将事件交给上层对话框
return QWidget::eventFilter(watched,event);
}
void testIME::setCN()
{
HKL hKL[4];
HKL hCurKL;
HWND hWnd = (HWND)this->winId();
hCurKL=::GetKeyboardLayout(0); //保存初始输入法
DWORD dwPID, dwTID;
dwTID = ::GetWindowThreadProcessId( hWnd, &dwPID );
HKL hkl = ::GetKeyboardLayout(dwTID);
//DWORD currentThId=::GetCurrentThreadId();
//::AttachThreadInput(currentThId,dwTID,TRUE);
WCHAR buffer[255];
::ImmGetDescription(hkl,buffer,255);
::GetKeyboardLayoutList(4,hKL); //获取输入法列表,只获取两项
// TODO: Add your control notification handler code here
if(hCurKL==hKL[0])
{
hCurKL=hKL[3]; //选择第4种输入法
}
::ActivateKeyboardLayout(hCurKL,KLF_SUBSTITUTE_OK); //切换输入法
//获得状态
HIMC hIMC;
DWORD dwConv, dwSent;
hIMC=ImmGetContext(hWnd);
ImmGetConversionStatus(hIMC,&dwConv,&dwSent);
//中文状态
if((dwConv & IME_CMODE_LANGUAGE) != IME_CMODE_NATIVE)
{
dwConv &= ~IME_CMODE_LANGUAGE;
dwConv |= IME_CMODE_NATIVE; //中文输入状态
}
//全角
if (!(dwConv & IME_CMODE_FULLSHAPE)) dwConv |= IME_CMODE_FULLSHAPE; //全角
if (!(dwConv & IME_CMODE_SYMBOL)) dwConv |= IME_CMODE_SYMBOL; //中文标点
ImmSetConversionStatus(hIMC,dwConv,dwSent);
ImmReleaseContext(hWnd,hIMC);
}
void testIME::on_pushButton_clicked()
{
//hCurKL=::GetKeyboardLayout(0); //保存初始输入法
QString strText;
HWND hWnd = (HWND)this->winId();
HKL hkl;
//
// HWND hWndQE = (HWND)ui.textEdit_CurIME->winId();
DWORD dwPID, dwTID;
dwTID = ::GetWindowThreadProcessId( hWnd, &dwPID );
hkl =GetKeyboardLayout(dwTID);
//
// HWND htopwindow = GetForegroundWindow();
// DWORD threadid = GetWindowThreadProcessId(htopwindow,NULL);
// hkl=GetKeyboardLayout(threadid);
//hkl = ::GetKeyboardLayout(0);
WCHAR ch[256];
BOOL bRes = GetKeyboardLayoutName(ch);
QString strTemp("");
strTemp = QString::fromStdWString(ch);
//GetCurrentIme(strTemp);
// QWidget * pWidget = QApplication::activeWindow();
// hWnd = (HWND)pWidget->window();
// DWORD thId;
// thId=::GetWindowThreadProcessId(hWnd,NULL);
// hkl=::GetKeyboardLayout(thId);
HIMC hIMC;
DWORD dwConv, dwSent;
//HWND hWnd = (HWND)this->winId();
hIMC=ImmGetContext(hWnd);
BOOL bOpen = false;
bOpen = ImmGetOpenStatus(hIMC);
strText += QString("high=%1").arg(HIWORD(hkl));
strText += "\t";
strText += QString("low=%1").arg(LOWORD(hkl));
strText += "\t";
strText += QString("name=") + strTemp;
strText += "\t";
strText += QString("bIme=%1").arg(ImmIsIME(hkl));
strText += "\t";
strText += QString("bCN=%1").arg(isCNStatus());
strText += "\t";
strText += QString("bOpen=%1").arg(bOpen);
strText += "\n";
ui.textEdit_CurIME->setText(strText);
}
void testIME::on_pushButton_switch_clicked()
{
QString strText(""),strCN(""),strEN("英");
strText = ui.pushButton_switch->text().trimmed();
inputmethod::eCN_EN m_eType; //标记当前是中文还是英文输入法
strCN = QStringLiteral("中");
s
没有合适的资源?快使用搜索试试~ 我知道了~
罗列系统的输入法列表,点击按钮,实现中英文输入切换
共103个文件
tlog:28个
obj:20个
dll:12个
5星 · 超过95%的资源 需积分: 12 32 下载量 56 浏览量
2015-10-13
17:24:41
上传
评论 1
收藏 58.67MB RAR 举报
温馨提示
1.开发工具:vs2010+Qt5.4.0 需要安装: (1)vs2010; (2)qt-opensource-windows-x86-msvc2010_opengl-5.4.0.exe; (3)qt-vs-addin-1.2.4-opensource.exe 2.罗列了系统的输入法列表,点击按钮,可以实现中英文切换 Release整个文件夹拷贝到win7、win8、xp都是可以直接运行起来
资源推荐
资源详情
资源评论
收起资源包目录
罗列系统的输入法列表,点击按钮,实现中英文输入切换 (103个子文件)
test.vcxprojResolveAssemblyReference.cache 713B
test.vcxprojResolveAssemblyReference.cache 713B
testIME.cpp 9KB
inputmethod.cpp 7KB
moc_testIME.cpp 4KB
moc_testIME.cpp 4KB
moc_inputmethod.cpp 3KB
moc_inputmethod.cpp 3KB
qrc_test.cpp 1KB
main.cpp 173B
icudt53.dll 20.53MB
Qt5Gui.dll 4.39MB
Qt5Widgets.dll 4.26MB
Qt5Core.dll 3.9MB
icuin53.dll 1.87MB
icuuc53.dll 1.26MB
qwindows.dll 870KB
qsqlite.dll 639KB
Qt5Sql.dll 148KB
qsqlodbc.dll 63KB
qsqlpsql.dll 52KB
qsqlmysql.dll 46KB
test.exe 122KB
testIME.exe 115KB
testIME.exe 46KB
test.vcxproj.filters 3KB
ui_testIME.h 3KB
inputmethod.h 2KB
testIME.h 695B
test.ilk 1.13MB
testIME.ilk 1.1MB
testime-4a8598e7.ipch 84.63MB
testime-d8cbb4e1.ipch 81.63MB
testIME.lastbuildstate 65B
testIME.lastbuildstate 63B
test.lastbuildstate 62B
test.lastbuildstate 60B
test.log 4KB
test.log 836B
test.exe.intermediate.manifest 381B
testIME.exe.intermediate.manifest 381B
test.exe.intermediate.manifest 381B
testIME.exe.intermediate.manifest 381B
testIME.obj 341KB
test.obj 341KB
inputmethod.obj 199KB
inputlanguage.obj 153KB
testIME.obj 113KB
test.obj 113KB
moc_testIME.obj 104KB
moc_test.obj 104KB
main.obj 100KB
moc_inputmethod.obj 77KB
inputmethod.obj 62KB
moc_inputlanguage.obj 60KB
inputlanguage.obj 45KB
moc_testIME.obj 12KB
moc_test.obj 12KB
moc_inputmethod.obj 12KB
moc_inputlanguage.obj 12KB
main.obj 11KB
qrc_test.obj 5KB
qrc_test.obj 2KB
test.pdb 1.86MB
testIME.pdb 1.84MB
vc100.pdb 1.23MB
test.qrc 64B
test.sdf 43.89MB
testIME.sdf 39.71MB
testIME.sln 879B
test.suo 31KB
testIME.suo 11KB
CL.read.1.tlog 546KB
CL.read.1.tlog 545KB
cl.command.1.tlog 21KB
cl.command.1.tlog 20KB
link.read.1.tlog 14KB
link.read.1.tlog 13KB
CL.write.1.tlog 11KB
custombuild.command.1.tlog 9KB
custombuild.command.1.tlog 9KB
CL.write.1.tlog 7KB
link.command.1.tlog 7KB
link.command.1.tlog 7KB
link.write.1.tlog 3KB
link.write.1.tlog 3KB
custombuild.write.1.tlog 2KB
custombuild.write.1.tlog 2KB
mt.read.1.tlog 2KB
mt.read.1.tlog 2KB
custombuild.read.1.tlog 2KB
custombuild.read.1.tlog 2KB
mt.command.1.tlog 1KB
mt.command.1.tlog 1KB
mt.write.1.tlog 782B
mt.write.1.tlog 758B
testIME.write.1.tlog 0B
test.write.1.tlog 0B
test.write.1.tlog 0B
testIME.write.1.tlog 0B
共 103 条
- 1
- 2
资源评论
- maitianren_csd2016-12-07挺有参考价值的,谢谢了
llfwdd
- 粉丝: 2
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于SpringBoot+Vue3快速开发平台、自研工作流引擎源码设计.zip
- docker安装部署全流程
- 基于树莓派的人脸识别系统python源码+项目部署说明+超详细代码注释.zip
- Python和R爬取分析赶集网北京二手房数据.zip
- Python和R爬取分析赶集网北京二手房数据.zip
- Java知识体系最强总结(2021版).txt
- Python知识点Python知识点Python知识点Python知识点Python知识点PythonPython知识点.txt
- Java开发基于seetaface6的人脸识别(活体检测)的封装源码.zip
- JSP在线失物招领管理平台源码.zip
- JSP在线旅游美食展现管理系统源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功