Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anyone tell why is this code not working???
C++
#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
Comments
Sergey Alexandrovich Kryukov 27-Mar-12 12:39pm    
Not clear. What is "not working"? What it is supposed to do?
--SA
subhendu_m 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.

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

Yes, your error messages can.
 
Share this answer
 
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.
 
Share this answer
 
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.
 
Share this answer
 
Comments
subhendu_m 28-Mar-12 2:39am    
it didn't helped.
it was a command line project.that's why it didn't show the results.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900