Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Keyboard
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;
}
Posted 27-Mar-12 5:51am
Comments
SAKryukov at 27-Mar-12 12:39pm
   
Not clear. What is "not working"? What it is supposed to do?
--SA
subhendu_m at 28-Mar-12 2:38am
   
it is supposed to activate the bengali keyboard. it shows that it has load itbut does load it/activate it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

can anyone tell why is this code not working???
 
Yes, your error messages can.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Comments
subhendu_m at 28-Mar-12 2:39am
   
it didn't helped.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

it was a command line project.that's why it didn't show the results.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 245
1 Kamal Rocks 184
2 Sergey Alexandrovich Kryukov 175
3 BillWoodruff 173
4 PIEBALDconsult 160
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 29 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100