键盘布局功能的工作 [英] working of keyboardlayout function

查看:313
本文介绍了键盘布局功能的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我为什么此代码无法正常工作??

can anyone tell why is this code not working???

#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <conio.h>

using namespace std;
// Keyboard layout structure
class _KeyboardLayout
{
public:
	HKL hBengali;
	bool bBengali;
	HKL hEnglish;
	bool bEnglish;
	_KeyboardLayout();
} ;

_KeyboardLayout::_KeyboardLayout()
{
// setting default values (as not installed = false)
bBengali=false;
bEnglish=false;
}


int main()
{
	
	_KeyboardLayout KeyboardLayout;
	// Get layout’s count
TCHAR szKeyboard[KL_NAMELENGTH];
int nBuff=::GetKeyboardLayoutList(0, NULL);
int nKeyboard;
HKL * phkl;
if((phkl = new HKL[nBuff])==NULL)
{
	cout<<"Out of Memory !";
	return 1;
}

// Get and parse layout items
int x=::GetKeyboardLayoutList(nBuff,phkl);
// iterate through list to check needed layouts
for(nKeyboard=0; nKeyboard<nBuff; nKeyboard++)
{
	::ActivateKeyboardLayout(phkl[nKeyboard], KLF_SETFORPROCESS);
	GetKeyboardLayoutName(szKeyboard);
	if(wcscmp(szKeyboard,_T("00000445"))==0)
	{
		KeyboardLayout.bBengali=true;
		KeyboardLayout.hBengali=phkl[nKeyboard];
		cout<<phkl[nKeyboard];
	}
	if(wcscmp(szKeyboard,_T("00000409"))==0)
	{
		KeyboardLayout.bEnglish=true;
		KeyboardLayout.hEnglish=phkl[nKeyboard];
	}

}
delete [] phkl;

if(!KeyboardLayout.bBengali)
	cout<<"error in bengali layout";
	//MessageBox(NULL,_T("Bengali keyboard layout not installed"),_T("Warning"),MB_OK|MB_ICONEXCLAMATION);
if(!KeyboardLayout.bEnglish)
	MessageBox(NULL,_T("English (USA) keyboard layout not installed"),_T("Warning"),MB_OK|MB_ICONEXCLAMATION);
else
{}
cout<<endl<<::LoadKeyboardLayoutW(_T("00000445"),KLF_ACTIVATE | KLF_SETFORPROCESS);
if(KeyboardLayout.bBengali)
{ 
cout<<endl<<::ActivateKeyboardLayout(HKL(HKL_PREV), KLF_REORDER);}
return 0;
}

推荐答案

谁能告诉我这段代码为什么不起作用?

是的,您的错误消息可以.
can anyone tell why is this code not working???

Yes, your error messages can.


有错误消息.但它应该工作.我是视觉编程的新手.但它无法正常工作.
there are error messages. but it should work. i''m newbie in visual programming. but it is not working in the way it should work. it is not activating the required keyboard layout.


似乎您加载了孟加拉语,然后通过激活以前的语言(很可能是英语)来中和该语言.因此,删除ActivateKeyBoardLayout 可能会对您有所帮助.

假设已经安装了孟加拉语,那么只需调用LoadKeyboardLayout即可为您完成这项工作.

希望对您有所帮助.
It seems that you load the Bengali language then neutralize that with activating previous language(which is most probably English). So removing the ActivateKeyBoardLayout may help you.

With assumption that Bengali is already has been installed then just a simple call to LoadKeyboardLayout will do the job for you.

Hope it helps.


这篇关于键盘布局功能的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆